Script to parse Electricity form P1 Smart Meter reading

Easy to use, 100% Lua-based event scripting framework.
Post Reply
User avatar
McMelloW
Posts: 195
Joined: Monday 20 November 2017 18:01
Target OS: Raspberry Pi
Domoticz version: V3.beta
Location: Harderwijk, NL
Contact:

Script to parse Electricity form P1 Smart Meter reading

Post by McMelloW » Tuesday 13 February 2018 15:47

The P1 Smart Meter with an USB connection cable hardware, creates a device with 6 different meter reading. Usage Low; Usage High; production Low; Production High; Consumption and Production. I wanted to see the readings in 6 different devices.
There is a lua-script that does this trick, but was not really happy with it. So, I decided to wrote a new one in dzVents. In fact, a script in dzVents is much more simple to write then Lua. Six vitual devices type Counter Incremental are created for the different values

The script is very straight forward. The values are fetchted from the P1 Smart Meter device (P1data) and put in a table (SMdata) in a fixed order. Then just update the devices with the accessory values from the table. That's all you have to do.

Code: Select all

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

]]--  The following need updated for your environment get the 'Idx' or 'Name' of the Device tab.

local fetchIntervalMins = 1                 -- (Integer) (Minutes, Range 5-60) How often SE file is fetched
local P1data = 33                               -- Electra, P1 Smart Meter device
local idxu1 = 42                                 -- Meter Usage low, Virtual device, counter incremental
local idxu2 = 43                                 -- Meter Usage High, Virtual 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

local ScriptVersion = '0.1.5'

return {
    active = true,
	logging = {
	    -- level = domoticz.LOG_DEBUG,    -- Uncomment this line to override the dzVents global logging setting
		marker = 'SME '.. ScriptVersion
	},
	on = {
		timer = { 'every minute' }
	},
	
	execute = function(domoticz, device)
	          
            -- Get values from device P1Data of the Smart Meter
    	    local SMdata = domoticz.devices(P1data).rawData
    	    
    	    -- Update the device and Debug meassages with the accessory values from table SMdata
            domoticz.devices(idxu1).updateCounter(SMdata[1])
            domoticz.log('Gebruik laag  = '.. SMdata[1], domoticz.LOG_DEBUG)
            domoticz.devices(idxu2).updateCounter(SMdata[2])
	    domoticz.log('Gebruik hoog  = '.. SMdata[2], domoticz.LOG_DEBUG)
            domoticz.devices(idxr1).updateCounter(SMdata[3])
    	    domoticz.log('Levering laag = '.. SMdata[3], domoticz.LOG_DEBUG)
            domoticz.devices(idxr2).updateCounter(SMdata[4])
	    domoticz.log('Levering hoog = '.. SMdata[4], domoticz.LOG_DEBUG)
	    domoticz.devices(idxcons).updateCounter(SMdata[5])
    	    domoticz.log('Actuele verbruik = '.. SMdata[5], domoticz.LOG_DEBUG)
    	    domoticz.devices(idxprod).updateCounter(SMdata[6])
	    domoticz.log('Actuele levering = '.. SMdata[6], domoticz.LOG_DEBUG)
    
    end -- execute
}
Comments and improvements are welcome
Greetings McMelloW

Gravityz
Posts: 272
Joined: Wednesday 16 December 2015 20:13
Target OS: NAS (Synology & others)
Domoticz version: V3.8637
Location: Netherlands
Contact:

Re: Script to parse Electricity form P1 Smart Meter reading

Post by Gravityz » Monday 01 October 2018 19:49

thanks for this(and unbelievable nobody thanked you for this)

i only use it to see the low and high actual meter values of the meter.
total production is already in the real P1 meter device

User avatar
McMelloW
Posts: 195
Joined: Monday 20 November 2017 18:01
Target OS: Raspberry Pi
Domoticz version: V3.beta
Location: Harderwijk, NL
Contact:

Re: Script to parse Electricity form P1 Smart Meter reading

Post by McMelloW » Tuesday 02 October 2018 22:58

Thanks very much.
Greetings McMelloW

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests