At the moment I am trying to get a custom sensor to show my daily gas and energy costs. the complicating factor is that I have a double tariff meter and fixed daily costs.
I have used a script which I found at:
https://ehoco.nl/stroom-gas-en-waterkos ... -domoticz/
The standard script is for a single tariff meter, which is why I played around with the other script found in the comment section of the page.
The thing is, I don't get it to work. I don't get any errors, but I don't see any energy costs either. So, I have the following questions:
1. As Domoticz uses the T1 and T2 tariffs correctly, would it be possible to write a script that reads out the kwh usage of the usage1 and usage2 (i.e., T1 and T2), multiply it with the Costs from the Domoticz 'Meters/Counters' settings and show it in a Custom Sensor?
2. Given the script I have below, how could I add a rule that states that the 'khwPrijs' = 0.21 between 7.00 and 23.00 hours and that the KwhPrijs = 0.19 between 23.00 and 07.00 hours. Using the code from the website I mentioned, doesn't work.
I have spend a full day searching for solutions, but can't seem to find the answer. Your help is appreciated

Code: Select all
return {
-- on = { timer = { "every 5 minutes" }}, -- script draait iedere 5 minuten
on = { devices = { "Stroom","Gas","Waterverbruik" }}, -- Verwijder -- aan het begin van deze regel en plaats -- voor bovenstaande regel als
-- je het script wilt draaien zodra er een nieuw verbruik aan Domoticz is doorgegeven
execute = function(dz)
-- Devices
local vandaagKwh = dz.devices('Stroom').counterToday -- Stroommeter device
local vandaagM3Gas = dz.devices('Gas').counterToday -- Gasmeter device
local StroomKosten = dz.devices('Stroomkosten') -- Stroomkosten device
local GasKosten = dz.devices('Gaskosten') -- Gaskosten device
-- Eenheidsprijs in Euro's / Kwh - M3
local kwhPrijs = 0.21
local gasM3Prijs = 0.5836
-- Vaste kosten in Euro's per dag (zoals vastrecht)
local kwhPrijsVast = 0.89000
local gasM3PrijsVast = 0.79000
-- Kosten berekenen
local kwhKosten = tonumber(dz.utils.round( (kwhPrijs * vandaagKwh),2) + kwhPrijsVast)--)--:gsub("%.",",") -- rounded to two decimals and replace dot by comma
local GasM3Kosten = tonumber(dz.utils.round( (gasM3Prijs * vandaagM3Gas),2) + gasM3PrijsVast)--)--:gsub("%.",",")
-- Kosten updaten
StroomKosten.updateCustomSensor(kwhKosten)
GasKosten.updateCustomSensor(GasM3Kosten)
end
}