Same automation for multiple sensors (individually)

Hi,

I would like to automate notifications for event per sensor. In my actual case I want to check every humidity sensor if it is higher than a given number, if yes I would like to trigger a notify.notify. This should be done per sensor basis, like it would be the case if only one sensor where defined. I try to avoid to write the same automation code for every sensor.

So my target is to define one automation and apply it to multiple sensors.

My actual automation yaml looks like

- id: humidity-warning-60
  alias: Humidity higher 60%
  trigger:
  - platform: numeric_state
    entity_id:
    - sensor.humidity1
    - sensor.humidity2
    # - many other sensors
    above: '60'
    for: 00:01:00
  action:
  - service: notify.notify
    data:
      title:  Humidity
      message: Humidity higher 60%
  mode: single

Right now it seems that it only trigger the action when all entities reach the > 60 state. I also would like to send the notification with the actual entity name which reached the > 60 state.

Is there an easy way to do that or maybe I do something wrong? (without writing 30 automation for 30 sensors)

Thanks in advance
Michael

Don’t know whether this will help or not…

I have an automation that alerts me when the temperature in my IT cupboard gets above 30C, but after that it continues sending alerts as the temperature rises. Rather than have a specific temperature as the trigger (which would only fire once), it fires whenever the temperature changes if it is above 30C. Then a condition checks to see whether the temperature is higher than it was on the last alert.

- id: '1626777655149'
  alias: Study IT cupboard too hot
  description: Sends SMS message when study IT cupboard gets too hot
  trigger:
  - platform: state
    entity_id: sensor.wirelesstag_it_cupboard_temperature
  condition:
  - condition: template
    value_template: '{{ trigger.to_state.state | float > 30 }}'
  action:
  - condition: numeric_state
    entity_id: sensor.wirelesstag_it_cupboard_temperature
    above: input_number.it_cupboard_temperature
  - service: notify.mobile
    data:
      message: Temperature in study IT cupboard is {{ states('sensor.wirelesstag_it_cupboard_temperature')
        }}
      data:
        priority: normal
        device: REVOVIEW IMO Q4 Pro
  - service: logbook.log
    data:
      name: Temperature
      message: SMS notification sent - study cupboard {{     states('sensor.wirelesstag_it_cupboard_temperature')
        }}
  - service: input_number.increment
    target:
      entity_id: input_number.it_cupboard_temperature
  mode: single

Could this be adapted somehow? With the “many other sensors” in the conditional part of the action? Maybe not - you still have to monitor them all somehow.

Hey @Stiltjack ,

I removed the for parameter and now it seems to work fine now. It seems that the trigger get fired when one entity reach the > 60 state. I think this would also solve your “problem” that you get a notification everything, because HA make sure that the trigger will only fire once.

The only thing which is left is the friendly name. I can only get the entity_id, not the friendly name

action:
  - service: notify.notify
    data:
      title: Humidity
      message: Humidity over 60% in {{ trigger.entity_id }} {{ trigger.name }}

I now get Humidity over 60% in sensor.humidity1

trigger.name don’t get resolved to a name. Do you know how to get the friendly name, the entity_id is not really nice to read.

That will trigger when any of those entities goes to above 60 for a minute.

1 Like

The correct way for the friendly name is

action:
  - service: notify.notify
    data:
      title: Humidity
      message: Humidity over 60% in {{ trigger.to_state.attributes.friendly_name }}
1 Like