Skip to content

Instantly share code, notes, and snippets.

@kipusoep
Last active February 16, 2023 21:34
Show Gist options
  • Save kipusoep/e1e0804ba7503e6806e8b7ec03298dfa to your computer and use it in GitHub Desktop.
Save kipusoep/e1e0804ba7503e6806e8b7ec03298dfa to your computer and use it in GitHub Desktop.
Ophalen van EnergyZero energieprijzen voor Domoticz
-- 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
}
@hardcodedpassword
Copy link

@barts2108
Copy link

barts2108 commented Jan 1, 2023

@kipusoep I take it from my supplier, probably value of 2023 but excl VAT (BTW), and I just see it is merged with ODE

@kipusoep
Copy link
Author

kipusoep commented Jan 1, 2023

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.

@kipusoep
Copy link
Author

kipusoep commented Jan 1, 2023

Ah, it seems the energyzero api doesn't return any gas prices at the moment.

@TheLion
Copy link

TheLion commented Feb 16, 2023

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