Hey, I’m trying to configure automation to basically switch my light depending on the mqtt payload. I would lik eto do something like this:
automation:
trigger:
platform: mqtt
topic: ggamble22/feeds/bedroom-light
action:
service_template: >
{% if mqtt.payload | string() == ‘ON’ %} “I get an error here for mqtt is undefined”
light.turn_on
{% else %}
light.turn_off
{% endif %}
entity_id: light.Bedroom
The issue is that I’m not sure what is the variable name to access the payload properly. I know I could make two separate automation services and that works fine based off the example in the docs but that seems unnecessarily cumbersome. Any help would be appreciated. Thanks.
Try this: {% if trigger.payload | string == 'ON' %}
Beware that HASS states are case sensitive, so if your payload is actually ‘on’ or ‘On’, this condition will not be met. Also, I’m not sure that | string is necessary, but on the other hand it shouldn’t hurt.
@fanaticDavid that worked fine. Thanks. The case sensitivity is the reason I am keeping everything capitalized. Well, that and it was the default when getting started with adafruit’s mqtt server.