wildr
January 24, 2024, 8:03pm
1
How do I access the value of the incoming mqtt message to trigger my automation?
- trigger:
- platform: mqtt
topic: "topic/temperature"
condition: "{{ value != states('sensor.entity')|float() }}"
action:
- service: mqtt.publish
data:
topic: topic/Refresh
payload: "1"
mode: restart
tom_l
January 24, 2024, 11:22pm
2
https://www.home-assistant.io/docs/automation/trigger/#mqtt-trigger
Because the payload
option only supports limited templates, which do not include functions like states()
, you’ll probably have to do something like this:
- trigger:
- platform: mqtt
topic: "topic/temperature"
value_template: "{{ value != states('sensor.entity')|float() }}"
payload: 'true'
action:
- service: mqtt.publish
data:
topic: topic/Refresh
payload: "1"
mode: restart
The value_template
evaluates the received message first and then if the payload
option matches the result of that template the trigger occurs.