#combined multiple sensor notifications

1 messages · Page 1 of 1 (latest)

flint leaf
#
description: ""
trigger:
  - type: temperature
    platform: device
    device_id: xxxxxxxxxxxxxx
    entity_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    domain: sensor
    above: 25
    below: 10
    for:
      hours: 0
      minutes: 1
      seconds: 0
  - type: temperature
    platform: device
    device_id: xxxxxxxxxxxxxxxxxxxx
    entity_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    domain: sensor
    above: 25
    below: 10
    for:
      hours: 0
      minutes: 1
      seconds: 0
condition: []
action: []
mode: single
#

I want to send a notification if any one of these sensor is out of range, a notification will be sent with temperature and humidty values

#

for a single sensor it is simple ```action:

  • service: notify.persistent_notification
    data:
    title: Waste Room Temperature Alert!!
    message: >-
    current Temperature is:
    {{states('sensor.a4_cxxxxxxxx_temperature',with_unit=true) }}
    Humidity is: {{
    states('sensor.a4_xxxxxxxxxxxxxxx_humidity',with_unit=true) }}
  • service: notify.ha_temp_email
    data:
    title: Waste Room Temperature Alert!!
    message: >-
    current Temperature is:
    {{states('sensor.a4_xxxxxxxxxxxxxxxxx_temperature',with_unit=true) }}
    Humidity is: {{
    states('sensor.a4_xxxxxxxxxxxxxxxx_humidity',with_unit=true) }}
    enabled: true
    mode: single```
#

came up with this service: notify.persistent_notification data: title: Waste Room Temperature Alert!! message: >- Temperature out of range : {{ trigger.to_state.name }} is above 18 Humidity is: {{ states('sensor.a4_xxxxxxxxxxxxxxx_humidity',with_unit=true) }}

#

got this error Error rendering data template: UndefinedError: 'trigger' is undefined

cunning briar
#

are you using the RUN button in the automation GUI to test?

#

in that case there is no trigger, so trigger variables won't work

#

BTW no need to censor those entity_ids en device_ids, they are just randomly created by HA to generate a unique id

#

Think of it this way, if you press RUN, how should HA know which of the two triggers to use?

flint leaf
#

okay

#

otherwise I wrote it correctly?

cunning briar
#

looks fine, I would use state triggers though

#

you should be able to test the automation by changing the state in devtools > states, but I'm not 100% sure if that works with device trigger

flint leaf
cunning briar
#

Wait, numeric state in this case

#
- platform: numeric_state
  entity_id: xxxxxx
  above: 25
  below: 10
  for:
    minutes: 1
flint leaf
#

not working

cunning briar
#

That's not really a lot of information you are giving. What's not working?

flint leaf
#

can't save it gives error at data(0)

#

let me post the complete automation

#

notification generated ```Pump room temperature Alert!!
is above 24C

#
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.pump_room1_f7e5_temperature
    for:
      hours: 0
      minutes: 1
      seconds: 0
    above: 24
  - platform: numeric_state
    entity_id: sensor.a4_c1_38_85_14_c4_14c4_temperature
    above: 24
    for:
      hours: 0
      minutes: 1
      seconds: 0
  - platform: numeric_state
    entity_id: sensor.a4_c1_38_85_14_c4_14c4_temperature
    for:
      hours: 0
      minutes: 1
      seconds: 0
    below: 15
  - platform: numeric_state
    entity_id: sensor.pump_room1_f7e5_temperature
    for:
      hours: 0
      minutes: 1
      seconds: 0
    below: 15
condition: []
action:
  - service: notify.persistent_notification
    data:
      title: Pump room temperature Alert!!
      message: "{{ trigger.entity_id }} is above 24C"
mode: single
flint leaf
#

why I can't save new automation even after changing data? there is no save button

cunning briar
#

There's something wrong with the automation config itself

#

I don't see it though

flint leaf
#

notification Pump room temperature Alert!! is above 24C

cunning briar
#

Are you pressing the RUN button in the GUI to test?

flint leaf
#

yes

#

three dots and click run

cunning briar
#

That doesn't work with trigger variables. How do you expect HA to tell which entity triggered an automation if it wasn't triggered by an entity

flint leaf
#

Hmm. I should change the trigger value to test it

cunning briar
#

Change the state in developer tools > states

flint leaf
#

Okay

flint leaf
#

can't change it in dev tools > states

#

found a way

#
sensor.pump_room1_f7e5_temperature is above 24C```
#

worked

cunning briar
#

Sure you can

flint leaf
#

How do change sensors names now to something sensible

#

I am using BTHOME integration

cunning briar
#

Change the value in the circle and then press the button to test

#

Change the name in the entity details

flint leaf
#

Yes it worked with this method

flint leaf
#

Can't post screen shots here

cunning briar
flint leaf
#

So should change entity I'd?

cunning briar
#

Depends

#

You asked about changing the name

#

So that's the top field there

flint leaf
#
sensor.pump_room1_f7e5_temperature is above 24C``` this was generated as notification
#

Name is correct I want name in notifications

#

Something on these line ``` Pump room temperature Alert!!
Pump room temperature is 30C which is above 24C

cunning briar
#

Use trigger.to_state.name

flint leaf
#
Pump 1 Temperature is above 24C```
#
Pump 2 Temperature is above 24C```
#

how to change the notifcation if temp goes below the range?

cunning briar
#

Lots of options

#
  • Two different automations
  • use a choose action and trigger ids
  • use #templates-archived to define the message based on the to_state of the trigger
flint leaf
#

one automation has 7 sensors!!!

#

which pathway I should choose?

cunning briar
#

The one you prefer

#

Btw, you can use one trigger for all entities

#
alias: Pump temperature trial
trigger:
  - platform: numeric_state
    entity_id: 
      - sensor.pump_room1_f7e5_temperature
      - sensor.a4_c1_38_85_14_c4_14c4_temperature
    for:
      minutes: 1
    above: 24
    id: high
  - platform: numeric_state
    entity_id: 
      - sensor.a4_c1_38_85_14_c4_14c4_temperature
      - sensor.pump_room1_f7e5_temperature
    for:
      minutes: 1
    below: 15
    id: low
action:
  - if:
      - condition: trigger
        id: high
    then:
      - service: notify.persistent_notification
        data:
          title: "{{ trigger.to_state.name | title }} temperature Alert!!"
          message: "{{ trigger.to_state.name }} is above 24C"
    else:
      - service: notify.persistent_notification
        data:
          title: "{{ trigger.to_state.name | title }} temperature Alert!!"
          message: "{{ trigger.to_state.name }} is below 15C"
mode: single
#

this is the 2nd option with the choose

#
alias: Pump temperature trial
trigger:
  - platform: numeric_state
    entity_id: 
      - sensor.pump_room1_f7e5_temperature
      - sensor.a4_c1_38_85_14_c4_14c4_temperature
    for:
      minutes: 1
    above: 24
    id: high
  - platform: numeric_state
    entity_id: 
      - sensor.a4_c1_38_85_14_c4_14c4_temperature
      - sensor.pump_room1_f7e5_temperature
    for:
      minutes: 1
    below: 15
    id: low
action:
  - service: notify.persistent_notification
    data:
      title: "{{ trigger.to_state.name | title }} temperature Alert!!"
      message: "{{ trigger.to_state.name }} is {{ 'above 24' if trigger.id == 'high' else 'below 15' }}C"
mode: single
#

And this is option 3

flint leaf
#

both use ids?

cunning briar
#

Basically I only use high in both examples

#

But both examples use trigger ids yes

#

You can also use other ways, you can use the state as well

flint leaf
#
Pump 1 Temperature is above 24C

cunning briar
#

Okay, I assume the entity is named Pump 1 then

flint leaf
#

yes

cunning briar
#

So it works then

flint leaf
#

yes

#

need to copy this and modify it for 18 entities