Automation based on part of MQTT payload

Hi,

I have a Sonoff RF Bridge and a couple of simple RF devices. Could somebody help a beginner with creating automations based on the “Data:xxx” part of the payload? Preferably in the visual editor.

I created the automation for the topic, I’m just failing to figure out how to filter based on the different payloads.

Many thanks

Post the automation you created (in YAML format).

If your automation is using an MQTT Trigger, then in all likelihood, you will need to use a template like this:

{{ trigger.payload_json.RfReceived.Data }}

Hi Taras,

I don’t really have an automation yet. I have a simple sonoff RF door sensor, it sends the following when opened:

MQT: tele/tasmota_01E1D2/RESULT = {“Time”:“2023-03-13T12:18:02”,“RfReceived”:{“Sync”:8000,“Low”:200,“High”:710,“Data”:“EAC701”,“RfKey”:“None”}}

I would like to use this as trigger for automations. “IF message containing “EAC701” received, THEN do x”

I hoped that it would be possible to use wildcards in the payload field like EAC701 but that doesn’t seem to work.

Many thanks

  trigger:
    - platform: mqtt
      topic: "tele/tasmota_01E1D2/RESULT"
      payload: "EAC701"
      value_template: "{{ value_json.RfReceived.Data }}"

Reference: MQTT Trigger

1 Like

Thanks it’s working!

It’s a pity that it can’t be done in the visual editor.

1 Like

Hi, sorry to bring up an old topic. I have a similar issue, I’ve tried the solution here but get no response.
MQTT String: 20;21;EV1527;ID=0daed6;SWITCH=09;CMD=ON;

The first two segments (20;21;) change with every transmission recieved.

I have a Button helper I want pushed when ever this device (I have multiple and want to be able to tell them apart) sends a pulse.

The “ID=0daed6” is unique to each so I’m trying to respond to that segment of the string response.

  • id: ‘1699695316161’
    alias: Motion sensor 1
    description: ‘’
    trigger:
    • platform: mqtt
      topic: /ESP00/msg
      payload: “ID=0daed6”
      value_template: “{{ value_json.RfReceived.Data }}”
      condition:
      action:
    • service: button.press
      data: {}
      target:
      entity_id: input_boolean.motion_detected
      mode: single

I’ve tried putting the topic in quotes, using different bits of the recieved payload and doing a full reboot after each change to no avail.

I’m open to any suggestions.
Thanks

Manged to split the string into segments using this example:

Which gives me subtopics that I can monitor for the specific device. Not everything reports properly but I get out what I need so I’m happy.

My current code:
alias: RFLINK32 String Split
description: ‘’
trigger:
platform: mqtt
topic: /ESP00/msg
action:

  • variables:
    data: ‘{{ trigger.payload[5:-1].split(’‘;’‘) }}’
    item:
    • counter1
    • DeviceType
    • DeviceID
    • Switch
    • State
    • Unknown
  • repeat:
    count: ‘{{ item | length }}’
    sequence:
    • service: mqtt.publish
      data:
      topic: /ESP00/msg/{{item[repeat.index-1]}}
      payload: ‘{{data[repeat.index-1]}}’