Lua - Light as Alarm
Purpose
The purpose of this script is to have the light gradually increase brightness over a 20 minute period. This script could be used to gradually wake someone up by increasing the brightness of the light.
Dependencies
This script’s first dependency is a light that is compatible with Domoticz. Additionally, the chosen light must have the ability to dim. This script was written and tested using a Yeelight (Color) 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\ folder.
YeeLight Installation instructions: Click Here
Script with Comments
return {
on = {
--Run script every weekday between 9:40 and 10 to gradually increase
--brightness of light
timer = {'every 6 minutes between 9:40 and 10:00 on mon,tue,wed,thu,fri'}
},
execute = function(domoticz, timer)
light = domoticz.devices('Home Yeelight')
--(hour 9 * 60 + minutes 30) Represents when you want the light to begin
--turning on
targetMinutes = 570
--calculates the current time in minutes
currentMinutes = ((domoticz.time.hour + 2) * 60) + domoticz.time.minutes
--calculates the difference between the actual time and desired time
differenceMinutes = currentMinutes - targetMinutes
--Checks to see if the light is off and it is time to begin turning the
--light on
if (light.state == 'Off' and differenceMinutes == 0) then
--Turn the light onto 25% brightness and log the current brightness
light.dimTo(24)
domoticz.log('25% brightness')
--checks to see if the light is on
elseif (light.state == 'On') then
--check to see if 6 minutes have passed since light turned on
if (differenceMinutes == 6) then
--If so, increase brightness to 50% and log new brightness
light.dimTo(49)
domoticz.log('50% brightness')
--check to see if 12 minutes have passed since light turned on
elseif (differenceMinutes == 12) then
--Turn the light onto 75% brightness and log the current brightness
light.dimTo(74)
domoticz.log('75% brightness')
--check to see if 18 minutes have passed since light turned on
elseif (differenceMinutes == 18) then
--Turn the light onto 100% brightness and log the current brightness
light.dimTo(99)
domoticz .log('100% brightness')
else
--Log if it is not time to increase brightness
domoticz.log('Not time to increase brightness')
end
else
--Log if light is off and not time to turn on yet
domoticz.log('Light is off, but not time to switch on yet')
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. The targetMinutes, which is the number of minutes at the time you want the light to start turning on, can easily be changed by using the formula in the comment above the targetMinutes.
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!