Moving from Blockly to dzVents

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

Moderator: leecollings

Post Reply
avdl72
Posts: 9
Joined: Saturday 15 October 2016 16:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: The Netherlands
Contact:

Moving from Blockly to dzVents

Post 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
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: Moving from Blockly to dzVents

Post 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
}
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
avdl72
Posts: 9
Joined: Saturday 15 October 2016 16:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: The Netherlands
Contact:

Re: Moving from Blockly to dzVents

Post 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
avdl72
Posts: 9
Joined: Saturday 15 October 2016 16:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: The Netherlands
Contact:

Re: Moving from Blockly to dzVents

Post 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)
avdl72
Posts: 9
Joined: Saturday 15 October 2016 16:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: The Netherlands
Contact:

Re: Moving from Blockly to dzVents

Post 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)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Moving from Blockly to dzVents

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
avdl72
Posts: 9
Joined: Saturday 15 October 2016 16:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: The Netherlands
Contact:

Re: Moving from Blockly to dzVents

Post 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.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Moving from Blockly to dzVents

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
avdl72
Posts: 9
Joined: Saturday 15 October 2016 16:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: The Netherlands
Contact:

Re: Moving from Blockly to dzVents

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest