Page 1 of 1

custom sensor error

Posted: Friday 07 June 2019 19:04
by snellejellep
hello, i am trying to use this to automate my garden irrigation:

Code: Select all

return {
	on = {
		timer ={
	    "every minute"
	    }
	},
	execute = function(dz, device)
		
		local sensor            = dz.devices("Grondvochtigheid voortuin")
		local nachtmodus        = dz.devices("nachtmodus")
		local programma         = dz.devices("Sproeier programma")
		local forecast          = dz.devices("Buienradar - Rain forecast [0-255]")
		
		if sensor < 50 and nachtmodus == "On" and forecast < 15 then
		    programma.dimTo(20)
		end
		
	end
}
which basically does this:
nachtmodus switches on when everyone gets to bed so no one is walking outside and can get potentially wet. and forecast is an buienradar sensor which seems to say how likely it is to be raining soon and how much. my sensor is a inductive water sensor connected to an nodemcu analog pin and it feeds to a custom sensor:

Image

well it is not perfect with the percentage but it gives a good indication.

only i get this error in my log, am i doing something wrong?

Code: Select all

2019-06-07 19:00:00.294 Status: dzVents: Info: ------ Start internal script: Automate Irrigatie:, trigger: every minute
2019-06-07 19:00:00.300 Status: dzVents: Error (2.4.19): An error occured when calling event handler Automate Irrigatie
2019-06-07 19:00:00.300 Status: dzVents: Error (2.4.19): ...scripts/dzVents/generated_scripts/Automate Irrigatie.lua:14: attempt to compare table with number
2019-06-07 19:00:00.300 Status: dzVents: Info: ------ Finished Automate Irrigatie

Re: custom sensor error

Posted: Friday 07 June 2019 19:36
by hoeby
The problem is in this line

Code: Select all

if sensor < 50 and nachtmodus == "On" and forecast < 15 then
Sensor and forecast are not value's, like your have written it in your code.
Therefor you want to compare a non value, with a value.

I am not an expert how to solve this. Try to look for a solution how this is done.

Re: custom sensor error  [Solved]

Posted: Friday 07 June 2019 20:33
by waaren
You try to compare devices (tables) to values. I don't know the devicetype but if you change line 14 to this

Code: Select all

if tonumber(sensor.state) < 50 and nachtmodus.state == "On" and tonumber(forecast.state) < 15 then
it might work. If not the please state what the device types you use have.

Re: custom sensor error

Posted: Friday 07 June 2019 20:48
by snellejellep
waaren wrote: Friday 07 June 2019 20:33 You try to compare devices (tables) to values. I don't know the devicetype but if you change line 14 to this

Code: Select all

if tonumber(sensor.state) < 50 and nachtmodus.state == "On" and tonumber(forecast.state) < 15 then
it might work. If not the please state what the device types you use have.
Thank you, i added it to the code and it works.

you are a legend, again!

you may need to consider putting a paypal me link in your bio so people can buy you a beer!

Re: custom sensor error

Posted: Friday 07 June 2019 21:04
by waaren
snellejellep wrote: Friday 07 June 2019 20:48 Thank you, i added it to the code and it works.
Good to read that it works and thanks for the compliment!