Help with Sensor Offline Automation

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

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:

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… :wink:

You can find more here:

Not exactly what you asked for but maybe this can help too
dummylabs/thewatchman: Home Assistant custom integration to keep track of missing entities and services in your config files (github.com)

that did not work when I run the automation I now get no notification at all

Try to share your automation again and I will try to test here.

Please format it properly.

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.

I think I have fixed it with

message: “ALERT THERE IS A SENSOR DOWN: {{ (trigger.entity_id, ‘sensor’) }}”

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 }}”
- 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

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

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

[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:

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. :slightly_smiling_face:

By the way, to you have a pattern to select those sensors? Are all the motion sensors, or motion sensors in a specific area?

great thanks
they just took part of the sensors data for different areas I will add more when fully working

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

the last one did not work for me but the one before with mode queued work fine

1 Like