Mqtt.py log warning "No matching payload found for entity"

The reason why it fails is because the value you’ve supplied for payload is incorrect. The error message says it all:

TypeError: payload must be a string, bytearray, int, float or None.

Here it is as a string:

payload: "{'RfReceived':{'Data':'33150E'}}"

If you want to publish payloads for testing purposes, just use:

Developer tools > MQTT > Publish a packet

I get the impression you don’t understand the difference between:

value

and

value_json
  • The first makes no assumption about the received data’s format and accepts it “as-is”.
  • The second assumes the received data’s format is JSON.

If the received payload is simply rotate_left then that’s not JSON and so you shouldn’t be creating templates using value_json.

Yes, sorry, I used those 2 automations because they were already there for other purposes, I forgot the MQTT publish section.

I tried.
The following sensor:

- platform: mqtt
    #friendly_name: Porta Giardino 
    name: "Contatto_Open_Close_1"
    # payload_on: "33150A"
    # payload_off: "33150E"
    device_class: door
    state_topic: "tele/Sonoff_RF_Bridge/RESULT"
    # value_template: "{{ value_json.RfReceived.Data }}"
    value_template: >-
      {% if value_json.RfReceived.Data == '33150A' %}
        {{'ON'}}
      {% elif value_json.RfReceived.Data == '33150E' %}
        {{'OFF'}}
      {% else %}
        {{states('binary_sensor.contatto_open_close_1') | upper}}
      {% endif %}

does not change state after publishing “{‘RfReceived’:{‘Data’:‘33150E’}}” or “{‘RfReceived’:{‘Data’:‘33150A’}}”

You are completely right if you think that I’m missing many concepts.
I stopped programming about 25 years ago (C++) and I just started to read and write some code last april after buying a RPI3B+ and installin Hassio, so I’m missin maaaaaany things.

But, and forgive me if I don’t understand, why the cube was working before if the old instruction was

value_template: "{{ value_json.RfReceived.Data }}"

?
Because the payload_on was clearly expressed?

payload_on: "rotate_left"

The sensor configuration you just posted appears to be correct. If you cannot make the sensor change state then it’s due to an error in the testing procedure.

I wish I had more time to explain the fundamentals to you but, unfortunately, I do not. I suggest you review the documentation, starting here:

Good luck.

Sorry, and thanks for the help you gave me until now.
Making and error in copy-paste “{‘RfReceived’:{‘Data’:‘33150A’}}” in MQTT section and clicking “publish” is quite hard, but probably I did it anyway.

If you’re using that utility to publish the payload, the payload’s format is like I first suggested to you:

{"RfReceived":{"Data":"33150A"}}

or even this:

{'RfReceived':{'Data':'33150A'}}

You’ll notice they do not have leading and trailing double-quotes (") because that version was exclusively for use with the payload option of the automation you had created.

Thanks for the additional help.
No luck anyway.

But the sensor stays off anyway.
I think I will stop for the moment.

Ok, after going home, rechecking everything, trying to understand how json works and spending the evening on this… I fixed many little mistakes and now sensors are working.

I’m still having “No matching payload found for entity” warnings and “Error parsing value: ‘value_json’ is undefined” errors, but I will look into it.

Thank you for stimulating me and for pointing me in the right direction.

Mmm… I try to report here the error.
For every sensor I get:

No matching payload found for entity: Pir_Digoo_2 with state topic: tele/Sonoff_RF_Bridge/RESULT. Payload: 33150E, with value template Template("{% if value_json.RfReceived.Data == '1CC3A6' %} {{'ON'}} {% else %} {{states('binary_sensor.pir_digoo_2') | upper}} {% endif %}")
8:05 components/mqtt/binary_sensor.py (WARNING)
Error parsing value: 'value_json' is undefined (value: 33150E, template: {% if value_json.RfReceived.Data == '1CC3A6' %} {{'ON'}} {% else %} {{states('binary_sensor.pir_digoo_2') | upper}} {% endif %})
8:05 helpers/template.py (ERROR)

This happens both for sensor with only open state and sensors with open & close state.
If the payload received matches the one specified, the sensor works.
But if it doesn’t match, it doesn’t use the current sensor state, and the warning “no matching payload found” pops up again

- platform: mqtt
    name: "Pir_Digoo_2"
    off_delay: 5
    device_class: motion
    state_topic: "tele/Sonoff_RF_Bridge/RESULT"
    value_template: >-
      {% if value_json.RfReceived.Data == '1CC3A6' %}
        {{'ON'}}
      {% else %}
        {{states('binary_sensor.pir_digoo_2') | upper}}
      {% endif %}

But I don’t know why, because if I put {{states(‘binary_sensor.pir_digoo_2’) | upper}} in the template checker, it gives correctly OFF.

Another day, same problem. The received payload is not in JSON format. The error message states that very clearly:

No matching payload found for entity: … Payload: 33150E
Error parsing value: ‘value_json’ is undefined (value: 33150E,

Probably I will say another wrong thing, but the payload look a nested JSON to me…

{
    "Time": "2020-02-20T15:56:23",
    "RfReceived": {
        "Sync": 14010,
        "Low": 480,
        "High": 1380,
        "Data": "33150E",
        "RfKey": "None"
    }
}

What you posted looks correct to me as well but whatever Home Assistant is receiving is not understood to be correct:

Error parsing value: ‘value_json’ is undefined

By the way, is the incorrect spacing shown in your example just a mistake when you posted it here or is that the way it is in your configuration file?

- platform: mqtt
    name: "Pir_Digoo_2"
    off_delay: 5

I assume it’s just a copy-paste error.

That’s exactly what Home Assistant is receiving:

And the wrong spacing was just a copy-paste mistake:

Which fails to explain its error message:

Error parsing value: ‘value_json’ is undefined

Yes, and believe me if I say that, even if I know that my knowledge is quite poor, I try to understand before asking.
If there’s something else that I can try or check…

No idea. Here’s the situation:

  • You’ve shown me a valid JSON payload.
  • You’ve shown me a valid binary_sensor configuration.
  • You’ve shown me an error message indicating value_json is undefined.

That’s 1 + 1 = 0. It makes no sense so the only logical conclusion is that either the payload, configuration, or the testing procedure is incorrect.


FWIW, I just finished helping someone else facing the same situation and the solution I offered, which is the same one used here, worked on the first try. I realize that’s cold comfort to you but the point is that, in your situation, there may be something happening that has not been revealed yet; there’s a missing clue somewhere.

Yes, and I think that I just found it.

I came back home, hacs had an update, so I installed it and rebooted.
After that, I checked logs, clean.
I activated some sensors, clean.
I activated the sensor that on close gives 33150E payload. Clean, no errors or warnings in logs.

At 20:13 my girlfriend opened the garage door… each sensor showed error about payload 33150E again.
So I switched on the PC and using notepad++ I did a search in all yaml files and… I found an automation that was publishing that payload on garage door opening, NOT in JSON format (but that was working before applying you fix because of the payload_on value).
Yes, I know, I left trash around after some test… :frowning:

So this should have been the last one, I didn’t try yet, but I’m quite sure that now it will be ok.

Thanks for your patience.

Like I said in my previous post:

… in your situation, there may be something happening that has not been revealed yet; there’s a missing clue somewhere

Now it’s starting to make sense; you found the missing "-2" in the equation. :slight_smile:

1 + 1 - 2 = 0

I can confirm that all the warnings went away. :partying_face: