custom sensor error  [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:

custom sensor error

Post 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
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
hoeby
Posts: 531
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: custom sensor error

Post 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.
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: custom sensor error  [Solved]

Post 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.
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: custom sensor error

Post 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!
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: custom sensor error

Post 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!
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest