Two JSON Calls
Posted: Friday 18 September 2020 6:59
Hi,
I have a quick question. I have a DZVents script that calculate the MonthTotal for my P1 meter by using a Json call. Basically this script works OK
Now, I wanted to add a new script that does a JSON call to my SolarEdge energy meter, to calculate what I use in my house for the month. Basically to start with it, I created a copy of the initial script. I have changed the local httpResponses to a different value so that it is a seperate script. But I am doing something wrong here, because when I enable this script the other script does not find any value's anymore. When I disable this script, the old script works OK. Could it be that two JSON calls around in the same time can be the problem? Or is there something more necessary to make this script unique?
A small snippit of the new script:
and a snippit of the P1 script:
I also tried somthing to combine it in one script; but really don't know where to start there...
I have a quick question. I have a DZVents script that calculate the MonthTotal for my P1 meter by using a Json call. Basically this script works OK
Now, I wanted to add a new script that does a JSON call to my SolarEdge energy meter, to calculate what I use in my house for the month. Basically to start with it, I created a copy of the initial script. I have changed the local httpResponses to a different value so that it is a seperate script. But I am doing something wrong here, because when I enable this script the other script does not find any value's anymore. When I disable this script, the old script works OK. Could it be that two JSON calls around in the same time can be the problem? Or is there something more necessary to make this script unique?
A small snippit of the new script:
Code: Select all
local httpResponses = "monthTotal_Sun"
return {
on = {
timer = { "every 1 minutes" },
httpResponses = {'httpResponses'}
},
logging = {
level = domoticz.LOG_ERROR, -- set to LOG_ERROR when script works as expected
marker = httpResponse
},
execute = function(dz, item)
-- ****************************** Your settings below this line ***************************************************
sunDevice = dz.devices(1055) -- Replace xxxx with ID of energyDevice you want to track
monthTotal = dz.devices(1032) -- Create as virtual managed counter (energy) and change yyyy to the ID of the new device
-- ****************************** No changes required below this line *********************************************
local function logWrite(str,level)
dz.log(tostring(str),level or dz.LOG_DEBUG)
end
local function triggerJSONSun(id, period, delay)
local delay = delay or 0
local URLString = 'http://192.168.0.4:8084/json.htm?type=graph&sensor=counter&range=month&idx=1055'
dz.openURL({ url = URLString,
method = "GET",
callback = httpResponses .. "_" .. period}).afterSec(delay)
endCode: Select all
local httpResponses = "monthTotal"
return {
on = {
timer = { "every 5 minutes" },
httpResponses = { httpResponses .. "*" }
},
logging = {
level = domoticz.LOG_ERROR, -- set to LOG_ERROR when script works as expected
marker = httpResponse
},
execute = function(dz, item)
-- ****************************** Your settings below this line ***************************************************
usageDevice = dz.devices(1008) -- Replace xxxx with ID of energyDevice you want to track
monthTotal = dz.devices(1033) -- Create as virtual managed counter (energy) and change yyyy to the ID of the new device
-- ****************************** No changes required below this line *********************************************
local function logWrite(str,level)
dz.log(tostring(str),level or dz.LOG_DEBUG)
end
local function triggerJSON(id, period, delay)
local delay = delay or 0
local URLString = 'http://192.168.0.4:8084/json.htm?type=graph&sensor=counter&range=month&idx=1008'
dz.openURL({ url = URLString,
method = "GET",
callback = httpResponses .. "_" .. period}).afterSec(delay)