Help with some scripting with the P1

Post Reply
User avatar
Derik
Posts: 1890
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Help with some scripting with the P1

Post by Derik » Monday 13 November 2017 21:08

Dear all..
Is there some one that can make dzvent working for my P1 actual
I try to get a script for my P1, when i deliver back to to the net, with my solar panels.

With blockley i cannot go to minus..

So what i an looking for:
When time is between x and y
when p1 actual is -500 and dummy X is off, switch dummy X on.
when p1 actual is >500 and dummy X is on, switch dummy off

Only i do not understand the dzvents script..
So hope someone help me.
xxx


I get the first reaction from emme:

uhm.. let's try:
:

Code: Select all

return {
	on = {
		timer = {
			'between x and y'
		},
		devices = {
			'P1'
		},
	},
	execute = function(domoticz, devP1)
	    local dummy = domoticz.devices('dummy')
		if tonumber(devP1.rawData[1]) > 500 and dummy.state == 'Off' then 
		    dummy.switchOn()
		elseif tonumber(devP1.rawData[1]) < -500 and dummy.state == 'On' then 
		    dummy.switchOff()
		end 
	end
}
I'm using rawData since I'm unsure what kind of device P1 is :P :P ciao M

P.S.
we can clean the code by not chasing the dummy switch state:
CODE:

Code: Select all

if tonumber(devP1.rawData[1]) > 500 then 
		    dummy.switchOn().checkFirst()
		elseif tonumber(devP1.rawData[1]) < -500  then 
		    dummy.switchOff().checkFirst()
		end
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups

User avatar
Derik
Posts: 1890
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Help with some scripting with the P1

Post by Derik » Monday 13 November 2017 21:39

Do have now:
https://drive.google.com/file/d/1PBCj8P ... sp=sharing
And this my P1:
https://drive.google.com/file/d/1sBuL6o ... sp=sharing
With the data of the P1:
https://drive.google.com/file/d/1i3LG5E ... sp=sharing

And the code i did change: [ Hope did this ok..:-) ]

Code: Select all

return {
	on = {
		timer = {
			'between 08:00 and 22:00'
		},
		devices = {
			'D.M. P1: Stroom'
		},
	},
	execute = function(domoticz, devP1)
	    local dummy = domoticz.devices('Dummy P1')
		if tonumber(devP1.rawData[1]) > 500 and dummy.state == 'Off' then 
		    dummy.switchOn()
		elseif tonumber(devP1.rawData[1]) < -500 and dummy.state == 'On' then 
		    dummy.switchOff()
		end 
	end
}
The code is not working:
https://drive.google.com/file/d/1q4WBKP ... sp=sharing
And the only thing in the log is:
https://drive.google.com/open?id=1X1THa ... AW-kiUM3ah

Hope you will help me.
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups

User avatar
emme
Posts: 638
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Help with some scripting with the P1

Post by emme » Monday 13 November 2017 22:11

ok.. the code is probably running and since there is no debug, neither error, it could be that the conditions are NOT invoked

that's probably because your D.M. P1: Strom is a combined device and rawData[1] returns ALL values string....

Since it is an Energy device... try to replace the .rawData[1] to .WhActual (that already return a Number value)
I'd also add some debug info....

Code: Select all

 return {
	on = {
		timer = {
			'between 08:00 and 22:00'
		},
		devices = {
			'D.M. P1: Stroom'
		},
	},
	execute = function(domoticz, devP1)
	    local dummy = domoticz.devices('Dummy P1')
	    domoticz.log('Here is a useful info: whActual: '..devP1.WhActual..'W',domoticz.LOG_FORCE)
		if devP1.WhActual > 500 and dummy.state == 'Off' then 
		    dummy.switchOn().checkFirst()
		    domoticz.log('Switching ON',domoticz.LOG_FORCE)
		elseif devP1.WhActual < -500 and dummy.state == 'On' then 
		    dummy.switchOff().checkFirst()
		    domoticz.log('Switching OFF',domoticz.LOG_FORCE)
		end 
	end
}
That's one small step for a programmer, one giant leap for me!
- - - - -
Raspberry Pi3 + AeonStick G5 + RFXCOMM433 + iRTrans Server + NodeJS
There's no stress in the mess!!

User avatar
Derik
Posts: 1890
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Help with some scripting with the P1

Post by Derik » Monday 13 November 2017 22:40

mmm
Looks it is working: GREAT.
Hope tomorrow when the sun i do his work.
The dummy is going off:
Only did see some errors:

Code: Select all

2017-11-13 21:35:59.170 (D.M.: P1) P1 Smart Meter (D.M. P1: Stroom)
2017-11-13 21:35:59.437 dzVents: Info: Handling events for: "D.M. P1: Stroom", value: "8708725;9639761;2777208;6692124;960;0"
2017-11-13 21:35:59.437 dzVents: Info: ------ Start internal script: DZ: Teruglever: Device: "D.M. P1: Stroom (D.M.: P1)", Index: 3185
2017-11-13 21:35:59.439 dzVents: !Info: Teruglever dummy switch : whActual: 960W
2017-11-13 21:35:59.439 dzVents: Info: ------ Finished DZ: Teruglever
2017-11-13 21:36:00.397 (D.M.: Zwave) Usage (Z: Pellet Actueel)
2017-11-13 21:36:00.419 (D.M.: Zwave) General/kWh (Z: Pellet Totaal)
2017-11-13 21:36:00.457 dzVents: Info: ------ Start internal script: DZ: Teruglever:, trigger: between 08:00 and 22:00
2017-11-13 21:36:00.483 Error: dzVents: Error: An error occured when calling event handler DZ: Teruglever
2017-11-13 21:36:00.483 Error: dzVents: Error: ...icz/scripts/dzVents/generated_scripts/DZ: Teruglever.lua:12: attempt to index local 'devP1' (a nil value)
2017-11-13 21:36:00.483 dzVents: Info: ------ Finished DZ: Teruglever
2017-11-13 21:36:00.556 LUA: Winddelen naar P.V.O.
Nill? @ 21:36:00:483


And do i need set the device or time or variable active ? [ on the right side ]
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups

User avatar
emme
Posts: 638
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Help with some scripting with the P1

Post by emme » Tuesday 14 November 2017 9:09

mmmh... the timer activation does not provide the devP1 table....
ok.. let's try to redefine it in case of it...

Code: Select all

 return {
	on = {
		timer = {
			'between 08:00 and 22:00'
		},
		devices = {
			'D.M. P1: Stroom'
		},
	},
	execute = function(domoticz, devP1, triggerInfo)
		if triggerInfo.type = domoticz.EVENT_TYPE_TIMER then
			devP1 = domoticz.devices('D.M. P1: Stroom')
		end 
	    local dummy = domoticz.devices('Dummy P1')
	    domoticz.log('Here is a useful info: whActual: '..devP1.WhActual..'W',domoticz.LOG_FORCE)
		if devP1.WhActual > 500 and dummy.state == 'Off' then 
		    dummy.switchOn().checkFirst()
		    domoticz.log('Switching ON',domoticz.LOG_FORCE)
		elseif devP1.WhActual < -500 and dummy.state == 'On' then 
		    dummy.switchOff().checkFirst()
		    domoticz.log('Switching OFF',domoticz.LOG_FORCE)
		end 
	end
}
please note that the script will be fired once a minute between 8.00 and 22.00 and in case of value change of D.M. P1: Stroom device

to avoid it you can check time within the code:

Code: Select all

return {
	on = {
		devices = {
			'D.M. P1: Stroom'
		},
	},
	execute = function(domoticz, devP1)
		local Time = require('Time')
		local currentTime = Time()
		local dummy = domoticz.devices('Dummy P1')
		if currentTime.hour >= 8 and currentTime.hour <= 22 then 
			domoticz.log('Here is a useful info: whActual: '..devP1.WhActual..'W',domoticz.LOG_FORCE)
			if devP1.WhActual > 500 and dummy.state == 'Off' then 
				dummy.switchOn().checkFirst()
				domoticz.log('Switching ON',domoticz.LOG_FORCE)
			elseif devP1.WhActual < -500 and dummy.state == 'On' then 
				dummy.switchOff().checkFirst()
				domoticz.log('Switching OFF',domoticz.LOG_FORCE)
			end 
		end 
	end
}
That's one small step for a programmer, one giant leap for me!
- - - - -
Raspberry Pi3 + AeonStick G5 + RFXCOMM433 + iRTrans Server + NodeJS
There's no stress in the mess!!

User avatar
Derik
Posts: 1890
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Help with some scripting with the P1

Post by Derik » Tuesday 14 November 2017 22:31

buzzy with work...
When i do have time is est.
THANKS!!!
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups

User avatar
Derik
Posts: 1890
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Help with some scripting with the P1

Post by Derik » Sunday 19 November 2017 14:17

Dear Emme,

Did use the latest script...
Only the switch is not going anywhere....
I have this:
ScreenShot065.png
ScreenShot065.png (71.99 KiB) Viewed 306 times
And the P1 is in the -
ScreenShot062.png
ScreenShot062.png (10.25 KiB) Viewed 306 times
only no active dummy
ScreenShot063.png
ScreenShot063.png (11.39 KiB) Viewed 306 times
There is some error i think:

Code: Select all

2017-11-19 13:15:21.219 dzVents: !Info: Here is a useful info: whActual: 0W
Because the actual value should be -...
Perhaps use the raw data??
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups

User avatar
emme
Posts: 638
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Help with some scripting with the P1

Post by emme » Monday 20 November 2017 9:00

mmmh... it depends on what kind of device is D.M. P1: Stroom...
I though it was a Electricity device, but the icon looks like a counter....
if so... use .counter instead of WhActual and try again
That's one small step for a programmer, one giant leap for me!
- - - - -
Raspberry Pi3 + AeonStick G5 + RFXCOMM433 + iRTrans Server + NodeJS
There's no stress in the mess!!

User avatar
Derik
Posts: 1890
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Help with some scripting with the P1

Post by Derik » Monday 20 November 2017 19:43

Sorry i am a noob in scripts...
Did change to:
ScreenShot066.png
ScreenShot066.png (71.48 KiB) Viewed 261 times
Only now i get:

Code: Select all

2017-11-20 18:39:59.199 (D.M.: Zwave) General/kWh (Z: Terras)
2017-11-20 18:39:59.513 dzVents: !Info: Here is a useful info: whActual: 18483.514W
2017-11-20 18:39:59.513 Error: dzVents: Error: An error occured when calling event handler DZ: Teruglever 2
2017-11-20 18:39:59.513 Error: dzVents: Error: ...z/scripts/dzVents/generated_scripts/DZ: Teruglever 2.lua:13: attempt to compare string with number
2017-11-20 18:39:59.665 (D.M.: Zwave) Current (Zter: Verwarming)
2017-11-20 18:40:00.481 LUA: D.M.: IP Port check
Where do i go wrong??


Perhaps was the raw data better?
ScreenShot067.png
ScreenShot067.png (30.39 KiB) Viewed 261 times
Only i do not how..
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups

User avatar
emme
Posts: 638
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Help with some scripting with the P1

Post by emme » Monday 20 November 2017 21:17

you change it good, but I cannot figure out what device is that and how dzvents threat it.... and this is my fault, not yours, neither dzVents

Let's try another method...
instead of .counter try .usage (as a P1 Smart Meter)

this should return a number and would not rise the error on line 13, but in case you still have such error....
try to change:
devP1.usage --> tonumber(devP1.usage)
...well... even counter should return a number...
That's one small step for a programmer, one giant leap for me!
- - - - -
Raspberry Pi3 + AeonStick G5 + RFXCOMM433 + iRTrans Server + NodeJS
There's no stress in the mess!!

dannybloe
Posts: 1078
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: Help with some scripting with the P1

Post by dannybloe » Tuesday 21 November 2017 8:28

you can try to dump the device info to the logs using devP1.dump(). It shows you all its properties but also which device adapters are in place for that device. The adapters decide what properties and methods are available for that device and they are based on props like deviceType, subType etc.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

User avatar
Derik
Posts: 1890
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Help with some scripting with the P1

Post by Derik » Wednesday 22 November 2017 8:12

mmm Cannot test....
There is no sun to try the switch...

xx
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest