Displaying entity data in a notification?

Ok, this one seems like it should be ridiculously simple, but it’s got me stumped!

I’ve got a notification to my iphone if my house voltage goes above 253v. At the moment it’s a simple automation that just pings my phone. Easy.

BUT - I want to send the actualy number in the notification. Should be easy right?! I’ve got an entity called sensor.iammeter_voltage and it’s ‘state’ gives the number I need (eg: 244.53v).

So, I tried the following:


I’ve tried a few variations of this ‘state’ wording… All I get is 'UndefinedError: ‘state’ is undefined…

3

2

Worst thing is I know it’s going to be something so simple… But hey, if you don’t ask…!

Thanks,
Matt

{{ states('sensor.sensor.iammeter_voltage') }}

Should do the trick.

Here’s the code from one of my alerts which is similar, hope this helps …

ups_supply_low:
  name: "UPS Supply Low"
  title: "Warning - UPS supply voltage low at {{ states('sensor.time') }}"
  message: "Check if breaker has tripped (currently {{ states.sensor.ups_input_voltage.state }}V) "
  entity_id: binary_sensor.ups_supply_voltage_low
  state: 'on'
  repeat: 1440
  can_acknowledge: true
  skip_first: false
  notifiers:
    - info_group

One too many ‘sensor.’ but yup, {{ states('sensor.iammeter_voltage') }} worked perfectly. I was certain I’d tried that. I tried something with ‘states’ and it just listed all the different states of the entity… But thank you very much. I knew it would be an easy one! I can sleep easy tonight!
Thanks Hellis81.

Thanks Jonah, good to see. :slight_smile:

Developers tool --》 Template is your friend :grinning:

If I may hijack this thread (as it comes top when I search for solutions), I am similarly tearing my hair out.

I have a CPU temperature sensor that is set via HASS.Agent. I’ve written an automation that sends a notification when it’s over a threshold, but can’t figure out how to display the temperature in the notification. It’s probably incredibly simple but I can’t get it.

I try the following in Dev Tools

service: notify.juba
data:
  message: "{{    sensor.juba_hass_agent_cputemperature }} C"

It correctly sees the sensor, and shows me the text value of the temperature (see pic below). However, when I call the service I get the error “Failed to call service notify.juba. Error rendering data template: UndefinedError: ‘sensor’ is undefined”

I have tried all kinds of variations with .value, state_attr and so on and just get different variations of error.
Thanks in advance for any help.

Got it working after some more trial, error and reading up on JINJA2:

{{ states('sensor.juba_hass_agent_cputemperature') }}C