Offset Gas counter

Moderator: leecollings

Post Reply
Knibor
Posts: 112
Joined: Sunday 20 May 2018 12:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: NL
Contact:

Offset Gas counter

Post by Knibor »

Hi, i have a P1 meter (slimme meter) And I can readout the "Gas" counter in Domoticz

Is it possible to copy the counter reading to another Virtual "managed" counter that has the possibility set an "offset"

Thanks
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Offset Gas counter

Post by waaren »

Knibor wrote: Thursday 10 January 2019 19:33 Hi, i have a P1 meter (slimme meter) And I can readout the "Gas" counter in Domoticz

Is it possible to copy the counter reading to another Virtual "managed" counter that has the possibility set an "offset"

Thanks
The dzVents script below does just that but to a virtual Gas meter. The offset is set in the script body and the new value will be set when your P1 gas device is updated.

Code: Select all

-- gasOffset

return {
    on      =   {   
                    devices         =   { "Gas"},        -- name of your real Gas devce
                },
                
    logging =   {   
                    level     =   domoticz.LOG_DEBUG,
                    marker    =   "gasOffset"    
                },

    execute = function(dz, item)
        local offset     = 123456                        -- Offset in dm3 (liters)
        local managedGas = dz.devices(1292)              -- id of device with offset
        managedGas.updateGas(item.counter * 1000 + offset)    
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Knibor
Posts: 112
Joined: Sunday 20 May 2018 12:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: NL
Contact:

Re: Offset Gas counter

Post by Knibor »

Waaren, thanks for the code.

Now I can reset the gasmeter when I get the energy bill.

Now I tried to calculate the Total cost in a year " Totaalkosten" this is the sum of the custom devices "Gaskosten" - "StroomOpbrengst"

I tried this dzVents code...but probably I do something wrong? It did't work.

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


execute = function(dz)

-- Devices

local StroomOpbrengst = dz.devices('Stroom Opbrengst')

local Gaskosten = dz.devices('Gaskosten')

local Totaalkosten = dz.devices('Totaalkosten')



-- Kosten berekenen

local kosten = tonumber(dz.utils(Gaskosten - StroomOpbrengst))

-- Kosten updaten

Totaalkosten.updateCustomSensor(kosten)

end
}

Can you help me with this.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Offset Gas counter

Post by waaren »

Knibor wrote: Friday 11 January 2019 21:17 Now I tried to calculate the Total cost in a year " Totaalkosten" this is the sum of the custom devices "Gaskosten" - "StroomOpbrengst"
I tried this dzVents code...but probably I do something wrong? It did't work.
Spoiler: show

Code: Select all

return {
    on = { timer   = { "every 5 minutes" }},    
    
    execute = function(dz)
        
        -- Devices
        local StroomOpbrengst   = dz.devices('Stroom Opbrengst')                         
        local Gaskosten         = dz.devices('Gaskosten')
        local Totaalkosten      = dz.devices('Totaalkosten')                         
        
        -- Kosten berekenen
        local kosten      = tonumber(dz.utils(Gaskosten - StroomOpbrengst))
        
        -- Kosten updaten
        Totaalkosten.updateCustomSensor(kosten)
         
    end
}
Can you help me with this.
Hi Knibor. "it does not work" is a bit too general. Most of the time when new code does not work you can get information on why it is not working in the domoticz logfile. In this case you try to subtract one device from another. What you want is do some calculation with device attributes.
And please enclose your code in code tags [ code] [/ code] (without the spaces). Can you try the code below ?

Code: Select all

return {
    on = { timer   = { "every 1 minutes" }},    

    logging   =     {  
                            level       =       domoticz.LOG_DEBUG,   
                            marker      =       "total Cost" 
                    },
    
    execute = function(dz)
   
        local function logWrite(str,level)
            dz.log(tostring(str),level or dz.LOG_DEBUG)
        end
        
        -- Custom sensors store values in sValue field (string)
        
        -- Money 
        local StroomOpbrengst   = dz.devices('Stroom Opbrengst').state
        local Gaskosten         = dz.devices('Gaskosten').state
        
        -- Device
        local Totaalkosten      = dz.devices('Totaalkosten')                         
        
        -- Kosten berekenen
        local kosten      = tonumber(Gaskosten) - tonumber(StroomOpbrengst)
        logWrite("Kosten zijn: " .. kosten ) 
        
        -- Kosten updaten
        Totaalkosten.updateCustomSensor(tostring(kosten))
         
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Knibor
Posts: 112
Joined: Sunday 20 May 2018 12:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: NL
Contact:

Re: Offset Gas counter

Post by Knibor »

Hi,

Thanks for the code, it works perfect. I divide the reading though 12, so I get the month cost.

The only thing is that I have now 4 digit behind the "dot"

I tried to round the reading on 2 digit, but no succes. The script was showing no error in front of the script line, but it didn't give me an correct output.

Can't find in the manual how to do this.
Schermafbeelding 2019-01-12 om 15.48.56.png
Schermafbeelding 2019-01-12 om 15.48.56.png (226.29 KiB) Viewed 1076 times
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Offset Gas counter

Post by waaren »

Knibor wrote: Saturday 12 January 2019 15:49 The only thing is that I have now 4 digit behind the "dot"
I tried to round the reading on 2 digit, but no succes. The script was showing no error in front of the script line, but it didn't give me an correct output.
try this

Code: Select all

return {
    on = { timer   = { "every 1 minutes" }},    

    logging   =     {  
                            level       =       domoticz.LOG_DEBUG,   
                            marker      =       "total Cost" 
                    },
    
    execute = function(dz)
   
        local function logWrite(str,level)
            dz.log(tostring(str),level or dz.LOG_DEBUG)
        end
        
        -- Custom sensors store values in sValue field (string)
        
        -- Money 
        local StroomOpbrengst   = dz.devices('Stroom Opbrengst').state
        local Gaskosten         = dz.devices('Gaskosten').state
        
        -- Device
        local Totaalkosten      = dz.devices('Totaal kosten')                         
        
        -- Kosten berekenen
        local jaarKosten       = tonumber(Gaskosten) - tonumber(StroomOpbrengst)
	local maandKosten      = dz.utils.round(jaarKosten / 12),2)
		
		
        logWrite("Kosten zijn: " .. maandKosten ) 
        
        -- Kosten updaten
        Totaalkosten.updateCustomSensor(tostring(maandKosten))
         
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Knibor
Posts: 112
Joined: Sunday 20 May 2018 12:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: NL
Contact:

Re: Offset Gas counter

Post by Knibor »

Thanks for the script.

I changed the line to

local maandKosten = dz.utils.round((jaarKosten / 12),2)

Yes it works!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest