Page 2 of 2

Re: Switch off, then hold up for 2 hours

Posted: Wednesday 26 August 2020 13:53
by Larsoss
Larsoss wrote: Tuesday 25 August 2020 9:56 haha. indeed I was that far already. I only tried to darken the lux sensor to test, but the dummy switch (evening) did not turn on.

Can i send you a DM?

Code: Select all

local LUX_SENSOR_NAME = 'Lux Hue Woonkamer' --Lux IDX / Sensor naam.
local SWITCH_NAME = 'Is het donker?' -- Dummy switch maken.

local OFF_LEVEL = 18 -- Boven de waarde gaat de Switch_Name uit.
local ON_LEVEL = 45 -- Onder deze waarde gaat de Switch_name aan.

return {
	on = {
		devices = {
			LUX_SENSOR_NAME
		}
	},
	execute = function(domoticz, device)
	    if device.isDevice and device.name == LUX_SENSOR_NAME then
	        local switch = domoticz.devices(SWITCH_NAME)
	        
	        if switch == nil then
	            domoticz.log( "Missing device " .. SWITCH_NAME .. ".", domoticz.LOG_ERROR)
	        elseif switch.bState == true and device.lux >= OFF_LEVEL then
	            switch.switchOff()
	        elseif switch.bState ~= true and device.lux < ON_LEVEL then
	            switch.switchOff()
	        end
	    end
	end
}

Code: Select all

-- Specify the name of the 1st dummy switch here.
local DARK_TIMER_NAME = 'Is het donker?'

-- Specify the name of the 2nd dummy switch here.
local SLEEP_TIMER_NAME = 'Slaap Dummy'

-- Specify the names of the switches for your garden or porch lights
-- here. If you want to switch multiple lights specify them like
-- { 'light1', 'light2', 'light3' }
local BUITENLAMPEN = { 'Tasmota-Vitrine', 'Tasmota-Lamp_naast_kast', 'Woonkamerlamp' }

return {
	on = {
		devices = {
			DARK_TIMER_NAME,
			SLEEP_TIMER_NAME
		}
	},
	execute = function(domoticz, device)
	    domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
	    
	    if device.isDevice and (DARK_TIMER_NAME == device.name or SLEEP_TIMER_NAME == device.name) then
            local dark = domoticz.devices(DARK_TIMER_NAME)
            local sleep = domoticz.devices(SLEEP_TIMER_NAME)

    	    if nil == dark then
    	        domoticz.log( "Missing device " .. DARK_TIMER_NAME .. ".", domoticz.LOG_ERROR)
    	    elseif nil == sleep then
    	        domoticz.log( "Missing device " .. SLEEP_TIMER_NAME .. ".", domoticz.LOG_ERROR)
    	    else
    	        domoticz.devices().filter(BUITENLAMPEN).forEach(
    	            function(lamp)
            		    if dark.bState and not sleep.bState then
            		        if not lamp.bState then
            		            lamp.switchOn()
            		        end
                        else
                            if lamp.bState then
                	            lamp.switchOff()
                	        end
                        end
    	            end
	            )
	        end
	    end
And i have 2 dummy switches called ''Is het donker?'' ''Slaap Dummy''
The last one is switch by the timers. Thats right. The ''Is het donker?'' not switch by the first script.

Re: Switch off, then hold up for 2 hours

Posted: Friday 28 August 2020 9:57
by rrozema
Is your lux sensor inside your room? Because then the lux value gets influenced by the lights themselves. This will only ever work correct if the lux sensor does not get any light on it from the lights it switches.

I tried the lux script myself too, using a lux sensor that is on my top floor, receiving daylight via a skylight. Even that gets too much light from the lamps inside my house to properly toggle the dummy switch. I went back to switching the dummy switch using timers, which gives a much more reliable result.