arachnetech / homebridge-mqttthing

A plugin for Homebridge allowing the integration of many different accessory types using MQTT.
Apache License 2.0
462 stars 104 forks source link

help return JSON.parse(message) with dot (OBIS Codes) #616

Closed JustAnotherIssue closed 1 year ago

JustAnotherIssue commented 1 year ago

Hey there, My smart power meter exposes OBIS Codes a MQTT middleware. But I got stuck in terms of parsing them in the mqttthing homebridge plugin. Please help me, thanks !!

The issue is about the dots e.g. 1.7.0 in the attributes object.

topic: SHRDZM/serial/sensor response: { "timestamp":"2023-04-15T18:53:55", "32.7.0":"229.90", "52.7.0":"227.60", "72.7.0":"232.60", "31.7.0":"0.68", "51.7.0":"1.31", "71.7.0":"2.12", "1.7.0":"840", this is the attribute/value I need**** "2.7.0":"0", "1.8.0":"749864", "2.8.0":"0", "3.8.0":"309", "4.8.0":"226048", "16.7.0":"840", "uptime":"0000:01:54:05" }

with trying "apply": "return JSON.parse(message).'1.7.0';" I receive an error, "Exception while creating services: SyntaxError: Unexpected string" also with every other tried characters.

Could you help with a clue?

THX!!

arachnetech commented 1 year ago

JSON.parse(message)['1.7.0'] might do it.

JustAnotherIssue commented 1 year ago

indeed it did. Thank you :-)

[16.4.2023, 07:58:08] [Smart Meter Watt] apply() function decoded message to [353]