Re: Switch off, then hold up for 2 hours
Posted: Wednesday 26 August 2020 13:53
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
The last one is switch by the timers. Thats right. The ''Is het donker?'' not switch by the first script.