After browsing the help section and documentation for hours I was not able to resolve my problem.
I am trying to do an automation with mqtt. When the value exceeds a certain value the action should start.
Therefore I created a trigger " When an MQTT message has been received" and a template condition. At first I tried to do it like this:
talias: set_wb_16a
description: ""
trigger:
- platform: mqtt
topic: pv/HM1500/ch0/P_AC
condition:
- condition: template
value_template: "\"{{trigger.payload_json > 300}}\""
action:
- service: mqtt.publish
data:
qos: 0
retain: false
topic: wallbox/999999/command
payload: maxCurrent 16
mode: single
The trigger is working everytime when new data is presented but I am unable to test the condition because I get an error message:
Error occurred while testing condition
In 'template' condition: UndefinedError: 'trigger' is undefined
When I listen to that specific topic it gets data like this:
Message 14 received on pv/HM1500/ch0/P_AC at 12:41 PM:
523.6
QoS: 0 - Retain: false
So I thought maybe I have to pick “pv/HM1500/ch0/#” as a topic. Output from listening is the following:
Message 4 received on pv/HM1500/ch0/P_AC at 12:21 PM:
369
QoS: 0 - Retain: false
I tried to edit the yaml to the following but it still says the trigger is undefined:
alias: set_wb_16a
description: ""
trigger:
- platform: mqtt
topic: pv/HM1500/ch0/#
condition:
- condition: template
value_template: "\"{{trigger.payload_json.P_AC > 300}}\""
action:
- service: mqtt.publish
data:
qos: 0
retain: false
topic: wallbox/999999/command
payload: maxCurrent 16
mode: single
Am I completely wrong?
Kind regards
Matthias