P1 smart meter solar power not to the net

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

Moderator: leecollings

Post Reply
User avatar
HenkSynology
Posts: 21
Joined: Tuesday 12 March 2019 17:33
Target OS: Windows
Domoticz version: 1.13191
Location: Stadskanaal, NL
Contact:

P1 smart meter solar power not to the net

Post by HenkSynology »

I'm install viewtopic.php?f=59&t=22177 great script from McMellow
Does not want to pollute his topic, so i made a new one.

So i have Devices idxprod , thats the kWh what is going to the net.
I want indicate how much goes too the net.

I think i buy a barrel and heatpipes in the future.
And switch 6 solid state relay for heating elements

So i made my first dzVentz script , and i think with a lot off mistakes :oops:
-------------------------------------------------------------------------------------------------------------
return {
on = {
timer = {
'between 05:00 and 22:00'
},
devices = {
'idxprod'
},
},
execute = function(domoticz, idxprod)
if tonumber(idxprod) > 500 and Switch1.state == 'Off' then Switch1.switchOn()
elseif tonumber(idxprod) < 500 and Switch1.state == 'On' then Switch1.switchOff()

if tonumber(idxprod) > 1000 and Switch2.state == 'Off' then Switch2.switchOn()
elseif tonumber(idxprod) < 1000 and Switch2.state == 'On' then Switch2.switchOff()

if tonumber(idxprod) > 1500 and Switch3.state == 'Off' then Switch3.switchOn()
elseif tonumber(idxprod) < 1500 and Switch3.state == 'On' then Switch3.switchOff()

if tonumber(idxprod) > 2000 and Switch4.state == 'Off' then Switch4.switchOn()
elseif tonumber(idxprod) < 2000 and Switch4.state == 'On' then Switch4.switchOff()

if tonumber(idxprod) > 2500 and Switch5.state == 'Off' then Switch5.switchOn()
elseif tonumber(idxprod) < 2500 and Switch5.state == 'On' then Switch5.switchOff()

if tonumber(idxprod) > 3000 and Switch6.state == 'Off' then Switch6.switchOn()
elseif tonumber(idxprod) < 3000 and Switch6.state == 'On' then Switch6.switchOff()


end
}
-------------------------------------------------------------------------------------------------------------

Can anyone tune up my scripts ?

You would make me very happy with it
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: P1 smart meter solar power not to the net

Post by waaren »

HenkSynology wrote: Saturday 16 March 2019 18:05 So i have Devices idxprod , thats the kWh what is going to the net.
I want indicate how much goes too the net and switch 6 solid state relay for heating elements
Can anyone tune up my script ?
Could be something like:

Code: Select all

return {
    on = { devices = { ['idxprod'] = { 'between 05:00 and 22:00' }}},

    execute = function(dz,item)
        local toNet     = item.WhActual
        local stepSize  = 500
            
        for i = 1,6 do
            if toNet > (i * stepSize) then 
                dz.devices("Switch" .. i).switchOn().checkFirst()
            else 
                dz.devices("Switch" .. i).switchOff().checkFirst()
            end
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
HenkSynology
Posts: 21
Joined: Tuesday 12 March 2019 17:33
Target OS: Windows
Domoticz version: 1.13191
Location: Stadskanaal, NL
Contact:

Re: P1 smart meter solar power not to the net

Post by HenkSynology »

Hi Waaren ,

Thanks for the script Image
I try the short script Image

But it don't work.
How must i name the Switch ?
Switch1
Switch 1 (1x spatie)
Switch 1 (2x spatie)

Its in the afternoon so i change idxprod too idxcons
idxprod = produce to net
idxcon = consume from net
return {
on = { devices = { ['idxcons'] = { 'between 05:00 and 22:00' }}},

execute = function(dz,item)
local toNet = item.WhActual
local stepSize = 100

for i = 1,6 do
if toNet > (i * stepSize) then
dz.devices("Switch" .. i).switchOn().checkFirst()
else
dz.devices("Switch" .. i).switchOff().checkFirst()
end
end
end
}
this is the log
2019-03-17 16:52:32.150 (P1data) P1 Smart Meter (Power)
2019-03-17 16:52:42.262 (P1data) P1 Smart Meter (Power)
2019-03-17 16:52:52.385 (P1data) P1 Smart Meter (Power)
2019-03-17 16:53:00.446 Status: dzVents: Info: SME 0.1.5: ------ Start internal script: P1_extract:, trigger: every minute
2019-03-17 16:53:00.515 Status: dzVents: Info: SME 0.1.5: ------ Finished P1_extract
2019-03-17 16:53:00.822 Status: EventSystem: Script event triggered: /usr/local/domoticz/dzVents/runtime/dzVents.lua
2019-03-17 16:53:01.705 Status: dzVents: Info: Handling events for: "idxcons", value: "137"
2019-03-17 16:53:01.705 Status: dzVents: Info: ------ Start internal script: terugleveren: Device: "idxcons (P1data)", Index: 18
2019-03-17 16:53:01.705 Status: dzVents: Error (2.4.6): An error occured when calling event handler terugleveren
2019-03-17 16:53:01.705 Status: dzVents: Error (2.4.6): ...z/var/scripts/dzVents/generated_scripts/terugleveren.lua:9: attempt to compare number with nil
2019-03-17 16:53:01.705 Status: dzVents: Info: ------ Finished terugleveren
2019-03-17 16:53:01.706 Status: dzVents: Info: ------ Start internal script: terugleveren2: Device: "idxcons (P1data)", Index: 18
2019-03-17 16:53:01.706 Status: dzVents: Error (2.4.6): An error occured when calling event handler terugleveren2
2019-03-17 16:53:01.706 Status: dzVents: Error (2.4.6): .../var/scripts/dzVents/generated_scripts/terugleveren2.lua:6: attempt to compare number with table
2019-03-17 16:53:01.706 Status: dzVents: Info: ------ Finished terugleveren2
2019-03-17 16:53:02.510 (P1data) P1 Smart Meter (Power)
2019-03-17 16:53:02.522 (P1data) P1 Smart Meter (Gas)
2019-03-17 16:53:12.636 (P1data) P1 Smart Meter (Power)
Image
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: P1 smart meter solar power not to the net

Post by waaren »

HenkSynology wrote: Sunday 17 March 2019 16:55 How must i name the Switch ?
Switch1
Switch1, Switch2 etc. So without spaces.
I assumed your idxprod is a Electric usage device but the error message in your log tells met it is a different type / subtype.
Can you have a look at the devices tab and tell me the type / subtype you see there for this device ?
[/quote]
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
HenkSynology
Posts: 21
Joined: Tuesday 12 March 2019 17:33
Target OS: Windows
Domoticz version: 1.13191
Location: Stadskanaal, NL
Contact:

Re: P1 smart meter solar power not to the net

Post by HenkSynology »

Hello Waaren tHENKs for your help Image


I have DS115j synology and have installed domoticz there, that works fine.

have bought a P1 smart meter cable and install the script from McMelloW that works fine

Image

I made virtuel dummy's
Image

Great day for me , idxprod= solar deliver - usage so im put now 1,7kWh too the net
Image

I made 6 virtuel dummy switches , Switch1 Switch2 etc.
Image

This is my dashboard, the Switches don't Switch
Image

this is my script , so far.
I search a lot in the forum

Code: Select all

return {
	on = {
		devices = {
			'idxprod'
		}
	},
	execute = function(domoticz, device)
 local terug = idxprod

          if terug >= 100  then domoticz.devices('Switch1').switchOn().checkFirst()
            else domoticz.devices('Switch1').switchOff().checkFirst()
            end
       
    end
}
this is the logbook
Image

I search a lot and try different things, i know now idxprod is a value that comes out a table.
I can see the value in the log but cannot compare it Image

I have run two events my own and the P1 smart meter from McMelloW

I bought also a RFX but thats the next level
User avatar
HenkSynology
Posts: 21
Joined: Tuesday 12 March 2019 17:33
Target OS: Windows
Domoticz version: 1.13191
Location: Stadskanaal, NL
Contact:

Re: P1 smart meter solar power not to the net

Post by HenkSynology »

I thought I had the solution, but i didn't Image

I know now i compare a complete table , just searching further
User avatar
HenkSynology
Posts: 21
Joined: Tuesday 12 March 2019 17:33
Target OS: Windows
Domoticz version: 1.13191
Location: Stadskanaal, NL
Contact:

Re: P1 smart meter solar power not to the net

Post by HenkSynology »

I think i got it, when i use this script from McMellow
I change a little thing
I get a alarm attempt to compare number with string
But when i look in the log i see a number

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 = 5                             -- Electra, P1 Smart Meter device
local idxu1 = 14                                 -- Meter Usage low, Virtual device, counter incremental
local idxu2 = 15                                 -- Meter Usage High, Virtual device, counter incremental
local idxr1 = 16                                 -- Meter Return Low, Virtual device, counter incremental
local idxr2 = 17                                 -- Meter Return High, Virtual device, counter incremental
local idxcons = 18                              -- Meter Actual Usage, Virtual device, counter incremental
local idxprod = 19                              -- 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)
	    

	print ('Actuele verbruik = '.. SMdata[5])
	print ('Actuele levering = '.. SMdata[6]) 
	terug = (SMdata[6])
	print (terug)



	     if terug >= 100  then domoticz.devices('Switch1').switchOn().checkFirst()
            else domoticz.devices('Switch1').switchOff().checkFirst()
            end
    
end -- execute
2019-03-25 17:27:50.000 (P1data) P1 Smart Meter (Power)
2019-03-25 17:28:00.084 (P1data) P1 Smart Meter (Power)
2019-03-25 17:28:00.740 Status: dzVents: Info: SME 0.1.5: ------ Start internal script: P1_extract:, trigger: every minute
2019-03-25 17:28:00.808 Status: dzVents: Info: SME 0.1.5: ------ Finished P1_extract
2019-03-25 17:28:00.814 Status: dzVents: Info: SME 0.1.5: ------ Start internal script: terugleveren:, trigger: every minute
2019-03-25 17:28:00.815 Status: dzVents: Actuele verbruik = 529
2019-03-25 17:28:00.816 Status: dzVents: Actuele levering = 0
2019-03-25 17:28:00.816 Status: dzVents: 0

2019-03-25 17:28:00.816 Status: dzVents: Error (2.4.6): SME 0.1.5: An error occured when calling event handler terugleveren
2019-03-25 17:28:00.816 Status: dzVents: Error (2.4.6): SME 0.1.5: ...z/var/scripts/dzVents/generated_scripts/terugleveren.lua:53: attempt to compare number with string
2019-03-25 17:28:00.816 Status: dzVents: Info: SME 0.1.5: ------ Finished terugleveren
2019-03-25 17:28:01.276 Status: EventSystem: Script event triggered: /usr/local/domoticz/dzVents/runtime/dzVents.lua
2019-03-25 17:28:10.165 (P1data) P1 Smart Meter (Power)

But when i change this

print ('Actuele verbruik = '.. SMdata[5])
print ('Actuele levering = '.. SMdata[6])
terug = (SMdata[6])+1
print (terug)
Evry thing works oke :shock:

2019-03-25 17:32:52.191 (P1data) P1 Smart Meter (Power)
2019-03-25 17:33:00.407 Status: dzVents: Info: SME 0.1.5: ------ Start internal script: P1_extract:, trigger: every minute
2019-03-25 17:33:00.561 Status: dzVents: Info: SME 0.1.5: ------ Finished P1_extract
2019-03-25 17:33:00.561 Status: dzVents: Info: SME 0.1.5: ------ Start internal script: terugleveren:, trigger: every minute
2019-03-25 17:33:00.562 Status: dzVents: Actuele verbruik = 450
2019-03-25 17:33:00.563 Status: dzVents: Actuele levering = 0
2019-03-25 17:33:00.563 Status: dzVents: 1
2019-03-25 17:33:00.566 Status: dzVents: Info: SME 0.1.5: ------ Finished terugleveren
2019-03-25 17:33:02.311 (P1data) P1 Smart Meter (Power)
User avatar
HenkSynology
Posts: 21
Joined: Tuesday 12 March 2019 17:33
Target OS: Windows
Domoticz version: 1.13191
Location: Stadskanaal, NL
Contact:

Re: P1 smart meter solar power not to the net

Post by HenkSynology »

Now i can see what i really put into the net
Switch1 = high , i put back 500W
Switch2 = high , i put back 1000W
Switch3 = high , i put back 1500W
Switch4 = high , i put back 2000W
Switch5 = high , i put back 2500W
Switch6 = high , i put back 3000W
next level is put the energie into something at home


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 = 5                             -- Electra, P1 Smart Meter device
local idxu1 = 14                                 -- Meter Usage low, Virtual device, counter incremental
local idxu2 = 15                                 -- Meter Usage High, Virtual device, counter incremental
local idxr1 = 16                                 -- Meter Return Low, Virtual device, counter incremental
local idxr2 = 17                                 -- Meter Return High, Virtual device, counter incremental
local idxcons = 18                              -- Meter Actual Usage, Virtual device, counter incremental
local idxprod = 19                              -- 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)
	    

	print ('Actuele verbruik = '.. SMdata[5])
	print ('Actuele levering = '.. SMdata[6]) 
	terug = (SMdata[6])+1
	print (terug)



	     if terug >= 500  then domoticz.devices('Switch1').switchOn().checkFirst()
            else domoticz.devices('Switch1').switchOff().checkFirst()
            end
            
              if terug >= 1000  then domoticz.devices('Switch2').switchOn().checkFirst()
            else domoticz.devices('Switch2').switchOff().checkFirst()
            end
            
              if terug >= 1500  then domoticz.devices('Switch3').switchOn().checkFirst()
            else domoticz.devices('Switch3').switchOff().checkFirst()
            end
            
              if terug >= 2000  then domoticz.devices('Switch4').switchOn().checkFirst()
            else domoticz.devices('Switch4').switchOff().checkFirst()
            end
            
              if terug >= 2500  then domoticz.devices('Switch5').switchOn().checkFirst()
            else domoticz.devices('Switch5').switchOff().checkFirst()
            end
            
              if terug >= 3000  then domoticz.devices('Switch6').switchOn().checkFirst()
            else domoticz.devices('Switch6').switchOff().checkFirst()
            end
            
        
    
end -- execute

}
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest