Please, pretty please, add something to the “Payload” option, in order to customize it somehow, it is too not usable in this moment.
For example, I want to make a trigger which will trigger only if the payload contains a specific string, I don’t want to trigger only by the entire payload received. It could work with a part of it, detecing some strings or even using a more complex template.
The workaround which all uses, by adding a condition to the automation, it is not the perfect fitt, because the “trances” will not be usable anymore. The trigger will fire everytime, no matter that condition, the condition will only block the automation to continue, but the trigger already has been fired…
For some situations, like mine, not even a MQTT sensor will help, thats why I think that customizing the payload from the trigger, will be the perfect solution.
For this payload: {"ZbReceived":{"Bathroom_Ambient":{"Device":"0x59C2","Name":"Bathroom_Ambient","EF00/0202":5,"Endpoint":1,"LinkQuality":45}}}
I done it and it is working, with this trigger:
Edit: But now… I still don’t get it to work for a similar situation… Same payload {"ZbReceived":{"Bathroom_Ambient":{"Device":"0x59C2","Name":"Bathroom_Ambient","EF00/0202":5,"Endpoint":1,"LinkQuality":45}}}
How can I make the autmation trigger when “EF00/0202” it is detected into the payload? I cannot add value_json as value, because I don’t want to use the value. I want to trigger when the “variable” EF00/0202 it is detected into the payload, not the value of this one
Ideally, value_template should report a value. The way you designed your template, it only reports a value when the key exists, otherwise it reports nothing.
value_template: |
{% if value_json['ZbReceived']['Bathroom_Ambient']['EF00/0216'] is defined %}
yes
{% endif %}
Other than that, there’s no functional difference; both templates report ‘yes’ only when the desired key exists in the payload.
value_template: >
{{ iif(value_json['ZbReceived']['Bathroom_Ambient']['EF00/0216'] is defined, 'yes', 'no') }}
You are right. And your way is cleaner too, but I needed something more complex and I didn’t know how to do it with iif. Look this is my final trigger:
- platform: mqtt
topic: tele/ZigBee_Bridge/C877/SENSOR
payload: trigger_template
value_template: |
{% set value = value_json['ZbReceived']['Living_Ambient']['EF00/0212']
| multiply(0.1) | float | round(1) - 0.50 %}
{% if ( (value is defined) and (is_number(value)) and
( ((states('variable.living_ambient_temperature') | float -
value ) | abs | round(1) >= 1) or (as_timestamp(now()) -
as_timestamp(states.variable.living_ambient_temperature.last_changed) |
int > 1800)) ) %}trigger_template{% endif %}
id: Temperature
alias: Temperature
This automation will trigger only if the value is defined, it is a number and the value will be bigger than the last one with at least value of 1 or the time will pass more than 30 minutes. I made this trigger because my “stupid” sensor it is sending mqtt data 2-3 times per second. Imagine how full is my bridge, with data But it is ok, the bridge can handle it, I just wanted to not have the HA database too big and the automation to not run every second.
The first line of your template uses the value of the ‘EF00/0212’ key before checking if the key is defined.
value_template: |
{% set value = value_json['ZbReceived']['Living_Ambient']['EF00/0212']
| multiply(0.1) | float | round(1) - 0.50 %}
{% if ( (value is defined) and ...
You should confirm the key is defined before attempting to use its value.
review severity will either be “alert”, “detection” or both using a select selector (in blueprint).
the json payload will be one of those, or something else, but always one value