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
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.
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.
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).
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.
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.