Script sets wrong value at 00:00  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
drasnirp
Posts: 2
Joined: Saturday 12 November 2022 8:55
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Script sets wrong value at 00:00

Post by drasnirp »

I have a script that calculates the costs of power and gas consumption. The problem is it set the highest value at 00:00 hour. See screendump.

That will result in a Dashticz Graph that shows this value at the next day. See screendump graph1. The top bars are consumption and the bottom two are the costs of consumption. Use on the 12th of november is at a minimum but the costs are equal to november 11th. After editing the idx 533 and 534 in de database, the graph is correct.
As shown in Graph2 screendump after editing the value of gas, the costs on november 12 are only networkcosts. Before I edited the value it had the same value as november 11th.

Whats is wrong with the script or Dashticz that this issue happens.
Domoticz:
Version: 2022.2
Build Hash: eea9db734
Compile Date: 2022-11-05 13:05:35
dzVents Version: 3.1.8
Python Version: 3.9.2 (default, Mar 12 2021, 04:06:34) [GCC 10.2.1 20210110]
Dashticz:
Master version 3.9
Rapberry pi 3B+

Any help is welcome.

Script:

Code: Select all

local scriptVar = 'A_KostenGasStroom'
return {
	on = { timer = { "every 5 minutes" }}, 				  -- script draait iedere minuut tussen tijden om waarde overdracht te voorkomen
	logging ={
        level = domoticz.LOG_ERROR, -- Change to LOG_DEBUG to debug / Change to LOG_ERROR if script is running properly
        marker = scriptVar,
    },
 -- 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('Electra').counterToday -- Stroommeter device
	local vandaagM3Gas = dz.devices('Gas').counterToday -- Gasmeter device
	--local vandaagM3Water = dz.devices('Waterverbruik').counterToday -- Watermeter device

	local StroomKosten = dz.devices('Electrakosten') -- Stroomkosten device
	local GasKosten = dz.devices('Gaskosten') -- Gaskosten device
	--local WaterKosten = dz.devices('Waterkosten') -- Waterkosten device

	-- Eenheidsprijs in Euro's / Kwh - M3 local kwhPrijs 
	local gasM3Prijs = 2.15138
	--local waterM3Prijs = 0.8200
		if (dz.time == 'Between 23:00 and 07:00') or (dz.day == 'Saturday') or (dz.day == 'Sunday') then
			kwhPrijs = 0.52943 -- Daltarief
		else kwhPrijs = 0.52943 -- Normaal tarief
		end
		
	-- Vaste kosten in Euro's per dag (zoals vastrecht)
	local kwhPrijsVast = 0.85273
	local gasM3PrijsVast = 0.64999
	--local waterM3PrijsVast = 0.0000
	
	-- Kosten berekenen
	
	
	--local kwhKosten   = ((kwhPrijs * vandaagKwh)     + kwhPrijsVast)
	local kwhtotaal = (((kwhPrijs * vandaagKwh)     + kwhPrijsVast)+0.005)
	dz.log('Stroomtotaal (day): '  .. kwhtotaal .. ' EUR', dz.LOG_DEBUG)
	local kwhtotaal = math.floor(kwhtotaal * 100)
	local kwhKosten = (kwhtotaal /100)
	local Gastotaal = (((gasM3Prijs * vandaagM3Gas) + gasM3PrijsVast)+0.005)
	dz.log('Gastotaal (day): '  .. Gastotaal .. ' EUR', dz.LOG_DEBUG)
	local Gastotaal = math.floor(Gastotaal * 100)
	local GasM3Kosten = (Gastotaal /100)
	dz.log('Stroomtotaal afgerond (day): '  .. kwhKosten .. ' EUR', dz.LOG_DEBUG)
	dz.log('Gastotaal afgerond (day): '  .. GasM3Kosten .. ' EUR', dz.LOG_DEBUG)
	end
	
	
	-- Kosten updaten
	StroomKosten.updateCustomSensor(kwhKosten)
	GasKosten.updateCustomSensor(GasM3Kosten)
	-- WaterKosten.updateCustomSensor(WaterM3Kosten)

	
	end
    }
Attachments
graph2.png
graph2.png (3.59 KiB) Viewed 285 times
graph1.png
graph1.png (4.08 KiB) Viewed 285 times
2022-11-12 09_00_41-192.168.68.107 - Verbinding met extern bureaublad.png
2022-11-12 09_00_41-192.168.68.107 - Verbinding met extern bureaublad.png (30.35 KiB) Viewed 285 times
drasnirp
Posts: 2
Joined: Saturday 12 November 2022 8:55
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Script sets wrong value at 00:00  [Solved]

Post by drasnirp »

Solved it by running a script that edits the value. This script uses sqlite3 to edit the wrong value at 00:00. Tested and works fine. Case Closed.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest