Created
November 8, 2022 22:19
-
-
Save dnmvisser/7c048ecd3f0e65c032cc390066fca4f4 to your computer and use it in GitHub Desktop.
Domoticz dzvents script voor het ophalen van Zonneplan prijzen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- dzvents script Instructions | |
-- Create the dummy hardware in Domoticz if you haven't done so already and | |
-- from there create two 'Custom Sensor' devices with the axis labels | |
-- '€/kWh' and '€/m³'. Then set the following two device ids: | |
local powerDeviceIdx = 48 | |
local gasDeviceIdx = 49 | |
return { | |
on = { | |
timer = { | |
'every hour' | |
}, | |
httpResponses = { | |
'triggerPower', | |
'triggerGas' | |
}, | |
--system = { | |
-- 'resetAllEvents' | |
--} | |
}, | |
logging = { | |
level = domoticz.LOG_INFO, | |
marker = 'Energieprijzen Zonneplan', | |
}, | |
execute = function(domoticz, item) | |
local Time = require('Time') | |
local hour = Time().hour | |
if (item.isHTTPResponse) then | |
if (item.ok) then | |
if (item.isJSON) then | |
local result_table = item.json | |
if (item.trigger == 'triggerPower') then | |
local price = result_table.data[hour+1].prijsZP; | |
local device = domoticz.devices(powerDeviceIdx); | |
device.updateCustomSensor(price) | |
domoticz.log('Updated power price: ' .. price) | |
elseif (item.trigger == 'triggerGas') then | |
local price = result_table.data[1].prijsZP; | |
local device = domoticz.devices(gasDeviceIdx); | |
device.updateCustomSensor(price) | |
domoticz.log('Updated gas price: ' .. price) | |
end | |
else | |
domoticz.log('HTTP is not json', domoticz.LOG_ERROR) | |
end | |
else | |
domoticz.log('There was a problem handling the request: ' .. url, domoticz.LOG_ERROR) | |
domoticz.log(item, domoticz.LOG_ERROR) | |
end | |
else | |
domoticz.openURL({ | |
url = 'https://enever.nl/feed/stroomprijs_vandaag.php', | |
method = 'GET', | |
callback = 'triggerPower', | |
}) | |
domoticz.openURL({ | |
url = 'https://enever.nl/feed/gasprijs_vandaag.php', | |
method = 'GET', | |
callback = 'triggerGas', | |
}) | |
end | |
end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment