Trigger one automation if any sensor trips

I am trying to write one automation to cover more than one sensor value (battery in this case) by adding more entities. This is a valid configuration, but it does not seem to work.

Does this configuration mean that ALL sensor must be over threshold? How do I configure that triggering is done if ANY sensor trip?

alias: "Battery <5% MSG"
trigger:
  platform: numeric_state
  below: 6
  entity_id:
    - sensor.battery_s1
    - sensor.battery_s2
    - sensor.battery_s3
action:
  service: notify.telegram_bot
  data_template:
    message: >
      {{ trigger.to_state.attributes.friendly_name }}: {{ trigger.to_state.state }}{{ trigger.to_state.attributes.unit_of_measurement }}

That will trip if any one sensor is over threshold (OR condition).

@msd

I have a similar automation…

alias: "Battery <5% MSG"
trigger:
  - platform: numeric_state
    below: 6
    entity_id: sensor.battery_s1
  - platform: numeric_state
    below: 6
    entity_id: sensor.battery_s2
  - platform: numeric_state
    below: 6
    entity_id: sensor.battery_s3

This automation will fire on the event that ANY of the sensors satisfies the “below” state. It is not an exclusive or condition as was previously mentioned here.
It’s perfectly acceptable to list multiple entities as in @msd example.

If it’s not working, my guess is that at least one of the values is stored as a string and not an integer. The documentation for numeric state trigger says “attempts to parse the state as a number and triggers if value is above and/or below a threshold”. In my experience however, if the state is not numeric, the trigger will never happen.

You can easily test this with the template console by pasting in this code:

{{states.sensor.battery_s1.state < 5}}

If the result is “TRUE” or “FALSE” then you have a number.
If the result is “BLANK” then you don’t.

If the value isn’t numeric, you can switch to a template sensor that explicitly does the conversion to numeric.

Thanks! This is interesting: the values are apparently strings, as nothing shows in the console unless I cast to float or int.

Now my config looks like this, it should work:

alias: "Temp <15\u00b0C or >28\u00b0C MSG"
trigger:
  platform: numeric_state
  below: 15
  above: 28
  entity_id: sensor.temperature_s1, sensor.temperature_s2, sensor.temperature_s3
  value_template: '{{ float(state.state) }}'
action:
  service: notify.msd_apps_bot
  data_template:
    message: >
      {{ trigger.to_state.attributes.friendly_name }}: {{ trigger.to_state.state }}{{ trigger.to_state.attributes.unit_of_measurement }}

I added the value_template clause.

It still doesn’t work… I don’t get it…

This sensors look like this btw:

- platform: rest
  resource: http://localhost:3001/sensor/1
  name: Temperature S1
  value_template: '{{ value_json.temperature }}'
  unit_of_measurement: "°C"

but even if I cast to float in the template the automation does not work…

Found out…

The configuration was wrong and the example in the previous post was not the one making problems.

My automation wasn’t working because I had a above and below condition in the same automation.

I see a lot of bad info being spread here multiple times…So once again:

TRIGGERS are “OR” conditions. Not XOR, but OR.

CONDITIONS are “AND” by default; but you can specify them to be OR (read the docs)

If you want AND triggers you need to put the triggers also as conditions… Which is a bit messy and ugly.