Last active
February 16, 2023 21:34
-
-
Save kipusoep/e1e0804ba7503e6806e8b7ec03298dfa to your computer and use it in GitHub Desktop.
Ophalen van EnergyZero energieprijzen voor Domoticz
This file contains hidden or 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
-- Instructions -- | |
-- Create the dummy hardware in Domoticz if you haven't already and from there, | |
-- create two 'Custom Sensor' devices with the axis labels 'EUR/kWh' and 'EUR/m³'. | |
-- Then set the following two device ids: | |
local powerDeviceIdx = 222 | |
local gasDeviceIdx = 223 | |
return { | |
on = { | |
timer = { | |
'every hour' | |
}, | |
httpResponses = { | |
'triggerPower', | |
'triggerGas' | |
}, | |
--system = { | |
-- 'resetAllEvents' | |
--} | |
}, | |
logging = { | |
level = domoticz.LOG_INFO, | |
marker = 'Energieprijzen', | |
}, | |
execute = function(domoticz, item) | |
local Time = require('Time') | |
local currentTime = Time() | |
if (item.isHTTPResponse) then | |
if (item.ok) then | |
if (item.isJSON) then | |
local result_table = item.json | |
local price = result_table.Prices[1].price; | |
if (item.trigger == 'triggerPower') then | |
price = price * 1.09 + ( 0.01472 + 0.04010 + 0.03325 ) | |
local device = domoticz.devices(powerDeviceIdx); | |
device.updateCustomSensor(price) | |
domoticz.log('Updated power price: ' .. price) | |
elseif (item.trigger == 'triggerGas') then | |
price = price * 1.09 + ( 0.05230 + 0.39591 + 0.09429 ) | |
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 | |
local utc = os.date("!*t") | |
local timestamp = domoticz.time.rawDate .. "T" .. utc.hour .. ":00:00.000Z" | |
domoticz.openURL({ | |
url = 'https://api.energyzero.nl/v1/energyprices?fromDate=' .. timestamp .. '&tillDate=' .. timestamp .. '&interval=4&usageType=1&inclBtw=false', | |
method = 'GET', | |
callback = 'triggerPower', | |
}) | |
domoticz.openURL({ | |
url = 'https://api.energyzero.nl/v1/energyprices?fromDate=' .. timestamp .. '&tillDate=' .. timestamp .. '&interval=4&usageType=4&inclBtw=false', | |
method = 'GET', | |
callback = 'triggerGas', | |
}) | |
end | |
end | |
} |
That explains @barts2108 😏
Btw, is your gas price still being updated? Mine hasn't since yesterday 1 AM and I see errors in the log.
Ah, it seems the energyzero api doesn't return any gas prices at the moment.
It would be great if the script can read the specific price for one supplier from the price feeds from Enever.nl (https://enever.nl/prijzenfeeds/) so everybody (from the Netherlands), no matter what supplier you have, can use your script. And you have the prices with and without taxes and all.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@kipusoep I take it from my supplier, probably value of 2023 but excl VAT (BTW), and I just see it is merged with ODE