return {
on = {
devices = { ['PIR 1'] = {'between 06:30 and 08:00'}}
},
execute = function(dz, item)
if (item.state == 'On') then
dz.devices('Light led').switchOn()
dz.devices('Radio').switchOn().afterSec(10)
dz.log ('Radio and LED = ON')
end
end
}
besix wrote: Saturday 30 November 2019 22:26
I have two small scripts they make light in the kitchen in the morning.
How to combine it into one script?
local motion = 'PIR 1'
local light = 'Light 1'
local morning = 'at 06:35-08:00'
return
{
on =
{
devices =
{
[motion] = { morning },
[light] = { morning },
},
},
execute = function(dz)
local isMotion = dz.devices(motion).active
local lightOn = dz.devices(light).active
local ledLight = dz.devices('Light led')
if isMotion then
dz.log ('Motion detected')
if not(lightOn) then ledLight.switchOn().checkFirst() end
dz.devices('Radio').switchOn().afterSec(10)
end
if lightOn then
dz.log ('Main light kitchen is On')
ledLight.switchOff().checkFirst()
end
end
}
local motion = 'PIR 1'
local light = 'Light 1'
local lux = 'External lux'
local morning = 'at 06:35-08:00'
return
{
on =
{
devices =
{
[motion] = { morning },
[light] = { morning },
},
},
execute = function(dz)
local isMotion = dz.devices(motion).active
local lightOn = dz.devices(light).active
local ledLight = dz.devices('Light led')
local LUX = dz.devices(lux).lux
if isMotion and LUX < 20 then
dz.log ('Motion detected')
if not(lightOn) then ledLight.switchOn().checkFirst() end
dz.devices('Radio').switchOn().afterSec(10)
end
if lightOn then
dz.log ('Main light kitchen is On')
ledLight.switchOff().checkFirst()
end
end
}
local motion = 'PIR 1'
local light = 'Light 1'
local lux = 'External lux'
local morning = 'at 06:35-08:00'
return
{
on =
{
devices =
{
[motion] = { morning },
[light] = { morning },
},
},
execute = function(dz)
local isMotion = dz.devices(motion).active
local lightOn = dz.devices(light).active
local ledLight = dz.devices('Light led')
local isDark = dz.devices(lux).lux < 20
if isMotion then
dz.log ('Motion detected')
if isDark then
dz.log ('It is dark')
if not(lightOn) then ledLight.switchOn().checkFirst() end
end
dz.devices('Radio').switchOn().afterSec(10)
end
if lightOn then
dz.log ('Main light kitchen is On')
ledLight.switchOff().checkFirst()
end
end
}