I’ve been scratching my head over this all day! I’m trying to integrate a few RF switches via OpenMQTTGateway to control some lights. The simplest way I can think of for this is to create an automation with a message on my OMG topic as the trigger, and a template specifying which light to toggle depending on which switch I press.
Here is a sample of the output from OMG. It’s just standard JSON: {"value":12540546,"protocol":1,"length":24,"delay":287}
The unique identifier is the “value” string.
I created a sample automation with one switch below, this works fine
trigger:
- platform: mqtt
topic: "/home/OpenMQTTGateway/433toMQTT"
condition:
- condition: template
value_template: "{{ trigger.payload_json['value'] == 12540546 }}"
action:
- service: light.toggle
- entity_id: light.lounge_tv
What I want to do however is add in multiple of these, but I cannot for the life of me find a template that will work at all. This is the current form:
trigger:
- platform: mqtt
topic: "/home/OpenMQTTGateway/433toMQTT"
action:
- service: light.toggle
data_template:
entity_id: >
{% if is_state_attr('trigger.payload_json', 'value', '11073208') %}
light.master_bedroom
{% elif is_state_attr('trigger.payload_json', 'value', '12540548') %}
light.lounge_tv
{% elif is_state_attr('trigger.payload_json', 'value', '3735524') %}
light.hallway_light
{% endif %}
This does absolutely nothing. Neither do any of the following conditional templates I’ve tried:
{% if is_state('trigger.payload_json['value'], 'xxxxxxxx') %}
{% if is_state('trigger.payload_json.value', 'xxxxxxxx') %}
{% if 'trigger.payload_json['value'] == 'xxxxxxxx' %}
{% if 'trigger.payload_json.value' == 'xxxxxxxx' %}
Although the MQTT packet is received fine, it can’t seem to parse the JSON correctly. Removing quote marks and replacing single quote marks with double quotes hasn’t made a difference. I can’t find anything online that’s worked, can anyone on here see where I’m going wrong?