Mqtt automation editor wont work with payload - please help

Hello,

i have a question about my mqtt automation.

when i leave out the payload in the automater the automation works
but if i put in the payload (and i really need to do this because i work with the sonoff/tasmoto wifi hub) then the action doesnt work

like you can see below hassio is recieving the messages when i go to developer tools - mqtt- listen to a topic

Message 0 received on tele/hub/RESULT at 2:14 PM:
{
“Time”: “2020-03-06T14:14:05”,
“RfReceived”: {
“Sync”: 7560,
“Low”: 270,
“High”: 730,
“Data”: “92D3B8”,
“RfKey”: “None”
}
}

below is my automation.yaml :

id: ‘1583497473605’
alias: motion gang voor
description: ‘’
trigger:

  • payload: “92D3B8”
    platform: mqtt
    topic: tele/hub/RESULT
    condition: []
    action:
  • device_id: 929eecf9a0df45f991bb3bd57bda9362
    domain: light
    entity_id: light.gang_voor
    type: turn_on

so without the payload filled in it works but thats no option.
if i fill in the payload with or without the “” it doesnt work.

Any one know an eassy way to fix this… ?

Please read this topic and format your code correctly otherwise we are not able to help you.

Also your trigger can’t work, because the payload is the whole message but in your trigger you just ask for part of the payload. It would be the best to create an mqtt sensor that extracts the “Data” from your MQTT payload and then use the sensor as the trigger.

Hai Burningstone,

thank you for your fast reaction.

on every forum ive read the payload was only the small part, so what should it be then?

and your option :slight_smile:

create an mqtt sensor that extracts the “Data” from your MQTT payload and then use the sensor as the trigger

would definitly be the best one but im as green as grass if it comes to hassio and yaml etcc so i really have no clue on how to do that.

The payload is the whole message. It’s just that the examples you read probably had an MQTT topic where only a single value is posted and not a JSON message as in your example.

Check the docs for the MQTT sensor here.

In your case it should look something like this:

sensor:
  - platform: mqtt
    name: "MQTT RF sensor"
    state_topic: "tele/hub/RESULT"
    value_template: "{{ value_json.Data }}"

This will create a sensor that has the “Data” value from the MQTT payload as the state.

You can then change the trigger of your automation to this:

trigger:
  platform: state
  entity_id: sensor.mqtt_rf_sensor
  to: "92D3B8"

As an alternative, read this topic. Very well explained how to work with the Sonoff RF Bridge.

thanks for your reply,

so i created the sensor in configuration.yaml like below

sensor:

  • platform: mqtt
    name: “MQTT RF sensor”
    state_topic: “tele/hub/RESULT”
    value_template: “{{ value_json.Data }}”

then in the automation editor i created a new automation

on trigger type i selected : state
then on entity i selected the newly created sensor.mqtt_rf_sensor
i left “From” and “For” empty an on “To” is i put in 92D3B8

Nothing happend when i pussed the button, then i changed it to “92D3B8” and again nothing

i selected at action my light and to turn it on.

any ideas?

Please format the code you post so that others can easily read it and be certain it doesn’t contain syntax errors. You may have noticed that everyone is responding to you with formatted code.

There are two easy ways to format code:

Select the code and click the forum editor’s </> icon.

OR

  • Enter three consecutive backquotes ``` on a separate line before the code.
  • Enter three more consecutive backquotes on a separate line after the code.
1 Like

Do you get any errors in the logs? What does the sensor sensor.mqtt_rf_sensor show when you press the button?

Hai,

When i look at the state in developer tools - state it keeps empty

only the entity and atributes are filled in.

This will never work

sensor:
  - platform: mqtt
    name: "MQTT RF sensor"
    state_topic: "tele/hub/RESULT"
    value_template: "{{ value_json.Data }}"

At least it should be

sensor:
  - platform: mqtt
    name: "MQTT RF sensor"
    state_topic: "tele/hub/RESULT"
    value_template: "{{  value_json.RfReceived.Data }}"

Please read the topic I mentioned above.

1 Like

You are absolutly right!

i tryed reading it but because im a real noob i really couldnt figure it out or understand what it was saying.

but i keep trying putting together all of you guys advice and some stuff i read (trial and error)

Got it working now partially.

it looks like hassio isnt recieving the data from my hub all of the time, if im lucky and have pressed the button 10 times or more then maybe the light goes off or not.

looks like there is an extreme delay

im running hassio on a raspberry pi is that maybe the problem? to slow?

Totally missed that there is a dict inside the json message. I’ll just blame the formatting :stuck_out_tongue: :rofl:

Can I squeez that only into one automation w/o creating a sensor?

The reason why I’m asking is only need one rf button. The sensor value would never be changed and the automation is looking for a change.

Idea could be to add the attribute timestemp of the hub. So there would be a change. But dont know how to integrate into the sensor. And yes, I reat the mqtt sensor artical.

Message on my hub is:

14:00:02.988 MQT: tele/tasmota_bridge/RESULT = {"Time":"2022-09-14T14:00:02","RfReceived":{"Sync":10790,"Low":310,"High":1010,"Data":"BB8DE1","RfKey":"None"}}