I need to create an automation that monitors the state of multiple sensors of the same ‘device_class’ (eg. temperature) and then sends a notification to my phone/email if the value drops below certain point with details of which specific sensor triggered it and numeric values
Write your automation triggers and a dummy message action, post it here, then we can show you how to add the details you want to the message using templates and trigger variables.
message: "{{ trigger.to_state.name }} detected high temperature of {{ trigger.to_state.state }}° C"
To test it, don’t use the automation’s Run command because that only executes the automation’s action and skips trigger and condition (therefore the trigger variable used in the template will be undefined).
NOTE
Your automation uses three Numeric Device Triggers. They’re meant to be convenient to use when creating triggers via the Visual Automation Editor. The problem is that, in YAML format, they’re verbose and cryptic (the latest version of Home Assistant no longer even uses the entity’s human-readible entity_id but a long cryptic string of numbers and letters).
In contrast, a Numeric State Trigger would look something like this in YAML format:
That’s one Numeric State Trigger monitoring three sensors and triggering when the value of any of them increases and crosses the threshold of 24. Compare how compact and legible it is to three separate Numeric Device Triggers.
Almost wish there was a blueprint like below but for other types of sensors (not batteries):
blueprint:
name: Low battery level detection & notification for all battery sensors
description: Regularly test all sensors with 'battery' device-class for crossing
a certain battery level threshold and if so execute an action.
domain: automation
input:
threshold:
name: Battery warning level threshold
description: Battery sensors below threshold are assumed to be low-battery (as
well as binary battery sensors with value 'on').
default: 20
selector:
number:
min: 5.0
max: 100.0
unit_of_measurement: '%'
mode: slider
step: 5.0
time:
name: Time to test on
description: Test is run at configured time
default: '10:00:00'
selector:
time: {}
day:
name: Weekday to test on
description: 'Test is run at configured time either everyday (0) or on a given
weekday (1: Monday ... 7: Sunday)'
default: 0
selector:
number:
min: 0.0
max: 7.0
mode: slider
step: 1.0
exclude:
name: Excluded Sensors
description: Battery sensors (e.g. smartphone) to exclude from detection. Only
entities are supported, devices must be expanded!
default:
entity_id: []
selector:
target:
entity:
device_class: battery
actions:
name: Actions
description: Notifications or similar to be run. {{sensors}} is replaced with
the names of sensors being low on battery.
selector:
action: {}
source_url: https://gist.github.com/sbyx/1f6f434f0903b872b84c4302637d0890
variables:
day: !input 'day'
threshold: !input 'threshold'
exclude: !input 'exclude'
sensors: "{% set result = namespace(sensors=[]) %} {% for state in states.sensor\
\ | selectattr('attributes.device_class', '==', 'battery') %}\n {% if 0 <= state.state\
\ | int(-1) < threshold | int and not state.entity_id in exclude.entity_id %}\n\
\ {% set result.sensors = result.sensors + [state.name ~ ' (' ~ state.state\
\ ~ ' %)'] %}\n {% endif %}\n{% endfor %} {% for state in states.binary_sensor\
\ | selectattr('attributes.device_class', '==', 'battery') | selectattr('state',\
\ '==', 'on') %}\n {% if not state.entity_id in exclude.entity_id %}\n {%\
\ set result.sensors = result.sensors + [state.name] %}\n {% endif %}\n{% endfor\
\ %} {{result.sensors|join(', ')}}"
trigger:
- platform: time
at: !input 'time'
condition:
- '{{ sensors != '''' and (day | int == 0 or day | int == now().isoweekday()) }}'
action:
- choose: []
default: !input 'actions'
mode: single
If the Nest sensor reports temperature in a Temperature attribute, as opposed to in its state, then you will need to use a separate Numeric State Trigger for it.
alias: Testing
description: ""
trigger:
- platform: numeric_state
entity_id:
- sensor.nest_thermo_temperature
attribute: Temperature
above: 24
- platform: numeric_state
entity_id:
- sensor.king_thsensor_t
- sensor.queen_thsensor_t
- sensor.princess_thsensor_t
- sensor.professor_thsensor_t
above: 24
condition: []
action:
- service: notify.mobile_app_wald
data:
message: "{{ trigger.to_state.name }} detected high temperature of {{ trigger.to_state.state }}° C"
mode: single
Let me know if I got that right or if it’s some other sensor that reports temperature in a Temperature attribute. It’s important to get this right otherwise the automation will be monitoring the wrong values.
In that case, a single Numeric State Trigger monitoring the Temperature attribute is what’s needed.
alias: Testing
description: ""
trigger:
- platform: numeric_state
entity_id:
- sensor.nest_thermo_temperature
- sensor.king_thsensor_t
- sensor.queen_thsensor_t
- sensor.princess_thsensor_t
- sensor.professor_thsensor_t
attribute: Temperature
above: 24
condition: []
action:
- service: notify.mobile_app_wald
data:
message: "{{ trigger.to_state.name }} detected high temperature of {{ trigger.to_state.state }}° C"
mode: single
I repeat that it’s important to get this right, otherwise the automation won’t be monitoring the correct values. Home Assistant doesn’t complain if you tell it to monitor the value of a sensor attribute that doesn’t exist (and the result is an automation that never triggers).