Page 2 of 4

Re: Script to parse Electricity form P1 Smart Meter reading

Posted: Friday 21 June 2019 11:20
by waaren
competer wrote: Friday 21 June 2019 9:40 I migrated my domoticz from Synology to a Rapsberry Pi model 3 B+
Whos can help resolving this
Based on the screenprint and log I cannot see any reason why the script produced this error.
Can you try to change the 93 to the name of the device (with surrounding quotes) ?

If that does not work please run the attached script. It should show you what dzVents thinks your devices are.

Code: Select all

--  dzVents script to dump device names etc
return {
    on = { timer = { 'every minute' }},
              
    execute = function(dz)
      dz.devices().forEach(function(dv)
        if dv.id then
          print(string.format("%-4d%3s%-30s%-20s%-20s%-60s", dv.id, " = ",(dv.name or 'nil' ),(dv.deviceType or 'nil'),dv.deviceSubType or 'nil',table.concat(dv._adapters,", ")))
        end
      end)
   end 
}

Re: Script to parse Electricity form P1 Smart Meter reading

Posted: Friday 21 June 2019 13:12
by competer
i found a error in the script,

Changed line 42 and 43

updateCounter(idcons,SMdata.usage)
updateCounter(idprod,SMdata.usageDelivered)
to
updateCounter(idxcons,SMdata.usage)
updateCounter(idxprod,SMdata.usageDelivered)

Now it is working perfectly

Code: Select all

--  dzVents script to Parse P1 Smart Meter Electricity value into separate Meter Readings.

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.8'

return {

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


    execute = function(dz, item)

    --  The following need updated for your environment get the 'Idx' or 'Name' of the Device tab.
        local P1data  = 93                                 -- Electra, P1 Smart Meter device
        local idxu1   = 43                                 -- Meter Usage low, Virtual device, counter incremental
        local idxu2   = 44                                 -- Meter Usage High, Virtual device, counter incremental
        local idxr1   = 45                                 -- Meter Return Low, Virtual device, counter incremental
        local idxr2   = 46                                 -- Meter Return High, Virtual device, counter incremental
        local idxcons = 103                                -- Meter Actual Usage, Virtual device, counter incremental
        local idxprod = 104                                -- Meter Actual Production, Virtual device, counter incremental
        
        -- Get values from device P1Data of the Smart Meter
        local SMdata = dz.devices(P1data)
  
        local function updateCounter(idx,value)   
            dz.devices(idx).updateCounter(value)
            dz.log("Set " .. dz.devices(idx).name .. " to: ",dz.LOG_DEBUG)
        end  

        -- Update the device and Debug meassages with the accessory values from table SMdata
        updateCounter(idxu1,SMdata.usage1)
        updateCounter(idxu2,SMdata.usage2)
        updateCounter(idxr1,SMdata.return1)
        updateCounter(idxr2,SMdata.return2)
        updateCounter(idxcons,SMdata.usage)
        updateCounter(idxprod,SMdata.usageDelivered)
    end 
}
}

Re: Script to parse Electricity form P1 Smart Meter reading

Posted: Friday 21 June 2019 13:34
by waaren
competer wrote: Friday 21 June 2019 13:12 ..Now it is working perfectly
Good te read it is working now !
What did you change to get rid of the first error ?

Code: Select all

2019-06-21 09:31:00.436 Error: dzVents: Error: (2.4.23) SME 0.1.7: There is no device with that name or id: 93

Re: Script to parse Electricity form P1 Smart Meter reading

Posted: Friday 26 July 2019 8:51
by Ragelink
Thanks for the script. Recently we have got a smart meter ( 3 phase version). The smart meter has been connectend by USB cable to my PI and is working fine. However I think the message Telegram of the 3 phase meter is different that the meter used within the script. Does this make sense? No data has been loaded into the variables. Is usage 1 and usage 2 also valid for this type of smart meter?

Hope someone kan help me on this quest :)

Re: Script to parse Electricity form P1 Smart Meter reading

Posted: Friday 26 July 2019 9:20
by waaren
Ragelink wrote: Friday 26 July 2019 8:51 Recently we have got a smart meter ( 3 phase version). The smart meter has been connectend by USB cable to my PI and is working fine. However I think the message Telegram of the 3 phase meter is different that the meter used within the script. No data has been loaded into the variables. Is usage 1 and usage 2 also valid for this type of smart meter?

Hope someone kan help me on this quest :)
The processing of the message Telegram of the 3 phase meter is done by the domoticz hardware thread. Last time I checked the phases are combined and won't be read separately.
This script does take it's information from the domoticz P1 device so it is not aware or influenced directly by the information in the Telegram.

What do you see in the log ?

Re: Script to parse Electricity form P1 Smart Meter reading

Posted: Friday 26 July 2019 11:40
by Ragelink
Hi,
Thanks for your quick respons!
019-07-26 11:39:00.593 Status: dzVents: Info: SME 0.1.7: ------ Start internal script: P1 meter script:, trigger: every 1 minutes
2019-07-26 11:39:00.614 Status: dzVents: Debug: SME 0.1.7: Processing device-adapter for Stroom huis: P1 smart meter energy device adapter
2019-07-26 11:39:00.616 Status: dzVents: Debug: SME 0.1.7: Processing device-adapter for Verbruik Laag: Counter device adapter
2019-07-26 11:39:00.616 Status: dzVents: Debug: SME 0.1.7: Set Verbruik Laag to:
2019-07-26 11:39:00.617 Status: dzVents: Debug: SME 0.1.7: Processing device-adapter for Verbruik Hoog: Counter device adapter
2019-07-26 11:39:00.618 Status: dzVents: Debug: SME 0.1.7: Set Verbruik Hoog to:
2019-07-26 11:39:00.619 Status: dzVents: Debug: SME 0.1.7: Processing device-adapter for Levering Laag: Counter device adapter
2019-07-26 11:39:00.619 Status: dzVents: Debug: SME 0.1.7: Set Levering Laag to:
2019-07-26 11:39:00.620 Status: dzVents: Debug: SME 0.1.7: Processing device-adapter for Levering Hoog: Counter device adapter
2019-07-26 11:39:00.621 Status: dzVents: Debug: SME 0.1.7: Set Levering Hoog to:
2019-07-26 11:39:00.621 Status: dzVents: Error (2.4.19): SME 0.1.7: An error occured when calling event handler P1 meter script
2019-07-26 11:39:00.621 Status: dzVents: Error (2.4.19): SME 0.1.7: ...cz/scripts/dzVents/generated_scripts/P1 meter script.lua:33: attempt to call field 'updateCounter' (a nil value)
2019-07-26 11:39:00.622 Status: dzVents: Info: SME 0.1.7: ------ Finished P1 meter script
Spoiler: show
-- dzVents script to Parse P1 Smart Meter Electricity value into separate Meter Readings.

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.7'

return {

on = {
timer = { 'every ' .. fetchIntervalMins .. ' minutes' }
},

logging = {
level = domoticz.LOG_DEBUG, -- Uncomment this line to override the dzVents global logging setting
marker = 'SME '.. ScriptVersion
},


execute = function(dz, item)

-- The following need updated for your environment get the 'Idx' or 'Name' of the Device tab.
local P1data = 70 -- Electra, P1 Smart Meter device
local idxu1 = 80 -- Meter Usage low, Virtual device, counter incremental
local idxu2 = 81 -- Meter Usage High, Virtual device, counter incremental
local idxr1 = 82 -- Meter Return Low, Virtual device, counter incremental
local idxr2 = 83 -- Meter Return High, Virtual device, counter incremental
local idxcons = 84 -- Meter Actual Usage, Virtual device, counter incremental
local idxprod = 85 -- Meter Actual Production, Virtual device, counter incremental

-- Get values from device P1Data of the Smart Meter
local SMdata = dz.devices(P1data)

local function updateCounter(idx,value)
dz.devices(idx).updateCounter(value)
dz.log("Set " .. dz.devices(idx).name .. " to: ",dz.LOG_DEBUG)
end

-- Update the device and Debug meassages with the accessory values from table SMdata
updateCounter(idxu1,SMdata.usage1)
updateCounter(idxu2,SMdata.usage2)
updateCounter(idxr1,SMdata.return1)
updateCounter(idxr2,SMdata.return2)
updateCounter(idcons,SMdata.usage)
updateCounter(idprod,SMdata.usageDelivered)
end
}

Re: Script to parse Electricity form P1 Smart Meter reading

Posted: Friday 26 July 2019 11:51
by Ragelink
Virtual devices are type : General and sub type: Counter Incremental

Re: Script to parse Electricity form P1 Smart Meter reading

Posted: Friday 26 July 2019 12:46
by waaren
Ragelink wrote: Friday 26 July 2019 11:40 2019-07-26 11:39:00.621 Status: dzVents: Error (2.4.19): SME 0.1.7: ...cz/scripts/dzVents/generated_scripts/P1 meter script.lua:33: attempt to call field 'updateCounter' (a nil value)
2019-07-26 11:39:00.622 Status: dzVents: Info: SME 0.1.7: ------ Finished P1 meter script
The error message tells the idxcons device ID does not point to a counter incremental device
Please replace function updateCounter with this one. (It will give some additional information on what goes wrong)

Code: Select all

        local function updateCounter(idx,value)
            local dv 
            if dz.devices(idx) then dv = dz.devices(idx) end 
            if dv then 
                if dv.deviceSubType ==  "Counter Incremental" then
                   dv.updateCounter(value)
                   dz.log("Set " .. dv.name .. " to: " .. value,dz.LOG_DEBUG)
                else
                  dz.log("Wrong device (sub)type ==>> Failed to set " .. 
                        (dv.name or 'nil') .. " (" .. ( dv.deviceType or '-')  .. "," .. 
                        (dv.deviceSubType or '') .. ") to: " .. value,dz.LOG_ERROR)
                end
            else
                dz.log("Device with idx " .. idx .. " does not exist",dz.LOG_ERROR)
            end
        end  

Re: Script to parse Electricity form P1 Smart Meter reading

Posted: Friday 26 July 2019 13:00
by Ragelink
2019-07-26 12:56:00.496 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2019-07-26 12:56:07.169 Status: EventSystem: reset all events...
2019-07-26 12:56:07.170 Status: dzVents: Write file: /home/pi/domoticz/scripts/dzVents/generated_scripts/Volvo Lader.lua
2019-07-26 12:56:07.171 Status: dzVents: Write file: /home/pi/domoticz/scripts/dzVents/generated_scripts/P1 meter script.lua
2019-07-26 12:57:00.485 Status: dzVents: Info: SME 0.1.7: ------ Start internal script: P1 meter script:, trigger: every 1 minutes
2019-07-26 12:57:00.505 Status: dzVents: Debug: SME 0.1.7: Processing device-adapter for Stroom huis: P1 smart meter energy device adapter
2019-07-26 12:57:00.507 Status: dzVents: Debug: SME 0.1.7: Processing device-adapter for Verbruik Laag: Counter device adapter
2019-07-26 12:57:00.508 Status: dzVents: Debug: SME 0.1.7: Set Verbruik Laag to: 461852
2019-07-26 12:57:00.511 Status: dzVents: Debug: SME 0.1.7: Processing device-adapter for Verbruik Hoog: Counter device adapter
2019-07-26 12:57:00.512 Status: dzVents: Debug: SME 0.1.7: Set Verbruik Hoog to: 0
2019-07-26 12:57:00.514 Status: dzVents: Debug: SME 0.1.7: Processing device-adapter for Levering Laag: Counter device adapter
2019-07-26 12:57:00.516 Status: dzVents: Debug: SME 0.1.7: Set Levering Laag to: 0
2019-07-26 12:57:00.518 Status: dzVents: Debug: SME 0.1.7: Processing device-adapter for Levering Hoog: Counter device adapter
2019-07-26 12:57:00.519 Status: dzVents: Debug: SME 0.1.7: Set Levering Hoog to: 0
2019-07-26 12:57:00.521 Status: dzVents: Error (2.4.19): SME 0.1.7: Wrong device (sub)type ==>> Failed to set nil (-,) to: 1291
2019-07-26 12:57:00.522 Status: dzVents: Error (2.4.19): SME 0.1.7: Wrong device (sub)type ==>> Failed to set nil (-,) to: 0
2019-07-26 12:57:00.523 Status: dzVents: Info: SME 0.1.7: ------ Finished P1 meter script

The " verbruik Laag" value is equal to the Total KWH showed on the meter and 1291 value is the current usage
Image

Re: Script to parse Electricity form P1 Smart Meter reading

Posted: Friday 26 July 2019 13:29
by waaren
Ragelink wrote: Friday 26 July 2019 13:00 2019-07-26 12:57:00.521 Status: dzVents: Error (2.4.19): SME 0.1.7: Wrong device (sub)type ==>> Failed to set nil (-,) to: 1291
2019-07-26 12:57:00.522 Status: dzVents: Error (2.4.19): SME 0.1.7: Wrong device (sub)type ==>> Failed to set nil (-,) to: 0
change

Code: Select all

updateCounter(idcons,SMdata.usage)
updateCounter(idprod,SMdata.usageDelivered)
to

Code: Select all

updateCounter(idxcons,SMdata.usage)
updateCounter(idxprod,SMdata.usageDelivered)

Re: Script to parse Electricity form P1 Smart Meter reading

Posted: Friday 26 July 2019 13:42
by Ragelink
No Errors anymore, but the data make no sense. Still the Verbruik Laag is " totaal Kwh van de meter"
actueel verbruik is however now correct

2019-07-26 13:40:00.403 Status: dzVents: Info: SME 0.1.7: ------ Start internal script: P1 meter script:, trigger: every 1 minutes
2019-07-26 13:40:00.421 Status: dzVents: Debug: SME 0.1.7: Processing device-adapter for Stroom huis: P1 smart meter energy device adapter
2019-07-26 13:40:00.423 Status: dzVents: Debug: SME 0.1.7: Processing device-adapter for Verbruik Laag: Counter device adapter
2019-07-26 13:40:00.423 Status: dzVents: Debug: SME 0.1.7: Set Verbruik Laag to: 462788
2019-07-26 13:40:00.424 Status: dzVents: Debug: SME 0.1.7: Processing device-adapter for Verbruik Hoog: Counter device adapter
2019-07-26 13:40:00.424 Status: dzVents: Debug: SME 0.1.7: Set Verbruik Hoog to: 0
2019-07-26 13:40:00.425 Status: dzVents: Debug: SME 0.1.7: Processing device-adapter for Levering Laag: Counter device adapter
2019-07-26 13:40:00.426 Status: dzVents: Debug: SME 0.1.7: Set Levering Laag to: 0
2019-07-26 13:40:00.427 Status: dzVents: Debug: SME 0.1.7: Processing device-adapter for Levering Hoog: Counter device adapter
2019-07-26 13:40:00.427 Status: dzVents: Debug: SME 0.1.7: Set Levering Hoog to: 0
2019-07-26 13:40:00.428 Status: dzVents: Debug: SME 0.1.7: Processing device-adapter for Actueel Verbruik: Counter device adapter
2019-07-26 13:40:00.428 Status: dzVents: Debug: SME 0.1.7: Set Actueel Verbruik to: 1331
2019-07-26 13:40:00.429 Status: dzVents: Debug: SME 0.1.7: Processing device-adapter for Actueel Levering: Counter device adapter
2019-07-26 13:40:00.430 Status: dzVents: Debug: SME 0.1.7: Set Actueel Levering to: 0
2019-07-26 13:40:00.430 Status: dzVents: Info: SME 0.1.7: ------ Finished P1 meter script

Re: Script to parse Electricity form P1 Smart Meter reading

Posted: Friday 26 July 2019 16:10
by waaren
Ragelink wrote: Friday 26 July 2019 13:42 No Errors anymore, but the data make no sense. Still the Verbruik Laag is " totaal Kwh van de meter"
actueel verbruik is however now correct
That is what this value is. Do you expect something else ?

Re: Script to parse Electricity form P1 Smart Meter reading

Posted: Friday 26 July 2019 19:52
by Ragelink
Maybe not 😬 many Thanks for your support

Re: Script to parse Electricity form P1 Smart Meter reading

Posted: Friday 26 July 2019 19:53
by Ragelink
Maybe not 😬 many Thanks for your support

Re: Script to parse Electricity form P1 Smart Meter reading

Posted: Saturday 27 July 2019 20:15
by DRB2019
I also have been playing with the script and modified it a little bit.
The goal was also to get the actual reading from the Gas.
I know that the reading is on one of the boxes under the utility section, but when i set this to favourite the reading is not shown
on the dashboard.

I started to make one new Dummy on the hardware tab, and then created 3 new devices, all
from type General and subtype Counter Incremental.

Below a screenshot how it looks on the utility tab.
Snap1.jpg
Snap1.jpg (238.17 KiB) Viewed 8071 times
Below a screenshot how it looks on the dashboard
Snap2.jpg
Snap2.jpg (192.73 KiB) Viewed 8071 times
I can't get the value of the gas meter.
I also noticed that the values on Electra 1.8.1. an 1.8.2 are not displayed in the same way.

Below the dzvent script i use.
any help would be very welcome !

Code: Select all

--  dzVents script to Parse P1 Smart Meter Electricity value into separate Meter Readings.

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.7'

return {

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


    execute = function(dz, item)

    --  The following need updated for your environment get the 'Idx' or 'Name' of the Device tab.
        local P1data  = 32         -- Electra, P1 Smart Meter device
        local idxu1   = 36         -- Meter Reading Low 1.8.1, Virtual device, counter incremental
        local idxu2   = 37         -- Meter Reading High 1.8.2, Virtual device, counter incremental

        local P1gas   = 35         -- Gas, P1 Smart Meter Device
        local gasu1   = 38         -- Gas Reading, Vitrual device, counter incremental
        
    --    local idxr1   = 44       -- Meter Return Low, Virtual device, counter incremental
    --    local idxr2   = 45       -- Meter Return High, Virtual device, counter incremental
    --    local idxcons = 74       -- Meter Actual Usage, Virtual device, counter incremental
    --    local idxprod = 75       -- Meter Actual Production, Virtual device, counter incremental
        
        -- Get values from device P1Data of the Smart Meter
        local SMdata = dz.devices(P1data)
        local SMgas = dz.devices(P1gas)
  
        local function updateCounter(idx,value)   
            dz.devices(idx).updateCounter(value)
            dz.log("Set " .. dz.devices(idx).name .. " to: ",dz.LOG_DEBUG)
        end  

        -- Update the device and Debug messages with the accessory values from table SMdata and SMgas
        updateCounter(idxu1,SMdata.usage1)
        updateCounter(idxu2,SMdata.usage2)--2
        updateCounter(gasu1,SMgas.usage1)
        --updateCounter(idxr1,SMdata.return1)
        --updateCounter(idxr2,SMdata.return2)
        --updateCounter(idxcons,SMdata.usage)
        --updateCounter(idxprod,SMdata.usageDelivered)
    end 
}

Re: Script to parse Electricity form P1 Smart Meter reading

Posted: Saturday 27 July 2019 21:03
by waaren
DRB2019 wrote: Saturday 27 July 2019 20:15 I also have been playing with the script and modified it a little bit. goal was also to get the actual reading from the Gas.
Lets try this step by step to keep it simple. Below script should update an incremental counter device every minute with current reading from a P1 gasmeter.

Code: Select all

return {

    on =      { timer = { 'every minute' }},

    execute = function(dz )

        local P1gas = dz.devices(35) -- Gas, P1 Smart Meter Device
        local CounterIncrementalGas = dz.devices(38) -- Gas Reading, Virtual device, counter incremental
        
        CounterIncrementalGas.updateCounter(P1gas.counter)
    end 
}

Re: Script to parse Electricity form P1 Smart Meter reading

Posted: Saturday 27 July 2019 21:44
by DRB2019
Lets try this step by step to keep it simple. Below script should update an incremental counter device every minute with current reading from a P1 gasmeter.

The script works !
Next step to implement this into the 0.1.7 script?

But the reading is in Kwh

Re: Script to parse Electricity form P1 Smart Meter reading  [Solved]

Posted: Sunday 28 July 2019 0:07
by waaren
DRB2019 wrote: Saturday 27 July 2019 21:44 But the reading is in Kwh
On the Utility tab press the Edit button of your virtual device. Use Type Gas and counter divider 1
Next step to implement this into the 0.1.7 script?
Next step to implement this into the 0.1.7 script?
First try to do something similar for Energy

Code: Select all

return {

    on =      { timer = { 'every minute' }},

    execute = function(dz )

    --  The following need updated for your environment get the 'Idx' or 'Name' of the Device tab.
        local P1 = dz.devices(32) -- Electra, P1 Smart Meter device
        
        local returnLow = dz.devices(44)     -- Meter Return Low, Virtual device, counter incremental
        local returnHigh = dz.devices(45)    -- Meter Return High, Virtual device, counter incremental
        local consume = dz.devices(74)      -- Meter Actual Usage, Virtual device, counter incremental
        local produce = dz.devices(75)      -- Meter Actual Production, Virtual device, counter incremental
        
        returnLow.updateCounter(P1.return1)
        returnHigh.updateCounter(P1.return2)
        consume.updateCounter(P1.usage)
        produce.updateCounter(P1.usageDelivered)
     
    end 
}
and if that works combine the two and add functionality to check if update is needed

Code: Select all

--  Parse P1 Smart Meter Electricity value into separate Meter Readings (target devices of type (incremental) counter.
return {

    on = { timer = { 'every 5 minutes' }},
    
    logging = { level = domoticz.LOG_DEBUG,    -- change to domomticz.LOG_ERROR when all OK
                marker = 'SME 0.2',
              },

    execute = function(dz )

    --  The following need updated for your environment get the 'Idx' or 'Name' of the Device tab.
        local P1 = dz.devices(32) -- Electra, P1 Smart Meter device (= source)
        local P1gas = dz.devices(35) -- Gas, P1 Smart Meter Device (= source)

        local returnLow = dz.devices(44)     -- Meter Return Low, Virtual device, counter incremental
        local returnHigh = dz.devices(45)    -- Meter Return High, Virtual device, counter incremental
        local consume = dz.devices(74)      -- Meter Actual Usage, Virtual device, counter incremental
        local produce = dz.devices(75)      -- Meter Actual Production, Virtual device, counter incremental
        local gas = dz.devices(38) -- Gas Reading, Virtual device, counter incremental
                
        local function controledUpdate( device, value, maxTime)
            local timeOut = maxTime or 60
            local cValue = tonumber(device.sValue or device.rawData[1]) -- sValue available in dzVents version > 2.4.21
            if (cValue ~= value) or (device.lastUpdate.minutesAgo > timeOut) then
                device.updateCounter(value)
                dz.log(device.name .. ' (' .. cValue .. ') Updated with ' .. value ,dz.LOG_DEBUG)
            else
                dz.log('No update required for ' .. device.name,dz.LOG_DEBUG)
            end
        end
        
        controledUpdate(returnLow,P1.return1)
        controledUpdate(returnHigh,P1.return2)
        controledUpdate(consume,P1.usage)
        controledUpdate(produce,P1.usageDelivered)
        controledUpdate(gas,P1gas.counter)
    end 
}

Re: Script to parse Electricity form P1 Smart Meter reading

Posted: Sunday 28 July 2019 12:53
by DRB2019
On the Utility tab press the Edit button of your virtual device. Use Type Gas and counter divider 1
That did almost the trick. The reading is now in m3, but there is nothing to see in the upper right corner.
Snap4.jpg
Snap4.jpg (62.82 KiB) Viewed 8034 times
I merged the script into one but i had to make a few small changes to get the reading i wanted.
I changed return into usage1 and usage2.
Below the script that is running now without errors, only the one mentioned above.

I'am also not running the dzvents version you named in the script.
I run:
Domoticz Version: 4.10717
Build Hash: b38b49e5
Compile Date: 2019-05-09 13:04:08
dzVents Version: 2.4.19

We are getting close to solve this :D :D

Code: Select all

--  Parse P1 Smart Meter Electricity value into separate Meter Readings (target devices of type (incremental) counter.
return {

    on =      { timer = { 'every minute' }},
    
    logging = { level = domoticz.LOG_DEBUG,    -- change to domomticz.LOG_ERROR when all OK
                marker = 'SME 0.2',
              },

    execute = function(dz )

    --  The following need updated for your environment get the 'Idx' or 'Name' of the Device tab.
        local P1 = dz.devices(32) -- Electra, P1 Smart Meter device (= source)
        local P1gas = dz.devices(35) -- Gas, P1 Smart Meter Device (= source)
        
        local usageLow = dz.devices(36)     -- Meter Usage Low, Virtual device, counter incremental
        local usageHigh = dz.devices(37)    -- Meter Usage High, Virtual device, counter incremental
        local consume = dz.devices(33)       -- Meter Actual Usage, Virtual device, counter incremental
        --local produce = dz.devices(75)     -- Meter Actual Production, Virtual device, counter incremental
        local gas = dz.devices(38)           -- Gas Reading, Virtual device, counter incremental
        
        local function controledUpdate( device, value, maxTime)
            local timeOut = maxTime or 60
            local cValue = tonumber(device.sValue or device.rawData[1]) -- sValue available in dzVents version > 2.4.21
            if (cValue ~= value) or (device.lastUpdate.minutesAgo > timeOut) then
                device.updateCounter(value)
                dz.log(device.name .. ' (' .. cValue .. ') Updated with ' .. value ,dz.LOG_DEBUG)
            else
                dz.log('No update required for ' .. device.name,dz.LOG_DEBUG)
            end
        end
   
        controledUpdate(usageLow,P1.usage1)
        controledUpdate(usageHigh,P1.usage2)
        controledUpdate(consume,P1.usage)
        --controledUpdate(produce,P1.usageDelivered)
        controledUpdate(gas,P1gas.counter)
    end 
}
Below the screenshot how it looks now on the dashboard.
Snap5.jpg
Snap5.jpg (148.01 KiB) Viewed 8034 times

Re: Script to parse Electricity form P1 Smart Meter reading

Posted: Tuesday 17 September 2019 7:31
by Derik
Dear developer..
Something look wrong..
ScreenShot004.png
ScreenShot004.png (169.7 KiB) Viewed 6626 times
For a week very big usage etc..
So perhaps something i can change???

I did not set anything else to other value, only update domoticz...