Page 1 of 1

Moving from Blockly to dzVents

Posted: Saturday 16 November 2019 16:41
by avdl72
I'm trying to learn dzVents but need some help after I have tried after a long to get it working.

I want this blockly workflow to be converted to dzVents.
Who can help me please.

Image

Re: Moving from Blockly to dzVents

Posted: Saturday 16 November 2019 16:51
by snellejellep
this should work:

Code: Select all

return {
	on = {
		devices = {
			'Rolluik 3'
		}
	},
	execute = function(dz, device)
		domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
		
		local rolluik       = dz.devices('Rolluik 3')
		
		if rolluik.state == "Off" then
		    dz.openURL("http://192.168.1.33/cm?cmd=Power2%20Off")
		    dz.openURL("http://192.168.1.33/cm?cmd=Power1%20On").afterSec(1)
		    dz.openURL("http://192.168.1.33/cm?cmd=Power1%20Off").afterSec(120)
		elseif rolluik.state == "On" then
		    dz.openURL("http://192.168.1.33/cm?cmd=Power1%20Off")
		    dz.openURL("http://192.168.1.33/cm?cmd=Power2%20On").afterSec(1)
		    dz.openURL("http://192.168.1.33/cm?cmd=Power2%20Off").afterSec(120)
		elseif rolluik.state == "Stop" then
		    dz.openURL("http://192.168.1.33/cm?cmd=Power1%20Off")
		    dz.openURL("http://192.168.1.33/cm?cmd=Power2%20Off")
		end
	end
}

Re: Moving from Blockly to dzVents

Posted: Sunday 17 November 2019 13:54
by avdl72
Thanks for your quick answer, but I get this error:

2019-11-17 13:45:19.954 Status: User: Admin initiated a switch command (51/Rolluik 3/On)
2019-11-17 13:45:20.046 Status: dzVents: Info: Handling events for: "Rolluik 3", value: "On"
2019-11-17 13:45:20.046 Status: dzVents: Info: ------ Start internal script: Script #1: Device: "Rolluik 3 (Dummy)", Index: 51
2019-11-17 13:45:20.046 Status: dzVents: Error (2.4.19): An error occured when calling event handler Script #1
2019-11-17 13:45:20.046 Status: dzVents: Error (2.4.19): ...domoticz/scripts/dzVents/generated_scripts/Script #1.lua:8: attempt to index global 'domoticz' (a nil value)
2019-11-17 13:45:20.046 Status: dzVents: Info: ------ Finished Script #1

Re: Moving from Blockly to dzVents

Posted: Sunday 17 November 2019 14:10
by avdl72
When I removed this line:
domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)

The error was gone but nothing happend.

2019-11-17 14:07:29.390 (Dummy) Light/Switch (Rolluik 3)
2019-11-17 14:07:29.380 Status: User: Admin initiated a switch command (51/Rolluik 3/On)
2019-11-17 14:07:29.474 Status: dzVents: Info: Handling events for: "Rolluik 3", value: "On"
2019-11-17 14:07:29.474 Status: dzVents: Info: ------ Start internal script: Rolluik 3 TEST: Device: "Rolluik 3 (Dummy)", Index: 51
2019-11-17 14:07:29.474 Status: dzVents: Info: ------ Finished Rolluik 3 TEST
2019-11-17 14:07:29.474 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2019-11-17 14:07:34.860 (Homewizard) Update 0:'5115433;5206485;1864682;4176149;219;0' (Electricity)

Re: Moving from Blockly to dzVents

Posted: Sunday 17 November 2019 14:20
by avdl72
Okay found one error.
There was a typo in the URL.

Still the log line: domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
is generating this error:
Status: dzVents: Error (2.4.19): ...domoticz/scripts/dzVents/generated_scripts/Script #1.lua:8: attempt to index global 'domoticz' (a nil value)

Re: Moving from Blockly to dzVents

Posted: Sunday 17 November 2019 21:58
by waaren
avdl72 wrote: Sunday 17 November 2019 14:20 Okay found one error.
There was a typo in the URL.

Still the log line: domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
is generating this error:
Status: dzVents: Error (2.4.19): ...domoticz/scripts/dzVents/generated_scripts/Script #1.lua:8: attempt to index global 'domoticz' (a nil value)
If you use dz in the execute = parms the every subsequent calls to the domoticz object should also be to dz. So script should be

Code: Select all

return {
	on = {
		devices = {
			'Rolluik 3'
		}
	},
	execute = function(dz, device)
		dz.log('Device ' .. device.name .. ' was changed', dz.LOG_INFO)
		
		local rolluik       = dz.devices('Rolluik 3')
		
		if rolluik.state == "Off" then
		    dz.openURL("http://192.168.1.33/cm?cmd=Power2%20Off")
		    dz.openURL("http://192.168.1.33/cm?cmd=Power1%20On").afterSec(1)
		    dz.openURL("http://192.168.1.33/cm?cmd=Power1%20Off").afterSec(120)
		elseif rolluik.state == "On" then
		    dz.openURL("http://192.168.1.33/cm?cmd=Power1%20Off")
		    dz.openURL("http://192.168.1.33/cm?cmd=Power2%20On").afterSec(1)
		    dz.openURL("http://192.168.1.33/cm?cmd=Power2%20Off").afterSec(120)
		elseif rolluik.state == "Stop" then
		    dz.openURL("http://192.168.1.33/cm?cmd=Power1%20Off")
		    dz.openURL("http://192.168.1.33/cm?cmd=Power2%20Off")
		end
	end
}
 
also described here

Re: Moving from Blockly to dzVents

Posted: Monday 18 November 2019 10:09
by avdl72
Okay thank you very much. It's getting a bit clearly now.

Now I go to the next fase to get a fail safe.
When triggering the Sonoff URL I get a response with {"POWER2":"OFF"} or {"POWER2":"On"} and I want to use that as a trigger to resend the command again if this message isn't received. And then a new command is send again.

Re: Moving from Blockly to dzVents

Posted: Monday 18 November 2019 12:02
by waaren
avdl72 wrote: Monday 18 November 2019 10:09 When triggering the Sonoff URL I get a response with {"POWER2":"OFF"} or {"POWER2":"On"} and I want to use that as a trigger to resend the command again if this message isn't received. And then a new command is send again.
Maybe a bit of overkill but this should be possible with a combination of one or more http callback triggers , - a postponed virtual switch trigger and expected results stored in dzVents persistent data.

Re: Moving from Blockly to dzVents

Posted: Monday 18 November 2019 14:06
by avdl72
Okay thx.
Maybe I give it a try without first.

Now I'm using the KAKU ASUN modules en these sometimes don't receive the commands.
These Sonoff Dual R2 modules should work better, and wifi is good in my house.