Notifications with sensor names details

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

Any help will be greatly appreciated!

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.

Thanks! Below is the base automation

description: ""
mode: single
trigger:
  - type: temperature
    platform: device
    device_id: 6bd1713222d1f058c1643990afa3cc56
    entity_id: ca169d5a5f37188952314d1ed5b04b77
    domain: sensor
    above: 24
  - type: temperature
    platform: device
    device_id: dd1ca49ada522262eb463055b8b584df
    entity_id: 02454e4a1197d5dbeecffa1615ae2ed6
    domain: sensor
    above: 24
  - type: temperature
    platform: device
    device_id: e68e11538b39397e843ad62b1bf6d59b
    entity_id: 5ae4b53ca8638260d75d0e5be11426a0
    domain: sensor
    above: 24
  - type: temperature
    platform: device
    device_id: 366cf267c52e03b320349e37f69580f2
    entity_id: 9ca0bcc976abb109c31bc61a311e6378
    domain: sensor
    above: 24
  - type: temperature
    platform: device
    device_id: 3c8f8755ecf9bbd1f90b9f8a4cf5f0bd
    entity_id: 56a6c72bc79c8a2009ab38fd2d078c19
    domain: sensor
    above: 24
condition: []
action:
  - service: notify.mobile_app_wald
    data:
      message: "[Sensor] detected high temperature of xx° C"
alias: Test

Can you use numeric state triggers acting on actual entity ids rather than device triggers please?

Entity id of the form sensor.something

      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:

  - platform: numeric_state
    entity_id: 
      - sensor.kitchen
      - sensor.bathroom
      - sensor.bedroom
    above: 24

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.

Updated:

alias: Testing
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.king_thsensor_t
    attribute: Temperature
    above: 24
  - platform: numeric_state
    entity_id: sensor.nest_thermo_temperature
    above: 24
  - platform: numeric_state
    entity_id: sensor.queen_thsensor_t
    above: 24
  - platform: numeric_state
    entity_id: sensor.princess_thsensor_t
    above: 24
  - platform: numeric_state
    entity_id: sensor.professor_thsensor_t
    above: 24
condition: []
action:
  - service: notify.mobile_app_wald
    data:
      message: "[Sensor] detected high temperature of xx° C"
mode: single

Does your first sensor actually report temperature in a separate Temperature attribute?

whoah this is much better! Amended code:

alias: Testing
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.king_thsensor_t
      - sensor.nest_thermo_temperature
      - 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

yes, except for Nest, those are all Aqara Temperature and Humidity sensors

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.

I believe all 5 report into temperature attribute as they all also have Humidity attribute

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).

got → Error in describing trigger: Cannot read properties of undefined (reading ‘entity_id’)

and it won’t show either way as I have one of them showing over 24 degress yet “Run” doesn’t trigger action / no notification arrives

Stopped because an error was encountered at 9 August 2023 at 15:09:08 (runtime: 0.18 seconds)

Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘to_state’

Perhaps you have overlooked what I had advised earlier:

That’s to be expected if you use the Run command to test an automation containing references to the trigger object.

Testing your automation

sorry about that - how can I go about testing it?

I am not smart enough for this one…

I am sure I’ve not done it right but: