Access multiple json.item objects
Posted: Wednesday 20 November 2024 16:05
Hi,
I 'm looking for a way to process multiple HTTP resonses of different openurl results.
E.g :
Open 2 different graph API calls for 2 different devices (idx 1 and idx2)
url1 = dz.settings['Domoticz url'] .. '/json.htm?type=command¶m=graph&sensor=counter&range=year&idx=' .. id1
dz.openURL({ url = url1, callback = scriptVar1 })
url2 = dz.settings['Domoticz url'] .. '/json.htm?type=command¶m=graph&sensor=counter&range=month&idx=' .. id2
dz.openURL({ url = url2, callback = scriptVar2 })
When I have only one url call, I process the results like this:
-- main
if item.isHTTPResponse and item.isJSON then
updateTextSensor(processResult(item.json))
elseif item.isTimer then
callYearGraph(idx1)
else
dz.log(' Error while retrieving elektra data. Result is ' .. item.statusText ..' ; Response is: ' .. item.data)
end
I know that the result of ONE openurl call is in item.json.
Can somebody give me an example of processing TWO url calls using TWO item.json tables with the different callback methods?
Thanks in advance, InfoEd
I 'm looking for a way to process multiple HTTP resonses of different openurl results.
E.g :
Open 2 different graph API calls for 2 different devices (idx 1 and idx2)
url1 = dz.settings['Domoticz url'] .. '/json.htm?type=command¶m=graph&sensor=counter&range=year&idx=' .. id1
dz.openURL({ url = url1, callback = scriptVar1 })
url2 = dz.settings['Domoticz url'] .. '/json.htm?type=command¶m=graph&sensor=counter&range=month&idx=' .. id2
dz.openURL({ url = url2, callback = scriptVar2 })
When I have only one url call, I process the results like this:
-- main
if item.isHTTPResponse and item.isJSON then
updateTextSensor(processResult(item.json))
elseif item.isTimer then
callYearGraph(idx1)
else
dz.log(' Error while retrieving elektra data. Result is ' .. item.statusText ..' ; Response is: ' .. item.data)
end
I know that the result of ONE openurl call is in item.json.
Can somebody give me an example of processing TWO url calls using TWO item.json tables with the different callback methods?
Thanks in advance, InfoEd