Question: Homeassistant "states.binary_sensor.your_sensor.last_changed"

Hi all

is there a way other than creating a template in HA to have the last _change value in Home remote ?

Coming from Homeseer, this information was available right out of the box but I can’t find anywat to get this info from HA

thanks

I am not aware of a way to do this but, as an HA user, I would love to be notified of how you figure it out!

Do you mean some kind of log or record of recent events?
Maybe it is possible with a script.

It should be possible if you create a small web server (with a PHP script) and then add a trigger with an action (method invoker) HTTP command to your button, which writes the data to a text file.
Example http: http://YOUR_SERVER_IP/log_action.php?device=light_livingroom&action=switch_on&status=ON
Then you could display the text file in a web browser field in HR.

Action Logging Script (log_action.php):
This script receives the HTTP request from The Home Remote (HR) and writes the action details to the log file.

<?php
/**
 * PHP Script to receive action logs from The Home Remote (HR) and save them to a file.
 *
 * This script is called via an HTTP GET request (Method Invoker) from HR when a device action occurs.
 */

// --- Configuration ---
$log_file = 'action_log.txt'; // The file where actions will be logged. Ensure this file is writable (e.g., CHMOD 666).

// --- Retrieve Data from HR (GET Parameters) ---
// The parameters should match what you configure in HR's Method Invoker URL.
$device = isset($_GET['device']) ? $_GET['device'] : 'Unknown Device';
$action = isset($_GET['action']) ? $_GET['action'] : 'Unknown Action';
$status = isset($_GET['status']) ? $_GET['status'] : 'N/A';

// --- Format Log Entry ---
$timestamp = date('Y-m-d H:i:s');
// Create a clean, pipe-separated log entry.
$log_entry = "{$timestamp} | DEVICE: {$device} | ACTION: {$action} | STATUS: {$status}\n";

// --- Write to Log File ---
// FILE_APPEND ensures the new entry is added to the end of the file.
// LOCK_EX locks the file during writing to prevent data corruption from simultaneous calls.
$success = file_put_contents($log_file, $log_entry, FILE_APPEND | LOCK_EX);

// --- Response to The Home Remote ---
if ($success !== false) {
    http_response_code(200); // Success
    echo "Log entry successfully saved.";
} else {
    http_response_code(500); // Internal Server Error
    echo "Error: Could not write to log file. Check file permissions ('{$log_file}').";
}
?>

Log Display Script (show_log.php):
This script reads the log file and formats its contents into a simple HTML page that you can view in The Home Remote.

<?php
/**
 * PHP Script to read the action log file and display it as an HTML page.
 *
 * This page is meant to be displayed in The Home Remote using the "Web Browser" control.
 */

// --- Configuration ---
$log_file = 'action_log.txt'; // Must match the file name used in log_action.php

// --- Read Log File Content ---
// @file_get_contents is used to suppress warnings if the file does not exist yet.
$log_content = @file_get_contents($log_file); 

// --- HTML Output Start ---
echo "<!DOCTYPE html>";
echo "<html lang='en'>";
echo "<head>";
echo "<meta charset='UTF-8'>";
// Simple styling for readability, especially on mobile/tablet interfaces
echo "<style>body { font-family: Arial, sans-serif; background-color: #333; color: white; margin: 10px; } 
      h2 { color: #FFA500; } 
      .log-entry { margin-bottom: 5px; padding: 5px; border-bottom: 1px solid #555; }</style>";
echo "<title>Home Remote Action Log</title>";
echo "</head>";
echo "<body>";
echo "<h2>Recent Home Automation Actions</h2>";

// --- Display Log Entries ---
if ($log_content) {
    // Split content into individual lines
    $lines = explode("\n", trim($log_content));
    
    // Reverse the array to show the latest actions at the top
    $lines = array_reverse($lines); 
    
    // Use an unformatted list or pre-tag for clean text display
    echo "<div style='font-family: monospace; font-size: 0.9em;'>";
    foreach ($lines as $line) {
        // Skip empty lines (can occur at the end of the file)
        if (!empty($line)) {
            // htmlspecialchars prevents XSS and displays special characters correctly
            echo "<div class='log-entry'>" . htmlspecialchars($line) . "</div>";
        }
    }
    echo "</div>";
} else {
    echo "<p>No log entries found or the log file is currently empty/unreadable.</p>";
}

// --- HTML Output End ---
echo "</body>";
echo "</html>";
?>
1 Like