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

2 Likes

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

I know this is a very old topic, but nevertheless i’ll ask here anyway.

The above solution works, but isn’t translated to my native language.

{{ states(“sensor.oprit_reason_for_no_current”) }} shows in the result “not_requesting_current”. So the notify also sends this. Makes perfect sense.

If I however look at the sensor in the GUI of Home Assistant it shows “Geen stroomaanvraag” which is a much ‘cleaner’ message for me in Dutch.

Is there any way to send the default translated information instead of the actual sensor value?