Problem with switch and Xiaomi LUX sensor

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

Moderator: leecollings

Post Reply
teemurama
Posts: 12
Joined: Saturday 09 June 2018 19:40
Target OS: Linux
Domoticz version:
Contact:

Problem with switch and Xiaomi LUX sensor

Post by teemurama »

Hello

What's wrong this code ? Lights switch on but shut down too fast. Lasts only under minute and then switch off.

Code: Select all

return {

	active = true,  

	on = {

		devices = {
			'Kuisti_liike'
		},

	},

	execute = function(dz, item, valo, kytkin)
		local valo = dz.devices('Kuisti')
		local sensor = dz.devices('Kuisti_liike')
		local Lux = dz.devices('Aqara Motion Sensor_lux')
		local LUX = Lux.lux

		if (sensor.state == 'On' and LUX <= 30 ) then 
		    dz.devices('Kuisti').switchOn().forMin(2)
	    else 
	        dz.devices('Kuisti').switchOff()
		
    end 
end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Problem with switch and Xiaomi LUX sensor

Post by waaren »

teemurama wrote: Friday 20 September 2019 22:30 Lights switch on but shut down too fast. Lasts only under minute and then switch off.
Code looks OK, but hard to tell without any log. That's why I always start with LOG_DEBUG and switch to LOG_ERROR (= almost silent) when script execute as expected. Also I am not a big fan of using forXXX(). For me it does not behave very intuitive.
Please have a look at this and see if that serve your needs.

Code: Select all

return {

	active = true,  

	on = {

		devices = {
			'Kuisti_liike'
		},

	},
	
	logging =   
    {
        level = domoticz.LOG_DEBUG, -- set to LOG_ERROR when tested and OK
        marker = 'Kuisti',
    },
	

	execute = function(dz, item)
		local valo = dz.devices('Kuisti')
		local sensor = dz.devices('Kuisti_liike')
		local Lux = dz.devices('Aqara Motion Sensor_lux')
		local LUX = Lux.lux

		if (sensor.state == 'On' and LUX <= 30 ) then 
		    dz.devices('Kuisti').cancelQueuedCommands()
		    dz.devices('Kuisti').switchOn()
			dz.devices('Kuisti').switchOff().afterSec(120)
		end 
end
} 
 
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