You still have some dz. in that code that needs to be replaced by domoticz.
Code: Select all
local scriptVar = '3PhaseCurrent'
return
{
on =
{
timer =
{
'every 5 minutes',
},
httpResponses =
{
scriptVar
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- set to LOG_ERROR when tested and OK
marker = scriptVar,
},
execute = function(domoticz, item)
if item.isTimer then
domoticz.openURL({
url = 'http://192.168.1.120/api/xdevices.json?cmd=30',
callback = scriptVar,
})
return
end
if (item.isHTTPResponse) then
if item.ok then
--- do the parsing logic here
local jsonValeur = item.json
faza1=(tonumber(jsonValeur.AN6)/310) --faza1 on IPX800V3
faza2=(tonumber(jsonValeur.AN7)/310) --faza2 on IPX800V3
faza3=(tonumber(jsonValeur.AN8)/310) --faza3 on IPX800V3
darling=(tonumber(jsonValeur.AN5)/310) --darling
domoticz.log('3 Phase values = ' .. faza1 .. ' , ' .. faza2 .. ' , ' .. faza3, domoticz.LOG_INFO)
-- update devices here
domoticz.devices(44).updateCurrent(faza1, faza2, faza3) -- update IDX:44 CM113, Electrisave
-- domoticz.devices(40).update????(darling) -- update command depends on device type. See dzVents Wiki
else
domoticz.log('There was a problem handling the request', domoticz.LOG_ERROR)
domoticz.log(item, domoticz.LOG_ERROR)
end
end
end
}
And no, dzvents timers can't be set faster than once per minute. I think you may be able to do it though using
command option .afterSec()), but i haven't tested it so I really don't know if below code actually works. But if it does work, it will query your device and update your device values in domoticz every 15 seconds. I also added .checkFirst() to the update statement, to prevent the values to be updated every 15 seconds even if no new value was read. Again, this is untested: see for yourself if it works. And please do let us know the results
Code: Select all
local scriptVar = '3PhaseCurrent'
return
{
on =
{
timer =
{
'every 1 minute',
},
httpResponses =
{
scriptVar
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- set to LOG_ERROR when tested and OK
marker = scriptVar,
},
execute = function(domoticz, item)
if item.isTimer then
domoticz.openURL({
url = 'http://192.168.1.120/api/xdevices.json?cmd=30',
callback = scriptVar,
})
domoticz.openURL({
url = 'http://192.168.1.120/api/xdevices.json?cmd=30',
callback = scriptVar,
}).afterSec(15)
domoticz.openURL({
url = 'http://192.168.1.120/api/xdevices.json?cmd=30',
callback = scriptVar,
}).afterSec(30)
domoticz.openURL({
url = 'http://192.168.1.120/api/xdevices.json?cmd=30',
callback = scriptVar,
}).afterSec(45)
return
elseif (item.isHTTPResponse) then
if item.ok then
--- do the parsing logic here
local jsonValeur = item.json
faza1=(tonumber(jsonValeur.AN6)/310) --faza1 on IPX800V3
faza2=(tonumber(jsonValeur.AN7)/310) --faza2 on IPX800V3
faza3=(tonumber(jsonValeur.AN8)/310) --faza3 on IPX800V3
darling=(tonumber(jsonValeur.AN5)/310) --darling
domoticz.log('3 Phase values = ' .. faza1 .. ' , ' .. faza2 .. ' , ' .. faza3, domoticz.LOG_INFO)
-- update devices here
domoticz.devices(44).updateCurrent(faza1, faza2, faza3).checkFirst() -- update IDX:44 CM113, Electrisave
-- domoticz.devices(40).update????(darling) -- update command depends on device type. See dzVents Wiki
else
domoticz.log('There was a problem handling the request', domoticz.LOG_ERROR)
domoticz.log(item, domoticz.LOG_ERROR)
end
end
end
}
However, dzvents may still not be the best solution for this, because this is actually an implementation of a hardware device. I think it should be possible to implement this using the
http/https poller hardware. Using that method it
is possible to trigger the refresh more often than once per minute, for example every 10 seconds is quite normal. An example of how this is done for another device can be found here (site is in Dutch, sorry) :
https://www.connectix.nl/watermeter-uit ... -domoticz/