Lua - Light Flashing Alternating Colors
Purpose
The purpose of this script is to have the light flash a variety of colors.
This script could be used as a party setting where you desire a flashing variety of colors.
Dependencies
This script’s first dependency is a light that is compatible with Domoticz.
The chosen light must have the ability to show colors. 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 the script every minute from 5pm to 5:10pm on Fridays
timer = {'every minute between 17:00 and 17:10 on fri'}
},
execute = function(domoticz, timer)
light = domoticz.devices('Home Yeelight')
--Check to see if the light is Off
if (light.state == 'Off') then
--Turn the light on
light.switchOn()
--Log that the light has turned on
domoticz.log('Light is turned on')
--Change the color: Blue -> Yellow -> Teal -> Pink -> Green ->
--Orange -> Purple -> Light Green -> Red -> Light Blue. Each color
--will stay on for 2 seconds, then the next color will come on. The
--colors will repeat once the last color is reached
light.setHex(0x00, 0x02, 0xFF)
light.setHex(0xFF, 0xD9, 0x0E).afterSec(2)
light.setHex(0x67, 0xFF, 0xF8).afterSec(4)
light.setHex(0xFF, 0x9F, 0xED).afterSec(6)
light.setHex(0x30, 0xFF, 0x0A).afterSec(8)
light.setHex(0xFF, 0x91, 0x23).afterSec(10)
light.setHex(0x9E, 0x06, 0xFF).afterSec(12)
light.setHex(0x97, 0xFF, 0x93).afterSec(14)
light.setHex(0xFF, 0x05, 0x0B).afterSec(16)
light.setHex(0x62, 0xCF, 0xFF).afterSec(18)
light.setHex(0xFF, 0xD9, 0x0E).afterSec(20)
light.setHex(0x00, 0x02, 0xFF).afterSec(22)
light.setHex(0xFF, 0xD9, 0x0E).afterSec(24)
light.setHex(0x67, 0xFF, 0xF8).afterSec(26)
light.setHex(0xFF, 0x9F, 0xED).afterSec(28)
light.setHex(0x30, 0xFF, 0x0A).afterSec(30)
light.setHex(0xFF, 0x91, 0x23).afterSec(32)
light.setHex(0x9E, 0x06, 0xFF).afterSec(34)
light.setHex(0x97, 0xFF, 0x93).afterSec(36)
light.setHex(0xFF, 0x05, 0x0B).afterSec(38)
light.setHex(0x62, 0xCF, 0xFF).afterSec(40)
light.setHex(0xFF, 0xD9, 0x0E).afterSec(42)
light.setHex(0x30, 0xFF, 0x0A).afterSec(44)
light.setHex(0xFF, 0x91, 0x23).afterSec(46)
light.setHex(0x9E, 0x06, 0xFF).afterSec(48)
light.setHex(0x97, 0xFF, 0x93).afterSec(50)
light.setHex(0xFF, 0x05, 0x0B).afterSec(52)
light.setHex(0x62, 0xCF, 0xFF).afterSec(54)
light.setHex(0xFF, 0xD9, 0x0E).afterSec(56)
--Log that the light has gone through one round of color change
domoticz.log('One round of color chars gone through')
--checks to see if the light is on or set to a color
elseif (light.state == 'On' or light.state == 'Set Color') then
--Change the color: Blue -> Yellow -> Teal -> Pink -> Green ->
--Orange -> Purple -> Light Green -> Red -> Light Blue. Each color
--will stay on for 2 seconds, then the next color will come on. The
--colors will repeat once the last color is reached
light.setHex(0x00, 0x02, 0xFF)
light.setHex(0xFF, 0xD9, 0x0E).afterSec(2)
light.setHex(0x67, 0xFF, 0xF8).afterSec(4)
light.setHex(0xFF, 0x9F, 0xED).afterSec(6)
light.setHex(0x30, 0xFF, 0x0A).afterSec(8)
light.setHex(0xFF, 0x91, 0x23).afterSec(10)
light.setHex(0x9E, 0x06, 0xFF).afterSec(12)
light.setHex(0x97, 0xFF, 0x93).afterSec(14)
light.setHex(0xFF, 0x05, 0x0B).afterSec(16)
light.setHex(0x62, 0xCF, 0xFF).afterSec(18)
light.setHex(0xFF, 0xD9, 0x0E).afterSec(20)
light.setHex(0x00, 0x02, 0xFF).afterSec(22)
light.setHex(0xFF, 0xD9, 0x0E).afterSec(24)
light.setHex(0x67, 0xFF, 0xF8).afterSec(26)
light.setHex(0xFF, 0x9F, 0xED).afterSec(28)
light.setHex(0x30, 0xFF, 0x0A).afterSec(30)
light.setHex(0xFF, 0x91, 0x23).afterSec(32)
light.setHex(0x9E, 0x06, 0xFF).afterSec(34)
light.setHex(0x97, 0xFF, 0x93).afterSec(36)
light.setHex(0xFF, 0x05, 0x0B).afterSec(38)
light.setHex(0x62, 0xCF, 0xFF).afterSec(40)
light.setHex(0xFF, 0xD9, 0x0E).afterSec(42)
light.setHex(0x30, 0xFF, 0x0A).afterSec(44)
light.setHex(0xFF, 0x91, 0x23).afterSec(46)
light.setHex(0x9E, 0x06, 0xFF).afterSec(48)
light.setHex(0x97, 0xFF, 0x93).afterSec(50)
light.setHex(0xFF, 0x05, 0x0B).afterSec(52)
light.setHex(0x62, 0xCF, 0xFF).afterSec(54)
light.setHex(0xFF, 0xD9, 0x0E).afterSec(56)
--Log that color has gone through when light started on or set to color
domoticz.log('Round of color change complete when light started on or set to color')
else
--Log that light is not in the right state
domoticz.log('Not in the right state. Current State: '.. light.state)
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 colors displayed can be easily changed as well. If you want to substitute a different color, you can find the 6-digit hex value by going to the light switch, choosing the Edit button, choosing a color on the color wheel, and the 6-digit hex value will be shown underneath the wheel. Then, use the new hex value in the setHex function.
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!