Extract value from json response
Posted: Saturday 26 March 2022 10:49
Hi, I am a newbie to domoticz, and have been experimenting with lua/dzvents scripting, and need a little help
My script calls dz.openurl with a callback
My question is after the
how do I extract the numeric value from the "node.Data" field so that power will contain a value of 309, and does not have the units of "watt" so that I can use this to update another custom sensor
Many Thanks
My script calls dz.openurl with a callback
Code: Select all
/json.htm?type=devices&rid=2, which successfully returns values,
ie
"Data" : "309 Watt",
"LastUpdate" : "2022-03-25 19:05:43",
Code: Select all
if item.isHTTPResponse and item.isJSON then
local results=item.json.result
for i, node in pairs(results) do
[b]local power = node.Data -- just holding the numeric part without units[/b]
local lastUpdate = Time(node.LastUpdate)
...
end
end
Many Thanks