Can this script made smarter / better
Posted: Sunday 15 April 2018 16:03
If have created the following script, which flash 2 yeelights and the Xiaomo gateway. Also it plays a sound using the Xiaomi gateway.
It is triggered with the TEST SW (a dummy switch which is activated by several PIR's).
The script works, but I think that the scripts can be made smarter of shorter.
Any tips ?
It is triggered with the TEST SW (a dummy switch which is activated by several PIR's).
The script works, but I think that the scripts can be made smarter of shorter.
Any tips ?
Code: Select all
return {
on = {
devices = {
'TEST SW'
}
},
execute = function(domoticz, device)
domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
domoticz.log('Executing alarm sound and light', domoticz.LOG_INFO)
local light = domoticz.devices('XIAOMI LIVING ROOM')
local alsw = domoticz.devices('TEST SW')
local light1 = domoticz.devices('Lamp bank links')
local light2 = domoticz.devices('YeeLight LED Bank')
local alarmsound = domoticz.devices('Xiaomi Doorbell')
local alarmlevel = domoticz.devices('GW Xiaomi Volume')
if device.state == 'On' then
-- Set alarm sound and level 100%
alarmlevel.dimTo(100)
-- alarmsound.switchSelector(50)
-- End set sound level
-- Start alarm lights
light.dimTo(100)
light.setRGB(255,0,0).afterSec(10)
light.setRGB(0,0,255).afterSec(9)
light.setRGB(255,0,0).afterSec(8)
light.setRGB(0,0,255).afterSec(7)
light.setRGB(255,0,0).afterSec(6)
light.setRGB(0,0,255).afterSec(5)
light.setRGB(255,0,0).afterSec(4)
light.setRGB(255,0,0).afterSec(3)
light.setRGB(0,0,255).afterSec(2)
light.setRGB(255,0,0).afterSec(1)
light.setRGB(0,0,255)
light1.dimTo(100)
light1.setRGB(255,0,0).afterSec(10)
light1.setRGB(0,0,255).afterSec(9)
light1.setRGB(255,0,0).afterSec(8)
light1.setRGB(0,0,255).afterSec(7)
light1.setRGB(255,0,0).afterSec(6)
light1.setRGB(0,0,255).afterSec(5)
light1.setRGB(255,0,0).afterSec(4)
light1.setRGB(255,0,0).afterSec(3)
light1.setRGB(0,0,255).afterSec(2)
light1.setRGB(255,0,0).afterSec(1)
light1.setRGB(0,0,255)
light2.dimTo(100)
light2.setRGB(255,0,0).afterSec(10)
light2.setRGB(0,0,255).afterSec(9)
light2.setRGB(255,0,0).afterSec(8)
light2.setRGB(0,0,255).afterSec(7)
light2.setRGB(255,0,0).afterSec(6)
light2.setRGB(0,0,255).afterSec(5)
light2.setRGB(255,0,0).afterSec(4)
light2.setRGB(255,0,0).afterSec(3)
light2.setRGB(0,0,255).afterSec(2)
light2.setRGB(255,0,0).afterSec(1)
light2.setRGB(0,0,255)
-- Switch off alarm sound and light after 11 seconds. Also switch off alarm switch (alsw). AlSW will be activated againif motion is detected
light.switchOff().afterSec(11)
light1.switchOff().afterSec(11)
light2.switchOff().afterSec(11)
alsw.switchOff().afterSec(11)
alarmsound.switchSelector(0).afterSec(11)
end
end
}