open multiple urls and combine results
Posted: Thursday 04 June 2020 12:09
Hi All,
I'm currently the happy owner of two solar systems which I already manage to read in domoticz.
Now I want to combine the reading in one dummy device.
In order to do that I was programming in dzvents to get the results of the CounterToday value of both the inverters.
see the attached script.
When I debug this all went ok until the translation from string to number value.
the number value is printed twice!
Can anyone help me out to achieve:
Open url device 1 get value of CounterToday as number
Open url device 2 get value of CounterToday as number
calculate the combined new value of CounterToday
write value back to dummy device
Thanx in advance.
I'm currently the happy owner of two solar systems which I already manage to read in domoticz.
Now I want to combine the reading in one dummy device.
In order to do that I was programming in dzvents to get the results of the CounterToday value of both the inverters.
see the attached script.
Code: Select all
return {
on = {
timer = { 'every 1 minutes' },
httpResponses = {
'trigger' -- must match with the callback passed to the openURL command
}
},
execute = function(domoticz, item)
if (item.isTimer) then
domoticz.openURL({
url = 'http://xx.x.x.xxx:8080/json.htm?username=xxxxx=&password=xxxxx=&type=devices&rid=679',
method = 'GET',
callback = 'trigger',
})
end
if (item.isHTTPResponse and item.ok) then
local results = item.json.result
-- loop through the nodes and print some info
for i, node in pairs(results) do
--local lastUpdate = Time(node.LastUpdate)
--print(node.Name ..' vandaag opgeleverd: ' ..node.CounterToday)
opbrengst1 = node.CounterToday
opbr1 = opbrengst1.gsub(opbrengst1, "( kWh)", "", 1)
opb1 = opbr1 + 0
print('opb1 :'..opb1)
end
for i, node in pairs(results) do
results[i] = nil
end
local results = nil
end
if (item.isTimer) then
domoticz.openURL({
url = 'http://xx.x.x.xxx:8080/json.htm?username=xxxxx=&password=xxxxx=&type=devices&rid=680',
method = 'GET',
callback = 'trigger',
})
end
if (item.isHTTPResponse and item.ok) then
--local Time = require('Time')
local results = item.json.result
-- loop through the nodes and print some info
for i, node in pairs(results) do
-- convert the time stamp in the raw data into a
-- dzVents Time object
--local lastUpdate = Time(node.LastUpdate)
print(node.Name ..' vandaag opgeleverd: ' ..node.CounterToday)
local opbrengst2 = node.CounterToday
opbr2 = opbrengst2.gsub(opbrengst2, "( kWh)", "", 1)
opb2 = opbr2 + 0
end
for i, node in pairs(results) do
results[i] = nil
end
end
print('opb1 :'..opb1 ..'&'..'opb2 :'..opb2)
opbtot = opb1 + opb2
print('Zonnepanelen opbrengst: ' ..opbtot)
end
}
the number value is printed twice!
Code: Select all
2020-06-04 12:02:00.471 Status: EventSystem: Script event triggered: timer_script_new
2020-06-04 12:02:00.555 Status: dzVents: opb1 :2.183
2020-06-04 12:02:00.621 Status: dzVents: opb1 :1.626
Open url device 1 get value of CounterToday as number
Open url device 2 get value of CounterToday as number
calculate the combined new value of CounterToday
write value back to dummy device
Thanx in advance.