Lua - Light off at Sunset
Purpose
The purpose of this script is to turn off a light at sunset on each weekday.
This script could be used to automatically turn off lights at sunset to begin preparing for bed.
Dependencies
This script’s only dependency is a light that is compatible with Domoticz.
This script was written and tested using a Yeelight and functioned properly.
Domoticz Setup
This script will require that you have a switch that connects to the light you are trying to use. You will need the name of your switch to substitute for ‘home yeelight’ in the script below.
Installation Instructions
Copy this script in your domoticz\scripts\dzVents\scripts folder.
YeeLight Installation instructions: Click Here
Script with Comments
return
{
on =
{
--Runs script at sunset each weekday
timer = {'at sunset on mon, tue, wed, thu, fri'},
},
execute = function(domoticz, timer)
light = domoticz.devices('home yeelight')
--check to see if the light is still on
if (light.state == 'On') then
--If the light is still on at sunset, turn off the light and log
--appropriate message
light.switchOff()
domoticz.log('The light was detected on at sunset on a weekday. The light is now off.')
else
--Will log this message if light was already off
domoticz.log('Light was already off')
end
end
}
Notes
The script above can be customized very easily.
To run the script at a different time besides sunset, change the timer variable to match when you want the script to run.
Enjoy!
I hope this script can be of some use to you and your team if applicable whether it be further development, bug fixes, and improvements!