Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't Parse Objects in Messeges #680

Open
Morphi08 opened this issue Jul 27, 2024 · 1 comment
Open

Can't Parse Objects in Messeges #680

Morphi08 opened this issue Jul 27, 2024 · 1 comment

Comments

@Morphi08
Copy link

Hi there,
I just new in Homebridge and want to control some outlets with this plugin,
Controlling, Power on and off will be right, but the parsing of power and voltage etc. would not be functional, maybe its my fail?

I use this Json:
"topics": { "getOnline": "cmnd/tasmota_E88366//Status", "getWatts": { "topic": "tele/tasmota_E88366/SENSOR", "apply": "return JSON.parse(message).ENERGY.Power;" }, "getVolts": { "topic": "tele/tasmota_E88366/SENSOR", "apply": "return JSON.parse(message).ENERGY.Voltage;" }, "getAmperes": { "topic": "tele/tasmota_E88366/SENSOR", "apply": "return JSON.parse(message).ENERGY.Current;" }, "getOn": "cmnd/tasmota_E88366/POWER", "setOn": "cmnd/tasmota_E88366/POWER"

the messages form the topics is this:
{"Time":"2024-07-27T10:51:55","ENERGY":{"TotalStartTime":"2023-05-18T00:00:00","Total":79.788,"Yesterday":0.036,"Today":0.008,"Period":0,"Power":1,"ApparentPower":3,"ReactivePower":3,"Factor":0.25,"Voltage":230,"Current":0.012}}

so I can't find any errors in my coding, so maybe someone else can open my eyes ;-)

best regards

@GithHobby
Copy link

GithHobby commented Dec 10, 2024

it should be a prob elm about nested JSON.
I'm not sure that you can use (as example)
return JSON.parse(message).ENERGY.Power;

Maybe you can try to change in:
return JSON.parse(message).[\"ENERGY\"].Power;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants