Ok I have a bunch of Zigbee sensors and they sometimes drop off the network and I don’t know about it until some automation doesn’t work. How can I use a single automation to let me know which one is unavailable. I know how to set it up to TRIGGER (I put all the sensors in the automation IF statement), however how do I write (and where does it go) the yaml to show which one alerted without doing a dozen if statements like I did the trigger?
You’d use a template to get the entity_id out of the trigger object. It’s different for every trigger type, so you’d have to post the automation for further help.
Here are some methods to keep the zigbee mesh healthy so this may be not needed. Several posts in this section could be helpful to you. The Home Assistant Cookbook - Index
Solution For Bad Zigbee Network
I’ll answer your question but firstly consider a zigbee mesh router. They come in a few form factors and are easy to setup. But essentially what they do is repeat the zigbee signal to extended your zigbee network reach and performance. Best to fix your network problems when you get the chance.
the one I’m using is a cheap outlet plug with power metering and oncourse doubles as a zigbee router. you can get a 4pack for $38.
Automation For Offline Devices
alias: Notify Offline Zigbee Devices
description: Checks for unavailable devices and announces them via TTS
triggers:
- trigger: time_pattern
hours: /1
conditions: []
actions:
- variables:
zigbee_entities: "{{ integration_entities('zha') }}"
unavailable_entities: >-
{{ states | selectattr('entity_id', 'in', zigbee_entities) |
selectattr('state', 'eq', 'unavailable') | map(attribute='entity_id') |
list }}
device_ids: >-
{{ unavailable_entities | map('device_id') | unique | reject('eq', none)
| list }}
unavailable_names: "{{ device_ids | map('device_attr', 'name') | list }}"
message: >-
{% if unavailable_names | count == 1 %}Your device {{
unavailable_names[0] }} is offline.{% else %}Your devices {{
unavailable_names[:5] | join(', ') }}{% if unavailable_names | count > 5
%} and {{ unavailable_names | count - 5 }} more{% endif %} are
offline.{% endif %}
- condition: template
value_template: "{{ unavailable_names | count > 0 }}"
- action: tts.speak
metadata: {}
data:
cache: true
message: "{{ message }}"
target:
entity_id: tts.google_translate_en_com
mode: single
Create a new automation in the GUI and click edit in yaml and paste this code then go back to visual editor and change your media player in the tts.speak.
It’s the battery-powered Aqara vibration sensors and Aqara door opening sensors, they always drop off for some reason even though they’re right next to a plugged in the wall repeater. It’s not a questions of the network, it’s just something they do sometimes. I made an interim automation that just tells me when one of the many battery-powered sensors go down but it just says SOME sensor went down because I hadn’t figured how to have it alert me on which specific sensor went down. It dings my phone and announces a general sensor outage over TTS. I’ll try the code above but it really messes me up HOW to apply this.
EDIT: I shouldn’t say they always drop off. However, they drop off more frequently than I’d like them to. Mostly the vibration sensors - maybe twice a month. The door ones are like once every 3 months.
The problem with the code above is that it only checks once an hour. Where as what you described in your original post was related to instant messages.
So if you just explain what trigger you plan on using… it will really make this a simple automation.
e.g.
triggers:
trigger: state
entity_id:
- sensor.1
- sensor.2
- sensor.3
to: unavailable
actions:
- action: notify.abc
data:
message: "{{ trigger.to_state.name }} is unreachable"
This is what I currently have. My trouble is how to get it to report which sensor went down instead of generic “something’s gone down”
alias: Zigbee Sensor Unavailable
description: ""
triggers:
- device_id: b734a18173a122f4bbcdbf0f3d322e64
domain: zha
type: device_offline
subtype: device_offline
trigger: device
- device_id: 77bb728f25ca5218d7694e55e008bf2d
domain: zha
type: device_offline
subtype: device_offline
trigger: device
- device_id: b7e9aaed64c8311a53d89a866eea1637
domain: zha
type: device_offline
subtype: device_offline
trigger: device
- device_id: 52f14a648f34aa0b119a6af7d501a9a3
domain: zha
type: device_offline
subtype: device_offline
trigger: device
- device_id: 647cb417aeebcd35f0ac05dfd2490db5
domain: zha
type: device_offline
subtype: device_offline
trigger: device
- device_id: 29353ceef3ea3391c86d95b842274608
domain: zha
type: device_offline
subtype: device_offline
trigger: device
- device_id: 5a1a73aea56d0d81d936329026883301
domain: zha
type: device_offline
subtype: device_offline
trigger: device
- device_id: dafaf8e24b2b2f24be8534338e583d22
domain: zha
type: device_offline
subtype: device_offline
trigger: device
- device_id: 2090995a4df786c635359abef9c70749
domain: zha
type: device_offline
subtype: device_offline
trigger: device
- device_id: 8d8d50fe86da169c15fe39bc5e91553b
domain: zha
type: device_offline
subtype: device_offline
trigger: device
- device_id: 5f44d772e90b0f1fef291c9a04c8cd90
domain: zha
type: device_offline
subtype: device_offline
trigger: device
- device_id: 655624196b8fbb77aaaddf450373e1b8
domain: zha
type: device_offline
subtype: device_offline
trigger: device
- device_id: 931b683c474b5272593f24d2d9f60aae
domain: zha
type: device_offline
subtype: device_offline
trigger: device
conditions: []
actions:
- action: input_boolean.turn_on
metadata: {}
data: {}
target:
entity_id: input_boolean.zigbee_sensor_down
- action: notify.mobile_app_xxxxxxxx
metadata: {}
data:
message: Zigbee sensor down
mode: single
For that automation, you can switch it to entity triggers. If you don’t want to do that, can you post a trace for it? Need to see the data in the trigger in order to modify that to ouput which device triggered it.
Ok I re-did it with entity only:
alias: Zigbee Sensor Unavailable
description: ""
triggers:
- trigger: state
entity_id:
- binary_sensor.dryer_vibration
- binary_sensor.washer_vibration_motion
- binary_sensor.front_door_contact_opening
- sensor.button_1_battery
- binary_sensor.family_rm_pool_door_opening
- binary_sensor.dining_rm_pool_door_opening
- binary_sensor.garage_courtyard_door_opening
- binary_sensor.office_courtyard_door_opening
- binary_sensor.pool_bathroom_door_opening
- binary_sensor.mb_toilet_leak_moisture_3
- binary_sensor.mb2_toilet_leak
- binary_sensor.pinkbath_toilet_leak_moisture_3
- binary_sensor.garage_courtyard_door_sensor
to: unavailable
for:
hours: 0
minutes: 5
seconds: 0
conditions: []
actions:
- action: input_boolean.turn_on
metadata: {}
data: {}
target:
entity_id: input_boolean.zigbee_sensor_down
- action: notify.mobile_app_xxxxxxxxx
metadata: {}
data:
message: Zigbee sensor down
mode: single
alias: Zigbee Sensor Unavailable
description: ""
triggers:
- trigger: state
entity_id:
- binary_sensor.dryer_vibration
- binary_sensor.washer_vibration_motion
- binary_sensor.front_door_contact_opening
- sensor.button_1_battery
- binary_sensor.family_rm_pool_door_opening
- binary_sensor.dining_rm_pool_door_opening
- binary_sensor.garage_courtyard_door_opening
- binary_sensor.office_courtyard_door_opening
- binary_sensor.pool_bathroom_door_opening
- binary_sensor.mb_toilet_leak_moisture_3
- binary_sensor.mb2_toilet_leak
- binary_sensor.pinkbath_toilet_leak_moisture_3
- binary_sensor.garage_courtyard_door_sensor
to: unavailable
for:
hours: 0
minutes: 5
seconds: 0
conditions: []
actions:
- action: input_boolean.turn_on
metadata: {}
data: {}
target:
entity_id: input_boolean.zigbee_sensor_down
- action: notify.mobile_app_xxxxxxxxx
metadata: {}
data:
message: "{{ trigger.to_state.name }} sensor down"
mode: single
Thank you! This looks good. I’ve seen this before but didn’t know the exact format. The {{ trigger…}} part was exactly what I was missing.
