gatd4
(gatd4)
October 10, 2022, 9:36am
1
please can someone help me
I have created an automation which notifies me when a sensor goes unavailable which works fine but the only problem is it does not tell me which sensor it was. I really need to Know which sensor it was.
thanks
here is my automation
id: '1664702339359'
alias: Sensors Offline
description: ''
trigger:
- platform: state
entity_id:
- binary_sensor.front_door_motion
- binary_sensor.motion_sensor_bathroom_motion
- binary_sensor.hue_motion_sensor_1_motion
- binary_sensor.motion_sensor_bedroom_motion
- binary_sensor.motion_sensor_hallway_down_motion
- binary_sensor.motion_sensor_hallway_up_motion
- binary_sensor.motion_sensor_kitchen_hallway_motion
- binary_sensor.motion_sensor_kitchen_motion
- binary_sensor.motion_sensor_toilet_motion
- binary_sensor.motion_sensor_studio_motion
- binary_sensor.motion_sensor_kids_bathroom_motion
- binary_sensor.motion_sensor_lounge_motion
- binary_sensor.lounge_camera_motion
- sensor.hallway_wifi_signal_strength
- sensor.nuki_front_door_lock_rssi
- binary_sensor.hive_hub_status
- sensor.front_door_wifi_signal_strength
to: unavailable
for:
hours: 0
minutes: 1
seconds: 0
condition: []
action:
- service: notify.mobile_app_iphone_14_pro_max
data:
message: 'ALERT THERE IS A SENSOR DOWN: {{sensors}}'
title: SENSOR NOW OFFLINE
mode: single
EdwardTFN
(Edward Firmo)
October 10, 2022, 9:40am
2
Try this:
message: "ALERT THERE IS A SENSOR DOWN: {{ state_attr(trigger.entity_id, 'friendly_name') }}"
You can find more about Trigger variables in the HA docs:
EdwardTFN
(Edward Firmo)
October 10, 2022, 9:49am
3
By the way, Iād like to friendly recommend you to format you code properly when publishing, as it would make much easier for people to understand and troubleshoot. Sometimes itās just about a missing blank space which is almost impossible to see if your code is not formatted properly. And itās just one single click moreā¦
You can find more here:
Before we beginā¦
This forum is not a helpdesk
The people here donāt work for Home Assistant, thatās an open source project. We are volunteering our free time to help others. Not all topics may get an answer, never mind one that helps you solve your problem.
[image]
This also isnāt a general home automation forum, this is a forum for Home Assistant and things related to it. Any question about Home Assistant, and about using things with Home Assistant, is welcome here. We canāt help you with eā¦
gatd4
(gatd4)
October 10, 2022, 10:02am
5
that did not work when I run the automation I now get no notification at all
EdwardTFN
(Edward Firmo)
October 10, 2022, 10:16am
6
Try to share your automation again and I will try to test here.
Please format it properly.
EdwardTFN
(Edward Firmo)
October 10, 2022, 10:19am
7
How are you running the automation? If you just run it with the UI it will fail, as Trigger variable is not defined.
Try to disconnect one of the devices for a minute and make sure it isnāt workingā¦ Take a look at your logs in case it fails.
gatd4
(gatd4)
October 10, 2022, 10:20am
8
I think I have fixed it with
message: āALERT THERE IS A SENSOR DOWN: {{ (trigger.entity_id, āsensorā) }}ā
EdwardTFN
(Edward Firmo)
October 10, 2022, 10:28am
9
If you include just entity_id
it will show only the entity id, which might be OK for you. The one I sent was the entity friendly name, which is the name you see in the dashboards (and your family might be more used to).
But anyways, if you want the Iād only, it should be like this:
message: āALERT THERE IS A SENSOR DOWN: {{ trigger.entity_id }}ā
gatd4
(gatd4)
October 10, 2022, 10:30am
10
- id: '1664702339359'
alias: Sensors Offline
description: ''
trigger:
- platform: state
entity_id:
- binary_sensor.front_door_motion
- binary_sensor.motion_sensor_bathroom_motion
- binary_sensor.hue_motion_sensor_1_motion
- binary_sensor.motion_sensor_bedroom_motion
- binary_sensor.motion_sensor_hallway_down_motion
- binary_sensor.motion_sensor_hallway_up_motion
- binary_sensor.motion_sensor_kitchen_hallway_motion
- binary_sensor.motion_sensor_kitchen_motion
- binary_sensor.motion_sensor_toilet_motion
- binary_sensor.motion_sensor_studio_motion
- binary_sensor.motion_sensor_kids_bathroom_motion
- binary_sensor.motion_sensor_lounge_motion
- binary_sensor.lounge_camera_motion
- sensor.hallway_wifi_signal_strength
- sensor.nuki_front_door_lock_rssi
- binary_sensor.nuki_front_door_lock_locked
- binary_sensor.nuki_front_door_lock_door_open
- binary_sensor.nuki_bridge_connected
- binary_sensor.hive_hub_status
- sensor.front_door_wifi_signal_strength
to: unavailable
for:
hours: 0
minutes: 0
seconds: 30
condition: []
action:
- service: notify.mobile_app_iphone_14_pro_max
data:
message: "ALERT THERE IS A SENSOR DOWN: {{ (trigger.entity_id, 'sensor') }}"
title: SENSOR NOW OFFLINE
mode: single
EdwardTFN
(Edward Firmo)
October 10, 2022, 10:35am
11
Great! Much easier nowā¦
Anyways, Iāve tested with the friendly name and it worked just fine:
alias: Sensors Offline
description: ""
trigger:
- platform: state
entity_id:
- binary_sensor.front_door_motion
- binary_sensor.motion_sensor_bathroom_motion
- binary_sensor.hue_motion_sensor_1_motion
- binary_sensor.motion_sensor_bedroom_motion
- binary_sensor.motion_sensor_hallway_down_motion
- binary_sensor.motion_sensor_hallway_up_motion
- binary_sensor.motion_sensor_kitchen_hallway_motion
- binary_sensor.motion_sensor_kitchen_motion
- binary_sensor.motion_sensor_toilet_motion
- binary_sensor.motion_sensor_studio_motion
- binary_sensor.motion_sensor_kids_bathroom_motion
- binary_sensor.motion_sensor_lounge_motion
- binary_sensor.lounge_camera_motion
- sensor.hallway_wifi_signal_strength
- sensor.nuki_front_door_lock_rssi
- binary_sensor.nuki_front_door_lock_locked
- binary_sensor.nuki_front_door_lock_door_open
- binary_sensor.nuki_bridge_connected
- binary_sensor.hive_hub_status
- sensor.front_door_wifi_signal_strength
to: unavailable
for:
hours: 0
minutes: 0
seconds: 30
condition: []
action:
- service: notify.mobile_app_iphone_14_pro_max
data:
message: "ALERT THERE IS A SENSOR DOWN: {{ state_attr(trigger.entity_id, 'friendly_name') }}"
title: SENSOR NOW OFFLINE
mode: single
gatd4
(gatd4)
October 10, 2022, 10:39am
12
just checked you where right needed to take the sensor offline for it to work
last thing it only sends one sensor message I pulled the hub so lots went down but I got only one message for one sensor
thanks a lot for all your help
EdwardTFN
(Edward Firmo)
October 10, 2022, 12:33pm
13
[quote=āEdwardTFN, post:11, topic:472810ā]
mode: single
[/quote
Try to change this to parallel or queued:
alias: Sensors Offline
description: ""
trigger:
- platform: state
entity_id:
- binary_sensor.front_door_motion
- binary_sensor.motion_sensor_bathroom_motion
- binary_sensor.hue_motion_sensor_1_motion
- binary_sensor.motion_sensor_bedroom_motion
- binary_sensor.motion_sensor_hallway_down_motion
- binary_sensor.motion_sensor_hallway_up_motion
- binary_sensor.motion_sensor_kitchen_hallway_motion
- binary_sensor.motion_sensor_kitchen_motion
- binary_sensor.motion_sensor_toilet_motion
- binary_sensor.motion_sensor_studio_motion
- binary_sensor.motion_sensor_kids_bathroom_motion
- binary_sensor.motion_sensor_lounge_motion
- binary_sensor.lounge_camera_motion
- sensor.hallway_wifi_signal_strength
- sensor.nuki_front_door_lock_rssi
- binary_sensor.nuki_front_door_lock_locked
- binary_sensor.nuki_front_door_lock_door_open
- binary_sensor.nuki_bridge_connected
- binary_sensor.hive_hub_status
- sensor.front_door_wifi_signal_strength
to: unavailable
for:
hours: 0
minutes: 0
seconds: 30
condition: []
action:
- service: notify.mobile_app_iphone_14_pro_max
data:
message: "ALERT THERE IS A SENSOR DOWN: {{ state_attr(trigger.entity_id, 'friendly_name') }}"
title: SENSOR NOW OFFLINE
mode: queued
max: 20
max_exceeded: warning
For more details:
EdwardTFN
(Edward Firmo)
October 10, 2022, 12:48pm
14
Changing mode will allow the automation to run multiple times. That might be a solution here, but probably not the best one.
I can work a bit more to improve the message in order to show all the sensors on that state, but I do this when Iām back home as it would be hard to do in my phone.
By the way, to you have a pattern to select those sensors? Are all the motion sensors, or motion sensors in a specific area?
gatd4
(gatd4)
October 10, 2022, 1:36pm
15
great thanks
they just took part of the sensors data for different areas I will add more when fully working
EdwardTFN
(Edward Firmo)
October 10, 2022, 4:27pm
16
Itās easier to list all entities with unavailable state than select a list, unless you have a pattern that could be create a list dynamically or using a group (which has no UI) or a Blueprint.
But try this to understand what Iām talking about. As Iām not using trigger variable, you can run/test without disconnecting your devices.
alias: Sensors Offline
description: ""
trigger:
- platform: state
entity_id:
- binary_sensor.front_door_motion
- binary_sensor.motion_sensor_bathroom_motion
- binary_sensor.hue_motion_sensor_1_motion
- binary_sensor.motion_sensor_bedroom_motion
- binary_sensor.motion_sensor_hallway_down_motion
- binary_sensor.motion_sensor_hallway_up_motion
- binary_sensor.motion_sensor_kitchen_hallway_motion
- binary_sensor.motion_sensor_kitchen_motion
- binary_sensor.motion_sensor_toilet_motion
- binary_sensor.motion_sensor_studio_motion
- binary_sensor.motion_sensor_kids_bathroom_motion
- binary_sensor.motion_sensor_lounge_motion
- binary_sensor.lounge_camera_motion
- sensor.hallway_wifi_signal_strength
- sensor.nuki_front_door_lock_rssi
- binary_sensor.nuki_front_door_lock_locked
- binary_sensor.nuki_front_door_lock_door_open
- binary_sensor.nuki_bridge_connected
- binary_sensor.hive_hub_status
- sensor.front_door_wifi_signal_strength
to: unavailable
for:
hours: 0
minutes: 0
seconds: 30
condition: []
action:
- service: notify.mobile_app_iphone_14_pro_max
data:
message: >-
Attention! There are {{ states
| selectattr('state', 'eq', 'unavailable')
| map(attribute='entity_id')
| list
| count
}} sensors unavailable:
- {{ states
| selectattr('state', 'eq', 'unavailable')
| map(attribute='entity_id')
| list
| join('
- ')
}}
title: SENSORS UNAVAILABLE
mode: single
gatd4
(gatd4)
October 10, 2022, 6:53pm
17
the last one did not work for me but the one before with mode queued work fine
1 Like