Hi Bjornp,
Thanks for sharing this!
I'm new to DzVents and also to LUA so forgive my ignorance
I tried out your script replacing the URL and device name but I get an error message in the log:
2020-06-17 19:00:10.463 Status: dzVents: Info: Handling httpResponse-events for: "trigger
2020-06-17 19:00:10.463 Status: dzVents: Info: ------ Start internal script: Kostal 1: HTTPResponse: "trigger"
2020-06-17 19:00:10.463 Status: dzVents: Error (2.4.19): There was a problem handling the request
2020-06-17 19:00:10.464 Status: dzVents: Error (2.4.19): {["isTimer"]=false, ["ok"]=false, ["data"]="", ["isDevice"]=false, ["isSecurity"]=false, ["isGroup"]=false, ["trigger"]="trigger", ["isJSON"]=false, ["isScene"]=false, ["statusText"]="Timeout was reached", ["statusCode"]=28, ["callback"]="trigger", ["baseType"]="httpResponse", ["protocol"]="HTTP/1.1", ["isVariable"]=false, ["headers"]={}, ["isHTTPResponse"]=true, ["_contentType"]=""}
2020-06-17 19:00:10.464 Status: dzVents: Info: ------ Finished Kostal 1
2020-06-17 19:00:10.349 Error: Error opening url:
http://192.168.0.50/api/dxs.json?dxsEnt ... =251658753
Any idea of what I did wrong?
Thanks
Below the script:
return {
on = {
timer = {
'every 5 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://192.168.0.50/api/dxs.json?dxsEnt ... =251658753', -- 67109120 = current power W and 251658753 = lifetime total kWh
method = 'GET',
callback = 'trigger',
})
end
if (item.isHTTPResponse) then
if (item.statusCode == 200) then
local json = domoticz.utils.fromJSON(item.data) -- Convert to JSON because Piko does not specify it as json in header
if json.dxsEntries[1]['dxsId'] == 67109120 and json.dxsEntries[2]['dxsId'] == 251658753 then
local current = json.dxsEntries[1]['value']
local lifetime = json.dxsEntries[2]['value']
print('Piko - Current power: ' .. domoticz.utils.round(current,0) .. ' W | Lifetime total: ' .. domoticz.utils.round(lifetime,3) .. ' kWh')
local inverter = domoticz.devices('Kostal')
inverter.updateElectricity(current,(domoticz.utils.round(lifetime,3)*1000)) -- lifetime needs to be in Wh (not kWh)
else
print('Entries not found or incorrect entries found in table')
end
else
domoticz.log('There was a problem handling the request', domoticz.LOG_ERROR)
domoticz.log(item, domoticz.LOG_ERROR)
end
end
end