Group Automation / Templating

Evening All,

I have quite a few Ping sensors as binary_sensors and I want to create an automation that alerts me if any of them go offline. Originally I thought about an automation including each sensor however that is a bit cumbersome

My second thought it to group them together however I realised 2 things:

1: A group would show as online as long as one of the ping monitors where up and down when all were failing

2: I am not sure how to write the automation to include the name of which switch is down.

Here is an example of the binary_sensors:

- platform: ping
  count: 5
  name: "host_1"
  host: 192.168.1.2
  scan_interval: 240

- platform: ping
  count: 5
  name: "host_2"
  host: 192.168.1.2
  scan_interval: 240

I then have this automation for one of them:

- id: "34563452345345"
  alias: Host_1_Offline
  description: "Notify the Team when Host 1 goes offline"
  trigger:
    - entity_id: binary_sensor.host_1
      platform: state
      from: "on"
      to: "off"
  condition:
    - condition: state
      entity_id: input_boolean.maint_mode
      state: "off"
  action:
    - service: notify.msteam
      data:
        message: "HASS has lost connection to Host 1!"
        title: "OFFLINE ALERT"
    - service: rest_command.network_warn
      data:
        msg: "Host 1 Offline"

So the idea is I want the trigger to be a group of any of them going offline and where Host 1 is specified I want that to be variable.

Pretty please could someone offer advice?

Thanks,
Max

Try this:

- id: "34563452345345"
  alias: Host_Offline
  description: "Notify the Team when a host goes offline"
  trigger:
    - platform: state
      entity_id:
        - binary_sensor.host_1
        - binary_sensor.host_2
      from: "on"
      to: "off"
  condition:
    - condition: state
      entity_id: input_boolean.maint_mode
      state: "off"
  action:
    - service: notify.msteam
      data:
        message: "HASS has lost connection to {{ trigger.to_state.object_id }}!"
        title: "OFFLINE ALERT"
    - service: rest_command.network_warn
      data:
        msg: "{{ trigger.to_state.object_id }} Offline"

That works perfectly thank you.

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved.