Page 1 of 1

help needed with sprinkler program script

Posted: Wednesday 24 June 2020 20:46
by snellejellep
hi all,

i have a script i use to take actions depending on a selector state.
now on line 50 i use a soil moisture sensor which is a custom sensor with percentage in domoticz see picture for more details: Image
the thing is that i get the following error:

Code: Select all

2020-06-24 20:22:08.902 Error: dzVents: Error: (3.0.2) Sproeier: An error occurred when calling event handler Sproeier programma
2020-06-24 20:22:08.902 Error: dzVents: Error: (3.0.2) Sproeier: ...scripts/dzVents/generated_scripts/Sproeier programma.lua:50: attempt to compare table with number
this is the script, i hope someone can figure out how to do this because if i put a percentage symbol behind the 80 it freaks out even more:

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 zone8 = dz.devices("Irrigatie zone 8")
		local zone9 = dz.devices("Irrigatie zone 9")
		local zone10 = dz.devices("Irrigatie zone 10")
		local soil7 = dz.devices("Grondvochtigheid zone 7")

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

		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
			zone8.switchOn()
			zone10.switchOn().afterMin(1)
			zone4.switchOn().afterMin(3)
			zone5.switchOn().afterMin(2)
			zone1.switchOn().afterMin(61)
			zone2.switchOn().afterMin(62)
			zone3.switchOn().afterMin(62)
			zone9.switchOn().afterMin(62)
			selector.switchOff().afterMin(122).silent()
			if soil7 < 80 then
			    zone7.switchOn().afterMin(63)
			end
			
		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
			zone8.switchOn()
			zone10.switchOn().afterMin(1)
			zone4.switchOn().afterMin(2)
			zone5.switchOn().afterMin(3)
			selector.switchOff().afterMin(61).silent()

		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)
			zone3.switchOn().afterMin(1)
	        zone9.switchOn().afterMin(2)
			selector.switchOff().afterMin(61).silent()
			if soil7 < 80 then
			    zone7.switchOn().afterMin(1)
			end

		elseif selector.state == "Waterstopcontact" then
			-- turn on zone 6 and turn it off after an hour
			zone6.switchOn()
			selector.switchOff().afterMin(60).silent()
		
		elseif selector.state == "Off" then
			-- force everything to turn off
			-- Already done
		end
	end
}

Re: help needed with sprinkler program script  [Solved]

Posted: Wednesday 24 June 2020 23:06
by waaren
snellejellep wrote: Wednesday 24 June 2020 20:46 i have a script i use to take actions depending on a selector state.
now on line 50 i use a soil moisture sensor which is a custom sensor with percentage in domoticz

Code: Select all

2020-06-24 20:22:08.902 Error: dzVents: Error: (3.0.2) Sproeier: An error occurred when calling event handler Sproeier programma
2020-06-24 20:22:08.902 Error: dzVents: Error: (3.0.2) Sproeier: ...scripts/dzVents/generated_scripts/Sproeier programma.lua:50: attempt to compare table with number
The script tries to compare the device 'Grondvochticheid zone 7' (which is a table for Lua) with a number
try again after changing line 28 from

Code: Select all

		local soil7 = dz.devices("Grondvochtigheid zone 7")
to

Code: Select all

		local soil7 = tonumber(dz.devices("Grondvochtigheid zone 7").state)

Re: help needed with sprinkler program script

Posted: Thursday 25 June 2020 17:24
by snellejellep
waaren wrote: Wednesday 24 June 2020 23:06 The script tries to compare the device 'Grondvochticheid zone 7' (which is a table for Lua) with a number
try again after changing line 28 from

Code: Select all

		local soil7 = dz.devices("Grondvochtigheid zone 7")
to

Code: Select all

		local soil7 = tonumber(dz.devices("Grondvochtigheid zone 7").state)
i changed that line and now it does not give me an arror anymore so that is great! i will see if it works this afternoon when i ask the system to water the garden again.

many thanks again!