Help needed with garden irrigation program selector  [Solved]

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

Moderator: leecollings

Post Reply
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Help needed with garden irrigation program selector

Post by snellejellep »

Hi, i need some help creating a dzvents stript for a selector switch to be used as some kind of irrigation program selector.
this is what i created so far but i can not figure out how to execute functions with a certain delay. i hope someone can help.

Code: Select all

return {
	on = {
		devices = {
			'Sproeier programma'
		}
	},
	execute = function(dz, device)
		local selector          = dz.devices("Sproeier programma")
		local zone1             = dz.devices("Irrigatie zone 1")            
		local zone2             = dz.devices("Irrigatie zone 2") 
		local zone3             = dz.devices("Irrigatie zone 3") 
		local zone4             = dz.devices("Irrigatie zone 4") 
		local zone5             = dz.devices("Irrigatie zone 5") 
		local zone6             = dz.devices("Irrigatie zone 6") 
		local zone7             = dz.devices("Irrigatie zone 7") 
		
		if selector.state == "Alles" then
		    -- first turn on zone 4 and 1 min later zone 5, then after an hour turn off zone 4 and 5 and turn on first zone 1, then a minute later zone 2,3 and 7
		elseif selector.state == "Voortuin" then
		    -- turn on zone 4 and 1 minute later zone 5, then after an hour turn off zone 4 and zone5
		elseif selector.state == "Achtertuin" then
		    -- turn on zone 1, and 1 minute later zone 2, 3 and 7 and turn them off after an hour
		elseif selector.state == "Waterstopcontact" then
		    -- turn on zone 6 and turn it off after an hour
		elseif selector.state == "Off" then
		    -- force everything to turn off
		    zone1.switchOff()
		    zone2.switchOff()
		    zone3.switchOff()
		    zone4.switchOff()
		    zone5.switchOff()
		    zone6.switchOff()
		    zone7.switchOff()
		end
	end
}
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Help needed with garden irrigation program selector  [Solved]

Post by waaren »

snellejellep wrote: Wednesday 22 May 2019 21:06 Hi, i need some help creating a dzvents stript for a selector switch to be used as some kind of irrigation program selector.
Could be something like this. (some assumptions, about resetting states when new selector level is chosen, made)

Code: Select all

return {
	on = {
		devices = {
			'Sproeier programma'
		}
	},

	   logging =	{   
						level   =   domoticz.LOG_ERROR,
						-- level   =   domoticz.LOG_DEBUG,
						marker  =   "Sproeier" 
					},	
					
	execute = function(dz, device)

		local selector = dz.devices("Sproeier programma")

		local zone1 = dz.devices("Irrigatie zone 1")
		local zone2 = dz.devices("Irrigatie zone 2")
		local zone3 = dz.devices("Irrigatie zone 3")
		local zone4 = dz.devices("Irrigatie zone 4")
		local zone5 = dz.devices("Irrigatie zone 5")
		local zone6 = dz.devices("Irrigatie zone 6")
		local zone7 = dz.devices("Irrigatie zone 7")

		local zones = { zone1, zone2, zone3, zone4, zone5, zone6, zone7 }

		dz.log(selector.name .. ' switched to ' .. selector.state, dz.LOG_DEBUG)

		for _, zone in ipairs(zones) do
			zone.cancelQueuedCommands() -- remove all 'old' scheduled starts / stops
			zone.switchOff().checkFirst()
		end
		
		if selector.state == "Alles" then
			-- first turn on zone 4 and 1 Min later zone 5, then after an hour turn off zone 4 and 5 and turn on first zone 1, then a Minute later zone 2,3 and 7
			zone4.switchOn().forMin(60)
			zone5.switchOn().afterMin(1).forMin(60)
			zone1.switchOn().afterMin(61).forMin(60)
			zone2.switchOn().afterMin(62).forMin(60)
			zone3.switchOn().afterMin(62).forMin(60)
			zone7.switchOn().afterMin(62).forMin(60)
			
		elseif selector.state == "Voortuin" then
			-- turn on zone 4 and 1 Minute later zone 5, then after an hour turn off zone 4 and zone5
			zone4.switchOn().forMin(60)
			zone5.switchOn().afterMin(1).forMin(60)

		elseif selector.state == "Achtertuin" then
			-- turn on zone 1, and 1 Minute later zone 2, 3 and 7 and turn them off after an hour
			zone1.switchOn().forMin(60)
			zone2.switchOn().afterMin(1).forMin(60)
			zone3.switchOn().afterMin(1).forMin(60)
			zone7.switchOn().afterMin(1).forMin(60)

		elseif selector.state == "Waterstopcontact" then
			-- turn on zone 6 and turn it off after an hour
			zone6.switchOn().forMin(60)
		
		elseif selector.state == "Off" then
			-- force everything to turn off
			-- Already done
		end
	end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: Help needed with garden irrigation program selector

Post by snellejellep »

waaren wrote: Wednesday 22 May 2019 22:18
snellejellep wrote: Wednesday 22 May 2019 21:06 Hi, i need some help creating a dzvents stript for a selector switch to be used as some kind of irrigation program selector.
Could be something like this. (some assumptions, about resetting states when new selector level is chosen, made)

Code: Select all

return {
	on = {
		devices = {
			'Sproeier programma'
		}
	},

	   logging =	{   
						level   =   domoticz.LOG_ERROR,
						-- level   =   domoticz.LOG_DEBUG,
						marker  =   "Sproeier" 
					},	
					
	execute = function(dz, device)

		local selector = dz.devices("Sproeier programma")

		local zone1 = dz.devices("Irrigatie zone 1")
		local zone2 = dz.devices("Irrigatie zone 2")
		local zone3 = dz.devices("Irrigatie zone 3")
		local zone4 = dz.devices("Irrigatie zone 4")
		local zone5 = dz.devices("Irrigatie zone 5")
		local zone6 = dz.devices("Irrigatie zone 6")
		local zone7 = dz.devices("Irrigatie zone 7")

		local zones = { zone1, zone2, zone3, zone4, zone5, zone6, zone7 }

		dz.log(selector.name .. ' switched to ' .. selector.state, dz.LOG_DEBUG)

		for _, zone in ipairs(zones) do
			zone.cancelQueuedCommands() -- remove all 'old' scheduled starts / stops
			zone.switchOff().checkFirst()
		end
		
		if selector.state == "Alles" then
			-- first turn on zone 4 and 1 Min later zone 5, then after an hour turn off zone 4 and 5 and turn on first zone 1, then a Minute later zone 2,3 and 7
			zone4.switchOn().forMin(60)
			zone5.switchOn().afterMin(1).forMin(60)
			zone1.switchOn().afterMin(61).forMin(60)
			zone2.switchOn().afterMin(62).forMin(60)
			zone3.switchOn().afterMin(62).forMin(60)
			zone7.switchOn().afterMin(62).forMin(60)
			
		elseif selector.state == "Voortuin" then
			-- turn on zone 4 and 1 Minute later zone 5, then after an hour turn off zone 4 and zone5
			zone4.switchOn().forMin(60)
			zone5.switchOn().afterMin(1).forMin(60)

		elseif selector.state == "Achtertuin" then
			-- turn on zone 1, and 1 Minute later zone 2, 3 and 7 and turn them off after an hour
			zone1.switchOn().forMin(60)
			zone2.switchOn().afterMin(1).forMin(60)
			zone3.switchOn().afterMin(1).forMin(60)
			zone7.switchOn().afterMin(1).forMin(60)

		elseif selector.state == "Waterstopcontact" then
			-- turn on zone 6 and turn it off after an hour
			zone6.switchOn().forMin(60)
		
		elseif selector.state == "Off" then
			-- force everything to turn off
			-- Already done
		end
	end
}
thank you! it works great!
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest