How do I post sensor values on MQTT whenever?

Hi!

I’m trying to send an MQTT message with a sensor value as payload based on a timer trigger. In Post sensor values to MQTT - #9 by 123 there is a way to send the sensor value if the trigger in the automation is the sensor.

Is there a way to define the payload with a sensor value independent of how the automation was triggered?

I have tried to define the payload like this with no success:

{"basic" : {
  "mediumPriceValue" : "{{sensor.ecowatch_low}}"
}}

I get Error rendering data template: UndefinedError: 'sensor' is undefined.

Can I do something else?

{"basic" : {
  "mediumPriceValue" : "{{states('sensor.ecowatch_low')}}"
}}

Thanks a lot! Now it works.

1 Like