Page 1 of 1

Problem with switch and Xiaomi LUX sensor

Posted: Friday 20 September 2019 22:30
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
}

Re: Problem with switch and Xiaomi LUX sensor

Posted: Friday 20 September 2019 22:55
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
}