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
Access multiple json.item objects
Moderator: leecollings
- waltervl
- Posts: 5148
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: Access multiple json.item objects
You have to check the trigger eg
Code: Select all
if item.isHTTPResponse and item.isJSON then
if item.trigger == 'scriptVar1' then
-- do your scrptvar 1 thing
elseif item.trigger == 'scriptVar2' then
-- do your scrptvar 2 thing
end
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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Who is online
Users browsing this forum: No registered users and 1 guest