Energy costs in bar graph instead of line graph

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

Moderator: leecollings

Post Reply
HennyN
Posts: 6
Joined: Friday 21 May 2021 21:42
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Energy costs in bar graph instead of line graph

Post by HennyN »

Hello,
I hope to get an answer / solution to my challenge here. I read my energy consumption with a P1 module. That works. I found a script to calculate consumption to Energy costs and it works too. However, I see a line graph in the “log” of Gas costs and I would like a bar graph the same I see with my gas consumption and my power consumption.

I see this in the log of my gas costs:
gaskosten.jpg
gaskosten.jpg (58.38 KiB) Viewed 1228 times

But I would like to see it like this:
gasverbruik.jpg
gasverbruik.jpg (53.33 KiB) Viewed 1228 times
So with bars.

I use this script for it and will therefore have to change something somewhere, so it does shows bars instead of lines.

Who knows the answer or gives me a hint?

Code: Select all

return {
        on = { timer = { 'every 15 minutes' }}, 

        execute = function(domoticz, device, timer)

        local vandaagKwh      = domoticz.devices('Power').counterToday 
        local vandaagM3Gas    = domoticz.devices('Gas').counterToday 
               
        local StroomKosten  = domoticz.devices('StroomKosten')
        local GasKosten     = domoticz.devices('GasKosten')
        local Kosten = domoticz.devices('TotaalEnergieKosten')
        
        -- Eenheidsprijs in Euro's / Kwh - M3
        local kwhPrijs = 0.22903
        local gasM3Prijs = 0.74681
        

        if (domoticz.time == 'Between 23:00 and 07:00') or (domoticz.day == 'Saturday') or (domoticz.day == 'Sunday') then
            kwhPrijs = 0.21024 -- Daltarief
        else
            kwhPrijs = 0.22903 -- Normaal tarief
        end 
       
        -- Vaste kosten in Euro's per dag (zoals vastrecht) 
        local kwhPrijsVast = 0.70132
        local gasM3PrijsVast = 0.54740
        
        -- Kosten berekenen
        local kwhKosten = tonumber(domoticz.utils.round( (kwhPrijs * vandaagKwh) + kwhPrijsVast,2))   
        local GasM3Kosten = tonumber(domoticz.utils.round( (gasM3Prijs * vandaagM3Gas) + gasM3PrijsVast,2))
        local Kostentotaal = kwhKosten + GasM3Kosten
      
        -- Kosten updaten
        StroomKosten.updateCustomSensor(kwhKosten)
        GasKosten.updateCustomSensor(GasM3Kosten)
        Kosten.updateCustomSensor(Kostentotaal)
    end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Energy costs in bar graph instead of line graph

Post by waaren »

HennyN wrote: Friday 21 May 2021 22:21 I use this script for it and will therefore have to change something somewhere, so it does shows bars instead of lines.
The type of graph is defined by the device type and not by dzVents. Best to experiment with other virtual device type. From the top of my head RFX counter produce bar graphs.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
HennyN
Posts: 6
Joined: Friday 21 May 2021 21:42
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Energy costs in bar graph instead of line graph

Post by HennyN »

Is it possible to define a new device-type based on an existing device type? Copy a device-type and modify it????
HennyN
Posts: 6
Joined: Friday 21 May 2021 21:42
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Energy costs in bar graph instead of line graph

Post by HennyN »

By modifing the script I came a littlebit further and now got this:
GasKostenKolom.jpg
GasKostenKolom.jpg (30.64 KiB) Viewed 1180 times
But kWh should be EUR and I have to get two decimals instead of 3 but I think I can solve that by editing the formular in the script...
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Energy costs in bar graph instead of line graph

Post by waaren »

HennyN wrote: Sunday 23 May 2021 21:12 But kWh should be EUR
Press the edit (aanpassen) button on the device when in the utility tab.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
HennyN
Posts: 6
Joined: Friday 21 May 2021 21:42
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Energy costs in bar graph instead of line graph

Post by HennyN »

Afronden.jpg
Afronden.jpg (40.8 KiB) Viewed 1136 times

Oké. Now I have still one challenge... :(
How do I get 2 decimal place every where...
I did some testing and found that I can multiply with 100 in the script and then devide by 100 in the device..
But is there a neater way, better way to do that. :?:

Meter deler.jpg
Meter deler.jpg (57.93 KiB) Viewed 1136 times
HennyN
Posts: 6
Joined: Friday 21 May 2021 21:42
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Energy costs in bar graph instead of line graph

Post by HennyN »

STRANGE !!!!!!

In an attempt to get column graphs of the cost of gas consumption I run into strange things. If I show the costs with a custom sensor, I get € 0.78. but when I turn it into a Counter I see € 0.78 in one place but € 0.22 in the top right (or often other values that do not match.
When I look at the log I see a negative value on today Monday.

What is going on here???? What am I doing wrong?

Rare getallen Gas.jpg
Rare getallen Gas.jpg (35.84 KiB) Viewed 1090 times
Instellingen Counter Gas.jpg
Instellingen Counter Gas.jpg (51.38 KiB) Viewed 1090 times
Grafiek Gaskosten.jpg
Grafiek Gaskosten.jpg (53.63 KiB) Viewed 1090 times

Code: Select all

return {
        on = { timer = { 'every 5 minutes' }}, 

        execute = function(domoticz, device, timer)

        local vandaagKwh      = domoticz.devices('Power').counterToday 
        local vandaagM3Gas    = domoticz.devices('Gas').counterToday 
               
        local StroomKosten  = domoticz.devices('StroomKosten')
        local GasKosten     = domoticz.devices('GasKosten')
        local TotaalKosten  = domoticz.devices('EnergieKosten')
        local KostenE       = domoticz.devices('KostenElektra')
        local KostenG       = domoticz.devices('KostenGas')
        local KostenET      = domoticz.devices('KostenEnergie')
        
       -- Eenheidsprijs in Euro's / Kwh - M3
        local kwhPrijs = 0.22903
        local gasM3Prijs = 0.74681
        

        if (domoticz.time == 'Between 23:00 and 07:00') or (domoticz.day == 'Saturday') or (domoticz.day == 'Sunday') then
            kwhPrijs = 0.21024 -- Daltarief
        else
            kwhPrijs = 0.22903 -- Normaal tarief
        end 
       
        -- Vaste kosten in Euro's per dag (zoals vastrecht) 
        local kwhPrijsVast = 0.70132
        local gasM3PrijsVast = 0.54740
        
        -- Kosten berekenen
        local KwhKosten = tonumber(domoticz.utils.round( (kwhPrijs * vandaagKwh) + kwhPrijsVast,2))   
        local GasM3Kosten = tonumber(domoticz.utils.round( (gasM3Prijs * vandaagM3Gas) + gasM3PrijsVast,2))
        local KostenTotaal = KwhKosten + GasM3Kosten
        local KwhKostenCount = 100 * KwhKosten
        local GasM3KostenCount = 100 * GasM3Kosten
	    local KostenTotaalCount = 100 * KostenTotaal
        
        -- Kosten updaten
        StroomKosten.updateCustomSensor(KwhKosten)
        GasKosten.updateCustomSensor(GasM3Kosten)
        TotaalKosten.updateCustomSensor(KostenTotaal)
        KostenE.updateCounter(KwhKostenCount)
        KostenG.updateCounter(GasM3KostenCount)
        KostenET.updateCounter(KostenTotaalCount)
        
    end
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Energy costs in bar graph instead of line graph

Post by waaren »

HennyN wrote: Monday 31 May 2021 21:43 in the top right (or often other values that do not match.
Top right corner should show (max. today value )- (max yesterday value )
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest