Condition / Trigger based on MQTT Payload

Greetings.

I have an existing automation, that works fine, but I want to add a condition based on an MQTT payload status.

I’ve read a number of similar posts, and appreciate MQTT payloads are not stored anywhere in HA, so checking the status on an MQTT payload is going to be a challenge.

So what am I trying to do… here’s the current automation:-

alias: Front Door Alert
description: Send alert to Telegram
trigger:
  - type: motion
    platform: device
    device_id: b49dcf843f2922c02695757c28954dbe
    entity_id: binary_sensor.frontdoorsensor_occupancy
    domain: binary_sensor
condition: []
action:
  - service: telegram_bot.send_message
    data:
      message: Front Door Activity
mode: single

The automation above is triggered from an Ikea Zigbee Tradfri sensor, and sends me a telegram message when movement is detected at the front door.

I want to insert a condition that messages are only sent when I am away from home. And I’d like the condition to be based upon my alarm system being armed i.e. when alarm is armed I am obviously away so send telegram messages when movement is detected.

Here’s the MQTT from my alarm system:-

alias: Honeywell MQTT
description: ""
trigger:
  - platform: mqtt
    topic: <the alarm topic is here>
    payload: Full Set
condition: []
action:
  - service: telegram_bot.send_message
    data:
      message: Alarm Activated
  - wait_for_trigger:
      - platform: mqtt
        topic: <the alarm topic is here>
        payload: Unset
  - service: telegram_bot.send_message
    data:
      message: Alarm Deactivated
mode: single

I recall there was an option to set a variable in esphome, but I not sure if such a variable can be set in HA? For example, if I could set a status based upon the MQTT messages from the alarm system, I could have the front door sensor automation check that status before it sends a telegram message.

Clear as mud, right.

Open to suggestions or things I could try.

Set up an MQTT sensor or trigger-based template sensor to store the payload.

Hi Drew,

Thanks for the help. So I created the MQTT sensor, and it turns out it keeps an accurate status… which is fantastic.

FX100 Status

I attempted to add the sensor status to the automation, but I got stuck at what to enter for Attribute or State?

I figured if I could enter ‘payload’ and then ‘unset’ that would be awesome, but it didn’t seem to work?

The payload of the message becomes the state of the sensor.

alias: Front Door Alert
description: Send alert to Telegram
trigger:
  - type: motion
    platform: device
    device_id: b49dcf843f2922c02695757c28954dbe
    entity_id: binary_sensor.frontdoorsensor_occupancy
    domain: binary_sensor
condition:
  - condition: state
    entity_id: sensor.fx100_status
    state:
      - Full Set
      - Whatever other states should be used if any...
action:
  - service: telegram_bot.send_message
    data:
      message: Front Door Activity
mode: single

Thanks again Drew… ended up going all out with below. Will arm the alarm and test, and also tonight to see if it works.

alias: Front Door Alert
description: Send alert to Telegram
trigger:
  - type: motion
    platform: device
    device_id: b49dcf843f2922c02695757c28954dbe
    entity_id: binary_sensor.frontdoorsensor_occupancy
    domain: binary_sensor
condition:
  - condition: or
    conditions:
      - condition: time
        after: "21:00:00"
        before: "06:00:00"
        weekday:
          - sat
          - fri
          - thu
          - wed
          - tue
          - mon
          - sun
      - condition: state
        entity_id: sensor.fx100_status
        state: Full Set
action:
  - service: telegram_bot.send_message
    data:
      message: Front Door Activity
mode: single