Homey Community Forum

MQTT flow parse json

I am using the mqtt client in homey to recieve an mqtt message containing a json object. Now I need a way to parse the json object into betterlogic variables? Anyone done it before?

{"battery.charge": "100", "battery.charge.low": "10", "battery.charge.warning": "50", "battery.date": "2001/09/25", "battery.mfr.date": "2015/02/28", "battery.runtime": "900", "battery.runtime.low": "120", "battery.type": "PbAc", "battery.voltage": "27.3", "battery.voltage.nominal": "24.0", "device.mfr": "American Power Conversion", "device.model": "Back-UPS RS 900G", "device.serial": "3B1509X29698 ", "device.type": "ups", "driver.name": "usbhid-ups", "driver.parameter.pollfreq": "30", "driver.parameter.pollinterval": "5", "driver.parameter.port": "auto", "driver.version": "DSM6-2-2-24922-broadwell-fmp-repack-24922-190507", "driver.version.data": "APC HID 0.95", "driver.version.internal": "0.38", "input.sensitivity": "medium", "input.transfer.high": "294", "input.transfer.low": "176", "input.voltage": "233.0", "input.voltage.nominal": "230", "ups.beeper.status": "enabled", "ups.delay.shutdown": "20", "ups.firmware": "879.L4 .I", "ups.firmware.aux": "L4 ", "ups.load": "28", "ups.mfr": "American Power Conversion", "ups.mfr.date": "2015/02/28", "ups.model": "Back-UPS RS 900G", "ups.productid": "0002", "ups.realpower.nominal": "540", "ups.serial": "3B1509X29698 ", "ups.status": "OL", "ups.test.result": "No test initiated", "ups.timer.reboot": "0", "ups.timer.shutdown": "-1", "ups.vendorid": "051d"}

I have not done it before… although I’ve worked with all the puzzle pieces.
I think it’s definitely doable.
Use MQTT client to receive the JSON in the “When” of a flow
Send the tag (=json data) to a Homeyscript in the “Then” of the flow
In homeyscript parse the json (you need to create this script first)
And update the Better logic variable inside the script: