Hi everyone,
I’m working on a blueprint that triggers when a specific MQTT topic is received. Here are the relevant parts of my configuration:
input:
awtrix_device_topic:
name: "MQTT Topic"
selector:
entity:
integration: mqtt
domain: sensor
app_publish_on_boot:
name: "Start app at device boot"
default: false
selector:
Boolean:
When I create an automation from this blueprint, I select the entity sensor.awtrix_590710_device_topic
, and its state is woonkamer_awtrix
.
The trigger looks like this:
trigger:
- platform: mqtt
topic: "+/+/avty_t"
payload: "online"
enabled: !input app_publish_on_boot
This trigger works fine, but if I have multiple devices sending out this topic, it can trigger undesirably, since it doesn’t filter based on the device topic (e.g., woonkamer_awtrix
).
To fix this, I added the following condition:
condition:
- condition: template
value_template: >
{% set base = states('input.awtrix_device_topic') %}
{{ trigger.topic | regex_match('^' ~ base ~ '/[^/]+/avty_t$') }}
enabled: !input app_publish_on_boot
This condition is supposed to match the device topic with the trigger topic.
When I change the condition to directly reference the sensor state, it works fine.
This also means that at least trigger.topic
is properly read.
condition:
- condition: template
value_template: >
{% set base = states('sensor.awtrix_590710_device_topic') %}
{{ trigger.topic | regex_match('^' ~ base ~ '/[^/]+/avty_t$') }}
enabled: !input app_publish_on_boot
This leads me to believe that the blueprint input entity state isn’t being properly retrieved.
Has anyone encountered a similar issue and/or knows what I might be doing wrong?