atlaware
(Atlaware)
November 23, 2018, 10:41am
1
Hi, it’s possible to use a “value_template” in automation with mqtt trigger platform?
I have a topic with json values and I cannot use payload directly.
This doesn’t work:
trigger:
platform: mqtt
topic: tele/sonoffbridge/RESULT
payload: ‘{ “RfReceived.RfKey”: “3” }’
Thank you
1 Like
VDRainer
(🍻)
November 23, 2018, 10:52am
2
I think you have to use a template condition for this.
Leave the payload of the mqtt trigger to trigger on every state change.
Use the condition to test for the key in trigger.to_state.state
.
atlaware
(Atlaware)
November 26, 2018, 4:51pm
4
Now I have completly understand you suggestion, thank you!
- id: pulsante_marty
alias: Pulsante Marty ramen
trigger:
- platform: mqtt
topic: "tele/sonoffbridge/RESULT"
condition:
condition: template
value_template: "{{ trigger.payload_json['RfReceived']['RfKey'] == 3 }}"
action:
- service: switch.toggle
data_template: { "entity_id": "switch.marty_ramen" }
3 Likes
mtabbut
(Matt)
January 15, 2019, 6:22pm
5
I used
value_template: ‘{{ trigger.payload_json.RfReceived.Data == “STRING” }}’
1 Like
markaves
(Mark Neil C. Aves)
May 29, 2020, 4:35pm
6
Hi Everyone,
I need your help in parsing an MQTT message. I have this sensor that occationally sends a null value and I need to turn on a switch if that happens.
{“Time”:“2020-05-29T17:01:32”,“AM2301”:{“Temperature”:null,“Humidity”:null,“DewPoint”:null},“TempUnit”:“C”}
I have tried this but it doesn’t work. Can you let me know what is wrong?
id: ‘1590768729127’
alias: sample
description: ‘’
trigger:
platform: mqtt
topic: tele/tasmota-02/SENSOR
condition:
condition: template
value_template: ‘{{ trigger.payload_json.AM2301[0].Temperature == null }}’
action:
device_id: cc6eb9c3955e41d1a7d2723c680b6562
domain: switch
entity_id: switch.85605775840d8e9da84c
type: turn_on
Thanks!
francisp
(Francis)
May 30, 2020, 6:00am
7
Please format your code correct
Click on the </>, and then put your code between the two times ```
In developer tools -> template
{% set my_test_json = {“Time”:“2020-05-29T17:01:32”,“AM2301”:{“Temperature”:null,“Humidity”:null,“DewPoint”:null},“TempUnit”:“C”} %}
The temperature is {{ my_test_json.AM2301.Temperature == null}}
markaves
(Mark Neil C. Aves)
May 31, 2020, 12:22am
8
Thanks @francisp . Works perfectly in the template editor. I’ll try this out.
markaves
(Mark Neil C. Aves)
June 1, 2020, 2:00pm
9
@francisp , I tried implementing this as a trigger to turn off a switch but for some reason, it doesnt work. Is there something missing in the action?
Trigger Code:
- id: '1590768729127'
alias: sample
description: ''
trigger:
- platform: mqtt
topic: tele/tasmota-02/SENSOR
condition:
- condition: template
value_template: '{{ trigger.payload_json.AM2301.Temperature == null }}'
action:
- device_id: cc6eb9c3955e41d1a7d2723c680b6562
domain: switch
entity_id: switch.85605775840d8e9da84c
type: turn_off
MQTT Transition to null: