Add a MQTT return to a var

I am struggling with the following:
I am able to receive messages from a MQTT Topic. The message is for example: {“state”:1}
In no way I can use this result in a logic part to make a decision.

I think that I have to create a script to pars the message. Is there a way and how to get as result after parsing: state:1?

I don’t know anything about MQTT, buth the result looks like a result I get from the Sonos api which i get through my NAS. The following message i receive

This way I parse it in a variable

I try to get this example working but for now without success.
What type of var did you make to get the parts data into RadioStation or RadioTrack?

MQTT is different from HTTP, those cards aren’t usable. I think the only way to parse data from MQTT message is using Homeyscript.

I also thought so… question is… what is a simple way to get the data part form {“state”:0} or {“state”:1} to state 0 or state 1. Or maybe tetter to pars it to: Zone Off or Zone On.

You may be able to use the card “Logica — Bevat” and check if the message contain either "state":1 or "state":0. Bit of a hack but might work and easier than using Homeyscript.

This was also my first thought but this will not work. I suppose due to the " " , logic can’t read it.

You could also try matching against :1 and :0.

I don’t understand why @robertklep solution won’t work. Have you tried this?

If this does not work, I would pass the received “state” to a variable. This way you can exactly extract the string to compare with. (and try the first flow again with the new string)

I have done as you requested. Even with a var included this solution does not work.
I included also a notification so I was sure that the Topic was received.

This is the received Topic:

“is precies” won’t work because the value is {"state":1} (brackets around it).

Can you show the flow you’re using?

Sure, no problem.

Flow:

The var part is like this:

I don’t understand why you’re using a variable (ZoneAan). Try matching against normal text content, and make sure that you’re using the right quote characters (not “state” but "state", i.e. regular quotes instead of “smart” quotes).

Using a var wat a proposal of Satoer. I have changed is back as you can see in the flow below.

I have checked the quotes but it doesn’t; work. For me it is a big question mark why this simple test flow does not work.

You can send the received message to a log to see how the message exactly looks.

The “Logica bevat” card apparently is broken, it can’t deal with quotes. So instead of matching against "state":1, match against :1. I confirmed that this works for me.

Robert,

I have tried your proposal and it worked. Strange thing is when I got the topic message for switching it off within the 20 second, this flow wil also be activated.
When I looked to the other status (off) the topic will be like this: {“state”:0,“duration”:60}
This is a combined topic State and Time.
Maybe it will at the end easer using a different solution, like scripting. No clue yet how to make a script but that is also a challenging part.
What I do not completely understand is, MQTT is not new. Why is there still so little information how to deal with topic information in Homey?"

Topic information in MQTT can be anything: JSON (like in this case), plain strings, XML, whatever. So I understand that the MQTT Client app doesn’t try to parse payloads and passes them as-is.

Ideally, someone would make a specific parser app to deal with different kinds of payloads, like a JSON parser app. But such an app doesn’t exist, so for now we have to use workarounds.

Thanks for the support.
I wil check if other MQTT client apps behave the same as the one which is currently running.

It is clear for me that there is no solution yet for Homey to simply deal with MQTT topics and have to use a workaround.