Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › binary sensor

How to Detect Stale Sensor Readings in Home Assistant With a Template Binary Sensor

By Freedom251 Team · · 10 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A Home Assistant template binary sensor can turn on when another entity has stopped providing usable data. The template checks for unknown or unavailable, then compares the source entity’s last_updated timestamp with the current time. In the example below, a reading older than 900 seconds (15 minutes) is reported as stale. That interval is only an example: set it from the device’s normal reporting cadence and the consequences of missing data.

What “stale” means in Home Assistant

A sensor value can look perfectly normal while no new report has arrived for a long time. A temperature of 21 °C, for example, does not tell you whether the thermometer reported it a few seconds ago or yesterday. A stale-reading check adds a second signal: whether the source entity has been updated recently enough to trust.

As an Amazon Associate I earn from qualifying purchases.

The result is a derived binary entity with a simple contract:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • On: the source is missing, explicitly unknown or unavailable, or its last update is older than your limit.
  • Off: the source has a usable state and its last update is within the limit.

This is a monitoring signal, not proof that hardware has lost power. Home Assistant’s state timestamp belongs to the entity and its integration. An integration may refresh that timestamp whenever it receives a report, but the official documentation does not establish that every integration updates it for every unchanged physical measurement. Confirm how the particular integration reports data before treating an “on” result as definitive evidence that the device itself is offline.

#1 Best Overall
Besisglas Starter Kit for Home Assistant, Zigbee 3.0 Hub, 2 Zigbee Sensors
  • EASIEST WAY TO GET STARTED WITH HOME ASSISTANT: With Home Assistant already installed, it only requires plugging the included power supply and Ethernet cable to get started
  • DESIGNED FOR THE HOME: The small, fanless, and silent design packs a quad-core processor, 32GB of storage, and 4GB of RAM
  • ONE HUB TO CONTROL YOUR WHOLE HOME: Simplify your smart home with HA70. Built with official Home Assistant OS and a professional Zigbee coordinator, it brings local control, powerful automation, and seamless device management into one compact hub
  • AUTOMATE EVERYTHING: Make all the devices in your home work in harmony - have your lights dim when you start watching a movie, or turn off your heat when you're away from home
  • YOUR HOME, YOUR DATA: Your home's data will be kept in the home on your HomeAssistant. You can easily view, share, and export that data anywhere you want

Choose the failure policy before writing the template

Decide what “on” should mean

The example uses “on” to mean problem detected. That makes the entity easy to put on a dashboard and easy to use as an automation trigger. A problem device class can make that intent clear in the interface, although the class only changes presentation; the state template still determines whether the binary sensor is on or off.

If your dashboard uses a different convention, choose a generic on/off presentation or another suitable device class instead of labeling the state inaccurately. The important part is that anyone reading the entity understands what an “on” state means.

Set a threshold from the source’s reporting cadence

There is no universal stale interval. Start with the interval the integration normally uses, then leave enough margin for ordinary delays, sleep cycles, radio retries and startup. A limit that is shorter than normal reporting will create false alarms; one that is too long will delay detection.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Source behavior How to choose a limit Illustrative reasoning
Reports on a regular interval Use a limit longer than the normal interval, with margin for a missed report. If a device normally reports every few minutes, a limit of several reporting periods is usually less noisy than a one-period limit.
Reports only when a value changes Do not infer a cadence from the physical value alone. Check the integration’s update behavior first. A stable temperature may legitimately produce no new measurement, so a timestamp-based alarm could otherwise be misleading.
Runs on a sleep or wake schedule Set the limit beyond the expected sleep window and transmission delay. The sensor can be healthy while silent between scheduled check-ins.
Safety- or comfort-critical data Choose a shorter limit only when the source can reliably meet it, and test the alert path. Earlier detection is useful only if it does not produce constant false positives.

The YAML example uses 900 seconds, or 15 minutes, as an easily recognizable demonstration value. It is not a published recommendation and should not be copied without checking the source device.

Choose how to treat unknown and unavailable

unknown and unavailable do not provide a usable current state, so the main pattern treats either value as stale immediately. It also treats a missing entity as stale. This is the safest default when the binary sensor is intended to expose any data-quality problem.

Rank #2
Pulcro.io TK Node Mini PC - Home Assistant, AMD R2314, 8GB RAM, 256GB SSD
  • 🌍 𝗔𝘀𝘀𝗲𝗺𝗯𝗹𝗲𝗱 𝗶𝗻 𝘁𝗵𝗲 𝗨𝗦𝗔 – Built and quality-checked in Texas with a 2-Year US-Based Limited Warranty for dependable long-term support.
  • 🏠 𝗛𝗼𝗺𝗲 𝗔𝘀𝘀𝗶𝘀𝘁𝗮𝗻𝘁 𝗢𝗦 𝗣𝗿𝗲𝗶𝗻𝘀𝘁𝗮𝗹𝗹𝗲𝗱 – Ready to power your smart home locally with fast, reliable automation and no mandatory cloud dependence. A truly powerful smart home hub.
  • ⚙️ 𝗗𝗲𝘀𝗶𝗴𝗻𝗲𝗱 𝗳𝗼𝗿 𝗖𝗼𝗻𝘁𝗶𝗻𝘂𝗼𝘂𝘀 𝗢𝗽𝗲𝗿𝗮𝘁𝗶𝗼𝗻 – Built for reliable 24/7 performance powering virtualization, automation, containers, storage, and professional workloads.
  • 🧠 𝗖𝗵𝗼𝗼𝘀𝗲 𝗬𝗼𝘂𝗿 𝗣𝗿𝗼𝗰𝗲𝘀𝘀𝗼𝗿 𝗣𝗲𝗿𝗳𝗼𝗿𝗺𝗮𝗻𝗰𝗲 – Available with AMD R2314 (efficient 4-core), AMD R2514 (8-thread multitasking), or Intel Core i3-1215U (hybrid 6-core performance) to match your workload.
  • 💾 𝗘𝘅𝗽𝗮𝗻𝗱𝗮𝗯𝗹𝗲 𝗥𝗔𝗠 & 𝗨𝗽 𝘁𝗼 𝟰𝗧𝗕 𝗡𝗩𝗠𝗲 𝗦𝘁𝗼𝗿𝗮𝗴𝗲 – Dual SO-DIMM slots support up to 64GB RAM. Dual NVMe SSD slots support up to 4TB total storage. Select installed memory and storage based on your needs.

A different policy is valid when another entity already handles connectivity outages. In that design, you can let unknown or unavailable remain outside the age test and use a separate availability indicator. Make that choice deliberately; otherwise an outage may be hidden by a stale sensor that stays off.

Create the template binary sensor in YAML

Add a template binary sensor to your Home Assistant configuration. If your installation already has a template: section, add another item under it rather than creating a second top-level key.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
template:
  - binary_sensor:
      - name: 'Outdoor temperature stale'
        unique_id: outdoor_temperature_stale
        device_class: problem
        state: >-
          {% set entity_id = 'sensor.outdoor_temperature' %}
          {% set source = states[entity_id] %}
          {% if source is none or source.state in ['unknown', 'unavailable'] %}
            true
          {% else %}
            {{ (now() - source.last_updated).total_seconds() > 900 }}
          {% endif %}

Replace sensor.outdoor_temperature with the exact source entity ID and change the name, unique ID and threshold to match your installation. The expression returns a Boolean value that Home Assistant converts to the binary sensor’s on/off state.

What each part does

  • entity_id stores the source ID in one place, making the template easier to adapt.
  • states[entity_id] retrieves the source state object. If the entity does not exist, the result is none.
  • The first branch catches a missing source, unknown and unavailable before attempting datetime arithmetic.
  • source.last_updated is the timestamp Home Assistant associates with the source state object.
  • now() supplies the current time. Subtracting the timestamps produces a duration, and total_seconds() > 900 tests whether the age exceeds 15 minutes.
  • device_class: problem asks the interface to present the binary sensor as a problem indicator. Remove or change it if that terminology does not fit your dashboard.

After saving the configuration, use the configuration-check function provided by your Home Assistant installation, then reload template entities or restart when your version requires it. Confirm that the new entity appears with the expected ID before building automations around it.

Create the same entity with the UI helper

Home Assistant also supports binary template entities through its helper interface. In Settings, open the area for Helpers, create a Template helper, and choose a binary sensor. Enter the state template from the example, set the source entity and threshold for your device, and select a presentation that communicates whether “on” means stale. Exact labels can vary between Home Assistant releases, so use the helper’s current field names rather than copying an older screenshot.

Rank #3
reTerminal E1002 – 7.3″ Color E Ink Spectra 6 Smart Display, ESP32-S3 WiFi Dashboard Panel, No-Code SenseCraft HMI, Home Assistant & ESPHome Compatible, Ultra-Low Power with 3-Month Battery Life
  • 7.3″ Color E Ink Spectra6 Display - Enjoy vibrant colors and sharp text with the 7.3-inch 800×480 E Ink Spectra 6 display. It stays clear in bright light and uses almost no power while holding an image—perfect for home dashboards, smart displays, reminders and daily information boards.
  • Ultra-Low Power with Up to 3-Month Battery Life - The built-in 2000mAh battery and ultra-efficient design allow the reTerminal E1002 to run for up to 3 months in deep-sleep mode (6-hour refresh interval). Place it anywhere—on your desk, bedside table or wall—without worrying about wires or frequent charging.
  • No-Code Dashboard Design with SenseCraft HMI - Create beautiful custom dashboards using SenseCraft HMI, an AI-powered no-code platform. Simply drag and drop UI elements, choose from ready-made templates or let AI generate layouts for you. Connect live data from sensors, APIs or smart home systems and deploy your design to the E1002 with just a few clicks.
  • Works with Home Assistant, ESPHome & Maker Tools - Enjoy smooth integration with popular smart home and developer ecosystems. Build TRMNL dashboards with 300+ plugins, connect instantly to Home Assistant via ESPHome, or create your own applications using Arduino, PlatformIO or ESP-IDF—ideal for makers and DIY smart home enthusiasts.
  • Customizable Hardware & Flexible Expansion - Designed with makers in mind, the reTerminal E1002 supports GPIO/I²C/SPI expansion and Grove modules, allowing you to easily add buttons, sensors or other accessories. Perfect for smart home displays, creative DIY builds, educational projects and personal productivity boards.

The YAML route is preferable when you keep configuration in files or want the definition reviewed alongside the rest of your system. The helper route is convenient when you manage entities from the UI. Both create a derived entity; neither adds a new physical sensor or changes how the source integration reports data.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Validate the expression before relying on it

Use Home Assistant’s Template editor to render the expression while you are developing it. Validation catches misspelled entity IDs, indentation errors and assumptions about the source state.

  1. Open the Template editor and paste the state expression, including the set, if and age calculation.
  2. Replace the source ID temporarily with the entity you want to inspect, or keep the variable and verify that it points to the correct ID.
  3. Check that the editor returns True or False, not an error or an empty result.
  4. Inspect the source entity’s state and last_updated value in Developer Tools. Confirm that the timestamp changes when the integration receives the kind of report you intend to monitor.
  5. After creating the entity, inspect the actual binary sensor in Developer Tools and on the dashboard. The editor verifies rendering, but the created entity verifies the configuration context and reload behavior.

To test both branches without waiting, temporarily select a known unavailable or unknown entity, or use a test entity in a non-production configuration. Do not falsify a live safety sensor merely to force a state change.

Put the stale state on a dashboard or in an automation

Dashboard use

Add the binary sensor to an entities card, an alert-style card or another dashboard view that your household or operations team already watches. A problem-class sensor normally displays a problem-oriented label, while a generic class may show ordinary on/off wording. Include the source sensor nearby so a person can see both the value and its freshness signal.

Automation trigger

Use the binary sensor as the trigger rather than repeating the timestamp calculation in every automation. A minimal automation can trigger when the entity changes to on:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
SONOFF NSPanel Pro 120 Smart Control Panel
  • 【All in One Control Panel With】 Enjoy a larger view with the 4.7-inch display that Control your home with just a tap—whether it’s monitoring energy use, viewing live cameras, adjusting the thermostat, managing your lighting or even browsing the web
  • 【Home Security】Customize 3 modes by setting different arming devices. When a sensor is triggered, the panel will sound an alarm and send a notification to your phone
  • 【Power Consumption】 You can select devices with energy statistics functions to track their daily energy consumption over a week
  • 【Camera Viewer】 NSPanel Pro can be used as a display and supports adding the following four types of cameras for live monitoring, allowing real-time views of your living room, garage, bedroom, and more
  • 【Explore Webpages】Listening to music, watching videos, or checking out the latest advice? Save the address in NSPanel Pro’s Webpages, start it quickly with one click, and relax anytime
alias: Notify when outdoor temperature is stale
trigger:
  - platform: state
    entity_id: binary_sensor.outdoor_temperature_stale
    to: 'on'
action:
  - service: persistent_notification.create
    data:
      title: 'Sensor data is stale'
      message: 'The outdoor temperature entity has not supplied a usable recent update.'

Change the notification service and message to fit your installation. Consider adding a condition if alerts should be suppressed during planned maintenance, and add a separate recovery automation when the binary sensor returns to off. The trigger fires when the derived state changes; it does not require every automation to know the source entity’s timestamp rules.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Understand detection timing

A template that reads an entity is reevaluated when the watched state changes. The use of now() adds a periodic refresh: Home Assistant documents that templates containing now() or utcnow() are reevaluated once per minute. Consequently, the stale state can appear up to about one minute after the exact threshold is crossed. This pattern is not a second-by-second watchdog.

For example, with a 900-second limit, the expression becomes true when the source is more than 900 seconds old, but the template may not publish the transition until the next minute refresh. If your alerting requirement is tighter than that, this template alone does not provide the required precision; choose an architecture designed for that timing requirement and verify it against the integration’s behavior.

Home Assistant documents last_changed and last_updated as UTC timestamps, while now() returns the current time in the configured timezone. Home Assistant supports comparisons between aware datetime objects with different zones, so the example can compare the objects directly without manually converting them.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Debug common failure modes

The binary sensor is always on

  • Check the source entity ID character for character. A missing entity is intentionally treated as stale by the example.
  • Inspect the source state. If it remains unknown or unavailable, fix the source integration or change the failure policy only if another outage indicator covers that condition.
  • Inspect last_updated directly. If it is genuinely older than the configured limit, the template is behaving as written.
  • Verify that the threshold is in seconds. A value of 900 means 15 minutes, not 900 minutes.

The binary sensor is always off

  • Confirm that the source is producing a state object and that its timestamp advances when a report arrives.
  • Raise the threshold temporarily to prove that the age comparison can cross the limit, then return it to the value justified by the device cadence.
  • Check that the template was reloaded after editing and that you are looking at the new entity, not an older helper with a similar name.

The value looks current but the timestamp does not change

This usually points to integration semantics rather than Jinja syntax. Some integrations may not create a new state update for every unchanged physical measurement. Review the source integration’s reporting behavior and decide whether last_updated represents the event you actually need to monitor. If it does not, use an integration-provided heartbeat, connectivity state or another explicit update signal instead of assuming the timestamp proves device health.

Best Value
SpeedFreakCNC Wall Mount Compatible with Home Assistant Green - Slim, Secure, Easy to Access Design
  • Only mount plastic mount is included. Home assistant device is not included.
  • Made In USA from High Quality Materials.
  • Secure Mounting — Uses #6 flat head screws (Not Included) for a stable, reliable installation.
  • Easy Access Ports: Design ensures all bottom ports are fully accessible for power, network, and peripheral connections.
  • Cooling-Friendly Design: Open structure allows airflow around cooling fins to help maintain optimal operating temperature.

The template editor works but the entity does not

The editor renders an expression in its own context; it does not prove that the saved helper or YAML entry loaded correctly. Recheck indentation, duplicate top-level template: keys, configuration validation output and the entity’s actual state in Developer Tools. Then reload the relevant template entities or restart Home Assistant as required by your configuration method.

Time behavior seems inconsistent

Do not mix manually created naive datetimes with Home Assistant’s aware datetime objects. Keep the direct subtraction used in the example, and avoid adding timezone conversions unless you have a specific integration requirement. Remember that the one-minute refresh, not just the arithmetic, determines when the threshold transition becomes visible.

Staleness detection is different from retaining a last known value

Home Assistant also documents trigger-based template sensors that can hold a last known value through a temporary unknown or unavailable period. That technique is useful when downstream logic needs continuity, such as displaying the last usable reading. It does not tell you that the retained value is fresh.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use the binary sensor in this article when the goal is to surface age or data quality. Use a retained-value template when the goal is to keep a usable fallback for another calculation. In a robust installation, both can exist: one entity preserves the last value, while another independently warns that the source has not updated within the permitted interval.

Operational checklist

  • Identify the exact source entity and confirm how its integration updates state timestamps.
  • Define whether unknown, unavailable and a missing entity should all count as stale.
  • Choose a limit longer than normal reporting and appropriate to the impact of delayed data.
  • Use now() in the state template and expect a refresh interval of about one minute.
  • Validate the expression in the Template editor, then inspect the created entity in Developer Tools.
  • Place the binary sensor beside the source value on a dashboard so freshness is visible.
  • Trigger notifications or other actions from the binary sensor’s transition to on.
  • Test recovery by confirming that a fresh source update returns the binary sensor to off.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

binary sensorHome AssistantHome Automationsmart hometemplatesYAML

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.