I am receiving this json from a Shelly H&T Plus
{
"src": "shellyplusht-e465b85f5e54",
"dst": "shelly/events",
"method": "NotifyFullStatus",
"params": {
"ts": 1703698870.74,
"ble": {},
"cloud": {
"connected": false
},
"devicepower:0": {
"id": 0,
"battery": {
"V": 5.21,
"percent": 60
},
"external": {
"present": true
}
},
"ht_ui": {},
"humidity:0": {
"id": 0,
"rh": 57.6
},
"mqtt": {
"connected": true
},
"sys": {
"mac": "E465B85F5E54",
"restart_required": false,
"time": "18:41",
"unixtime": 1703698870,
"uptime": 2,
"ram_size": 246304,
"ram_free": 153748,
"fs_size": 458752,
"fs_free": 172032,
"cfg_rev": 24,
"kvs_rev": 0,
"webhook_rev": 0,
"available_updates": {},
"wakeup_reason": {
"boot": "deepsleep_wake",
"cause": "status_update"
},
"wakeup_period": 600,
"reset_reason": 8
},
"temperature:0": {
"id": 0,
"tC": 22.7,
"tF": 72.8
},
"wifi": {
"sta_ip": "192.168.178.75",
"status": "got ip",
"ssid": "FRITZ!Box 7530 KI",
"rssi": -49
},
"ws": {
"connected": false
}
}
}
I am trying to use a change node with JSONata to preparare data for a chart node [dashboard-2 palette]
Ignore for a moment that the following code it is not retrieving a value for 'y', but an object. This question is about a JSONata syntax problem, i suppose. I only want to understand how to access keys in JSONata
I am using change node to prepare this payload
[
{
"y" : msg.payload.params["devicepower:0"],
"series" : "Volts"
},
{
"y" : msg.payload.params["devicepower:0"]["battery"],
"series" : "Percentuale"
}
]
When I debug the output msg
I see that both the 'y' are msg.payload.params
I am not able i think to access "devicepower:0"
in JSONata. what am I doing wrong?
The dump of final msg, actually is
[
{
"y": {
"ts": 1.95,
"ble": {},
"cloud": {
"connected": false
},
"devicepower:0": {
"id": 0,
"battery": {
"V": 5.22,
"percent": 60
},
"external": {
"present": true
}
},
"ht_ui": {},
"humidity:0": {
"id": 0,
"rh": 57.6
},
"mqtt": {
"connected": true
},
"sys": {
"mac": "E465B85F5E54",
"restart_required": false,
"time": null,
"unixtime": null,
"uptime": 1,
"ram_size": 246384,
"ram_free": 155716,
"fs_size": 458752,
"fs_free": 172032,
"cfg_rev": 24,
"kvs_rev": 0,
"webhook_rev": 0,
"available_updates": {},
"wakeup_reason": {
"boot": "deepsleep_wake",
"cause": "status_update"
},
"wakeup_period": 600,
"reset_reason": 8
},
"temperature:0": {
"id": 0,
"tC": 22.6,
"tF": 72.6
},
"wifi": {
"sta_ip": "192.168.178.75",
"status": "got ip",
"ssid": "FRITZ!Box 7530 KI",
"rssi": -49
},
"ws": {
"connected": false
}
},
"series": "Volts"
},
{
"y": {
"ts": 1.95,
"ble": {},
"cloud": {
"connected": false
},
"devicepower:0": {
"id": 0,
"battery": {
"V": 5.22,
"percent": 60
},
"external": {
"present": true
}
},
"ht_ui": {},
"humidity:0": {
"id": 0,
"rh": 57.6
},
"mqtt": {
"connected": true
},
"sys": {
"mac": "E465B85F5E54",
"restart_required": false,
"time": null,
"unixtime": null,
"uptime": 1,
"ram_size": 246384,
"ram_free": 155716,
"fs_size": 458752,
"fs_free": 172032,
"cfg_rev": 24,
"kvs_rev": 0,
"webhook_rev": 0,
"available_updates": {},
"wakeup_reason": {
"boot": "deepsleep_wake",
"cause": "status_update"
},
"wakeup_period": 600,
"reset_reason": 8
},
"temperature:0": {
"id": 0,
"tC": 22.6,
"tF": 72.6
},
"wifi": {
"sta_ip": "192.168.178.75",
"status": "got ip",
"ssid": "FRITZ!Box 7530 KI",
"rssi": -49
},
"ws": {
"connected": false
}
},
"series": "Percentuale"
}
]
As you can see, both the syntax are extracing only down to msg.params, and ignoring all square brackets. Why ?