-
-
Save kipusoep/e1e0804ba7503e6806e8b7ec03298dfa to your computer and use it in GitHub Desktop.
-- 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 | |
} |
@barts2108 ofcourse I don't mind! Improvements are always welcome.
I was wondering; the energyTax
variables you posted are pretty high, is that because of the region you live in?
For me it's approximately € 0,036 for both elec and gas. The amount you've posted is € 0,114. Or is this just an example?
see https://www.anwb.nl/huis/energie/energiebelasting for the tax rates
@kipusoep I take it from my supplier, probably value of 2023 but excl VAT (BTW), and I just see it is merged with ODE
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.
In case you only can get the taxes inclusive of VAT (BTW) you should use
price = price * (1.0 + (vatPercentage / 100)) + (elec.energyTax + elec.ode + elec.transactionCost)
and
price = price * (1.0 + (vatPercentage / 100)) + (gas.energyTax + gas.ode + gas.transactionCost)
for the calculations