Total value from P1 Gas to custom sensor

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

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:

Total value from P1 Gas to custom sensor

Post by Knibor »

Hi,

Is it possible to convert the value from P1 Gas "total counter" with value 21.558 to a virtual "General Custom"
Attachments
Schermafbeelding  gas.png
Schermafbeelding gas.png (31.75 KiB) Viewed 961 times
Schermafbeelding Gas3.png
Schermafbeelding Gas3.png (30.36 KiB) Viewed 961 times
Gravityz
Posts: 652
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: Total value from P1 Gas to custom sensor

Post by Gravityz »

modified the p1 meter script for gas

Code: Select all

local fetchIntervalMins = 1    -- (Integer) Minutes frequence of this script execution 1 = every minute, 10 = every 10 minutes, etc ) must be one of (1,2,3,4,5,6,10,12,15,20,30)
local ScriptVersion = '0.1.0'

return {

    on =      {
                        timer = { 'every ' .. fetchIntervalMins .. ' minutes' }
              },
    logging = {
                        -- level = domoticz.LOG_DEBUG,    -- Uncomment this line to override the dzVents global logging setting
                        
              },

    execute = function(domoticz, item)

    --  The following need updated for your environment get the 'Idx' or 'Name' of the Device tab.
        local P1data  = 282                                 -- Gas, P1 Smart Meter device
        local idxu1   = 290                                 -- Virtual gas meter device

        -- Get values from device P1Data of the Smart Meter
  local SMdata = domoticz.devices(P1data)
  
        local function updateCounter(idx,value)   
            domoticz.devices(idx).updateGas(value)

        end  
        updateCounter(idxu1,SMdata.counter)
     end 
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Total value from P1 Gas to custom sensor

Post by waaren »

Knibor wrote: Tuesday 28 May 2019 20:15 Hi,
@
Is it possible to convert the value from P1 Gas "total counter" with value 21.558 to a virtual "General Custom"
Sure but if I take the label literally and you only need the usage of the current year then you need to keep track of the usage of previous years which complicates it a bit (not much because you would have the script store that value in a domoticz variable).
Without that added complexity it could look as short as this.

Code: Select all

return {
         on = { timer = {'at *:19'}, -- at least once / hour at a quiet moment
        devices = {'Gas verbruik dit jaar'}}, -- and when the meter got updated
        
    execute = function( dz )
        local totalGas = dz.devices('Totaal Gasverbruik dit jaar')
        local gas = dz.devices('Gas verbruik dit jaar')
        
        totalGas.updateCustomSensor(gas.counter)
    end
}
@Gravityz , question was about updating a custom sensor. The method updateGas does not exist for such a sensor.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Gravityz
Posts: 652
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: Total value from P1 Gas to custom sensor

Post by Gravityz »

@waaren, clear. only looked at the icon :-)
Knibor
Posts: 112
Joined: Sunday 20 May 2018 12:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: NL
Contact:

Re: Total value from P1 Gas to custom sensor

Post by Knibor »

Hi, thanks for the script gentlemen, the last script works perfectly now.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest