-
-
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 | |
} |
@wkossen I guess by using dzvents instead of lua :-)
That would be an interesting thing. maybe the .lua extension of the scriptname set me on the wrong path. let me try that :)
indeed. the error is gone, but no values in the custom sensors yet...
Well dzvents is a superset of lua, hence the lua extensions.
Well dzvents is a superset of lua, hence the lua extensions.
i'm such an amateur.... but thanks for your very fast response.... still no values though, but also no errors in log...
Keep in mind it runs every whole hour. You can trigger it on save by uncommenting lines 18 ~ 20.
For these 2 lines ..
price = price * 1.09 + ( 0.01472 + 0.04010 + 0.03325 )
price = price * 1.09 + ( 0.05230 + 0.39591 + 0.09429 )
Do you have any explanation what the value's are ? 1.09 I can trace back to dutch VAT (BTW) which is 9% until end of the year.
The other 3 values I have no idea what they are, and why they are there.
What I do know is that I would have put the values and the BTW as well in a variable at the top of the script (or even a user variable)
for electricity these are: energy tax (should be 0.03677 p/kWh), ODE (should be 0.03048), and probability transaction costs (differs per provider).
for gas idem: taxes + ODE + transaction costs (0.36069 + 0.08586 + x )
Thanks for that info... it makes more sense now.
@kipusoep it would be better to have those as parameters or config
it's even a little more complicated. In the script above the energytax, ode and transaction cost are assumed includig VAT (BTW
price = price * 1.09 + ( 0.01472 + 0.04010 + 0.03325 )
If taking all prices without VAT (BTW) the calculation should be
price = (price + 0.01472 + 0.04010 + 0.03325 ) * 1.09
I hope you don't mind that I post my changes here. If so please let me know then I will remove it.
-- 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 = 91
local gasDeviceIdx = 92
local vatPercentage = 9 -- value of the VAT (BTW) percentage (without % sign)
local elec = {
energyTax = 0.114079, -- must be excluding VAT (BTW) - Put the real values from your energy supplier
ode = 0.036300, -- must be excluding VAT (BTW) - Put the real values from your energy supplier
transactionCost = 0.0, -- must be excluding VAT (BTW) - Put the real values from your energy supplier
}
local gas = {
energyTax = 0.114079, -- must be excluding VAT (BTW) - Put the real values from your energy supplier
ode = 0.036300, -- must be excluding VAT (BTW) - Put the real values from your energy supplier
transactionCost = 0.0, -- must be excluding VAT (BTW) - Put the real values from your energy supplier
}
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 + elec.energyTax + elec.ode + elec.transactionCost) * (1.0 + (vatPercentage / 100))
local device = domoticz.devices(powerDeviceIdx);
device.updateCustomSensor(price)
domoticz.log('Updated power price: ' .. price)
elseif (item.trigger == 'triggerGas') then
price = (price + gas.energyTax + gas.ode + gas.transactionCost) * (1.0 + (vatPercentage / 100))
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
}
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
@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.
same error here... how can i fix that?