Notify - How to display sensor value in message

Dear all

I am not yet very familiar with HA but I already made some great experience with my configuration.
My configuration:

  • Easy ESP with 2 temperature sensors (send data via MQTT to HA)
  • HA based on Raspberry 4 and MQTT broker
  • HA App on a Android based smartphone

I would like to send a message to the smartphone as soon as the temperature is above a defined value. I did automation task which is working perfect as long as the message is generic. But I am not able to send the value of the sensor. Error: Error rendering data template: UndefinedError: 'sensonr ist undefined’

The entry in the automation.yaml:

id: '1641497734070'
   alias: Temperature Warning
   description: ''
   trigger:
   - platform: numeric_state
     entity_id: sensor.temperatur_gefrierschrank
     above: '25'
     for:
       hours: 0
       minutes: 0
       seconds: 30
     attribute: unit_of_measurement
   condition: []
   action:
   - service: notify.mobile_app_huawei_p20
     data:
       title: Temperature Warning
       message: 'Temperature is: {{ sensor.temperatur_gefrierschrank }}'
   mode: single

Can anybody give me some advice/hints? Thank you for your support!

Best regards
Christoph

1 Like

To get the state value of an entity, use the states() function.

       message: 'Temperature is: {{ states("sensor.temperatur_gefrierschrank") }}'

The states() function is described here: Templating - States

NOTE

You need to remove this line from the automation’s trigger:

     attribute: unit_of_measurement

By including that line, you made the State Trigger monitor the sensor’s unit_of_measurement attribute for changes to its value. That’s not where the sensor’s temperature value is stored.

9 Likes

Thank you very much Taras, it works perfectly! It’s great to have a competent Home Assistant community and to get answers quickly!

2 Likes

ty! you saved my day