I wanted to create a flexible Circadian light piston to automatically vary light level and temperature relative to sun position. I created this before I discovered the Circadian Daylight smart app (https://community.smartthings.com/t/circadian-daylight-smartthings-smart-bulbs/13623).
Though this piston is relatively specific to my implementation, I wanted to put it up here as a starting point for others to demonstrate you don’t need to use a separate smart app for this use case. Use webCoRE where possible!
This piston does two things:
-
Every 5 minutes, sets global variables {@lightTemperature} and {@lightLevel} for the current light level and temperature based on time of day. In your individual light pistons, use these global vars to set lights as appropriate when turning on lights via scheduled/triggered routines.
-
Every 5 minutes, with all lights that are currently on, fade all the lights in {lightsAll} to the current {@lightTemperature} and {@lightLevel}. If you don’t want this part of the script and just want to use the @lightTemperature and @lightLevel vars in other pistons, delete the entire ‘if’ statement starting at line 153. NOTE: Changing the color temperature with lights in this section will override any colors or fading activities set with other pistons.
Variables you need to set and changes needed for this to work:
* {lightsAll}, line 21 - this is all the light devices you want to use circadian lights
* {lightsAllNoFades}, line 23 - this piston will overwrite any light fading activities set in other pistons. So I use this variable for my list of lights that never use fades.
* {hourMaxStart} / {hourMaxEnd}, line 26/27 - some people like the 'peak' of circadian hours to be longer. this will define the hour range for that peak time (defaults to 10 AM - 1 PM)
* {@lightTemperatureMin}, global integer variable - the minimum light temperature you want to use for sunset->sunrise. I use 2237. lowest reasonable amount would be 1900.
* {@lightTemperatureMax}, global integer variable - the maximum light temperature you want to use for peak times. I use 6500. highest reasonable amount would be 6500.
* {@lightLevelDay}, global integer variable - the maximum light level to use during the day. 100 is common.
* {@lightLevelEvening}, global integer variable - the minimum light level to use during the evening. 80-100 is common. I use 90.
* {@lightLevelNight}, global integer variable - the minimum light level to use at night when you are asleep. I use 20.
* {@timeBedtimeWeekday}, global time variable - time you go to bed on weekdays
* {@timeBedtimeWeekend}, global time variable - time you go to bed on weekends
* {@timeSleepWeekday}, global time variable - time you go to sleep on weekdays
* {@timeSleepWeekend}, global time variable - time you go to sleep on weekends
* {@timeWakeWeekday}, global time variable - time you wake up on weekdays
* {@timeWakeWeekend}, global time variable - time you wake up on weekends
* the 'if' conditions in line 138-144 - these are pretty specific to my implementation about when to set level/temperature for {lightsAll} vs {lightsAllNoFades}. if you don't need to use {lightsAllNoFades} you can move the 'with' statement at line 146 to line 137 and delete this entire 'if' statement at line 137, or you can modify this meet your needs. Some people use location modes here instead of time to set level/temperature different groups of lights. Another common implementation is define a list of switches that, if on, i want to ignore changing the light temperature/level, and you would put that here.
Improvements welcome!