Script to parse Electricity form P1 Smart Meter reading

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

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.log('Gebruik laag  = '.. SMdata[1], domoticz.LOG_DEBUG)
	    domoticz.log('Gebruik hoog  = '.. SMdata[2], domoticz.LOG_DEBUG)
    	    domoticz.log('Levering laag = '.. SMdata[3], domoticz.LOG_DEBUG)
	    domoticz.log('Levering hoog = '.. SMdata[4], domoticz.LOG_DEBUG)
    	    domoticz.log('Actuele verbruik = '.. SMdata[5], domoticz.LOG_DEBUG)
	    domoticz.log('Actuele levering = '.. SMdata[6], domoticz.LOG_DEBUG)
    end -- execute
Comments and improvements are welcome
Greetings McMelloW

Post Reply

Who is online

Users browsing this forum: Doler and 7 guests