I have a few Zigbee motion sensors and door sensors, and occasionally some of them will stop updating their state in Home Assistant. I’m not sure why that happens, but it seems to happen sometimes if I’m doing a lot of HA restarts or making changes to my Zigbee network.
I wanted to be able to set up a checklist so that I can walk around my house and trigger all of my sensors and then see which ones aren’t working. Here’s the dashboard view that I set up:
I set up a sensor entity in Node-RED to set a current timestamp. Any entities that haven’t been changed since this timestamp are in the “pending” column, and they move over to the “changed” column once they’ve successfully updated their state.
I set up the switch entity in Node-RED called “Reset Sensor Checklist Timestamp”. I added a restart button to the dashboard, and I trigger the flow using the nodered.trigger
service.
I used the auto-entities Lovelace plugin to set up the entities
cards. I ended up with some complex logic, so I just used a template string to generate the list of entities. (The “Template” tab in the Developer Tools is super helpful!)
The Lovelace view uses the “Panel (1 card)” view type so that the horizontal stack card uses the full width. Here’s the YAML for all the cards:
type: vertical-stack
cards:
- square: false
columns: 5
type: grid
cards:
- show_name: true
show_icon: true
type: button
tap_action:
action: call-service
service: nodered.trigger
service_data: {}
target:
entity_id: switch.reset_sensor_checklist_timestamp
icon: mdi:refresh
show_state: false
icon_height: 24px
theme: synthwave
name: Restart Sensor Checklist
- type: horizontal-stack
cards:
- type: custom:auto-entities
card:
type: entities
title: Pending Sensors
show_empty: false
sort:
method: last_changed
reverse: true
filter:
template: >
[ {%- set entities = [] -%} {%- set changed_before =
states.sensor.sensor_checklist_timestamp.state | int -%} {%- for
entity in states.binary_sensor -%}
{%- set entity_last_changed = (entity.last_changed.timestamp() * 1000) | int -%}
{%-
if (entity.entity_id | regex_search('_occupancy$')
or entity.entity_id | regex_search('_contact$'))
and entity.entity_id != 'binary_sensor.hallway_echo_occupancy'
and entity_last_changed <= changed_before
-%}
{{ {'entity': entity.entity_id,
'secondary_info': 'last-changed'} }},
{%- set battery_entity_id = entity.entity_id
| replace('binary_sensor.', '')
| replace('_occupancy', '_battery')
| replace('_contact', '_battery') -%}
{%- if states.sensor[battery_entity_id] -%}
{{ {'entity': 'sensor.' + battery_entity_id,
'secondary_info': 'last-changed' } }},
{%- endif -%}
{%- endif -%}
{%- endfor %} ]
- type: custom:auto-entities
card:
type: entities
title: Changed Sensors
sort:
method: last_changed
reverse: true
filter:
template: >
[ {%- set entities = [] -%} {%- set changed_before =
states.sensor.sensor_checklist_timestamp.state | int -%} {%- for
entity in states.binary_sensor -%}
{%- set entity_last_changed = (entity.last_changed.timestamp() * 1000) | int -%}
{%-
if (entity.entity_id | regex_search('_occupancy$')
or entity.entity_id | regex_search('_contact$'))
and entity_last_changed > changed_before
-%}
{{ {'entity': entity.entity_id, 'secondary_info': 'last-changed'} }},
{%- endif -%}
{%- endfor %} ]
This works pretty well on mobile too (in landscape), so you can use it as a checklist while you walk around the house.
This was a fun project, and it helped me find 3 sensors that weren’t updating properly. I reset them all and repaired them with my Zigbee mesh and now everything is working. I hope this write-up helps someone else or gives you some ideas!