Compare trigger topic with input entity state as condition in blueprint

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?

Well, this is a bit embarrassing :sweat_smile:

After hours of searching and finally gathering the courage to post about it, I think I’ve found the solution after just a few more minutes of tinkering.

I changed the code to this, and it seems to be working fine now.

variables:
  device_topic: !input awtrix_device_topic

condition:
  - condition: template
    value_template: >
      {% set base = states(device_topic) %}
      {{ trigger.topic | regex_match('^' ~ base ~ '/[^/]+/avty_t$') }}
    enabled: !input app_publish_on_boot

Hello MrNick4B,

That isn’t a thing…
You can still pull the value of the input, but this way.