Announcement

Collapse
No announcement yet.

Circadian Lighting for Aeon Labs RGB Bulb

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Circadian Lighting for Aeon Labs RGB Bulb

    Was playing around this morning to work out a script that can control my Aeon Labs RGB bulbs (model ZW098). I'd like these bulbs to shift from cooler colors to very warm (basically red) colors based on time of day, similar to what apps like f.lux do for computer screens.

    As a disclaimer - these bulbs aren't very good. Compared to the wifi bulbs on the market the colors and brightness are terrible - but it is the only zwave option I am aware of.

    Anyway, the hardest part was figuring out how to set the RGB values in a single CAPI call (requires use of a different property). This first draft of the script is designed to just run on an interval (30 minutes) and based on the time of day it will iterate through the list of bulbs defined and set them to one of three colors (two defined colors using the RGB values, and one 'warm white' property that turns on the brighter white led's in the bulb).

    I'm working now to make this calculate more of a sine wave and adjusts finer colors throughout the day, slightly shifting every interval to the ideal color -- but this will give you some ideas if you are hoping to control this bulb.

    In this rough version you just add device.Add() calls, each with the name of the RGB device and the name of the Warm White device for that bulb. Two bulbs are listed in this example.

    Code:
    using System.Collections.Generic;
    using HomeSeerAPI.CAPI;
    
    const int SunriseWindowHours = 1;
    
    public object Main(object[] Parms)
    {
    	try
    	{
    
    		hs.WriteLog("Info","Circadian Lighting Script Running");
    
    		// Devices
    		List<Tuple<string, string>> devices = new List<Tuple<string, string>>();
    		
    		devices.Add(
    			new Tuple<string, string>(
    				"Office Custom RGB", 
    				"Office Color Control Warm_White Channel")
    			);
    
    		devices.Add(
    			new Tuple<string, string>(
    				"Office Fan Custom RGB", 
    				"Office Fan Warm_White Channel")
    			);
    
    		// Add more devices here...
    		
    		// Get sunrise, sunset and noon
    		DateTime sunrise = hs.SunriseDt;
    		DateTime sunset = hs.SunsetDt;
    		DateTime solarNoon = hs.SolarNoon;
    		DateTime current = DateTime.Now;
    
    
    		// Color constants
    		string colorSunriseSunset = "#ff9000";
    		string colorNight = "#ff5400";
    
    		// Configure devices
    		foreach(Tuple<string, string> device in devices)
    		{
    			int deviceReferenceRgb = hs.GetDeviceRefByName(device.Item1);
    			int deviceReferenceWarm = hs.GetDeviceRefByName(device.Item2);
    
    			// Are we within the sunrise/sunset window?
    			if (current.Subtract(sunrise).Duration().TotalHours < SunriseWindowHours)
    			{
    				SetWarmWhite(deviceReferenceWarm, false);
    				SetRgbColor(deviceReferenceRgb, colorSunriseSunset);
    			}
    			// Is it after sunset window?
    			else if (current >= sunset.Add(TimeSpan.FromHours(SunriseWindowHours)) || 
    					 current < sunrise.Subtract(TimeSpan.FromHours(SunriseWindowHours)))
    			{
    				SetWarmWhite(deviceReferenceWarm, false);
    				SetRgbColor(deviceReferenceRgb, colorSunriseSunset);
    			}
    			// Default to warm white for rest of the day
    			else
    			{
    				SetWarmWhite(deviceReferenceWarm, true);
    			}		
    		}
    
    		return 0;
    	}
    	catch (Exception ex)
    	{
    		hs.WriteLog("Error",ex.ToString());
    		return 1;
    	}
    }
    
    public void SetRgbColor(int device, string color) 
    {	
    
    	HomeSeerAPI.CAPI.CAPIControl capiControl;
    
    	capiControl = hs.CAPIGetSingleControl(
    		device, 
    		true, 
    		"Custom Color(value)", 
    		false, 
    		false);
    
        capiControl.ControlString = color;
        hs.CAPIControlHandler(capiControl);       
    }
    
    public void SetWarmWhite(int device, bool turnOn)
    {
    	HomeSeerAPI.CAPI.CAPIControl capiControl;
    
    	capiControl = hs.CAPIGetSingleControl(
    		device, 
    		true, 
    		"Warm White Level (value)", 
    		false, 
    		false);
    
        capiControl.ControlValue = turnOn ? 200 : 0;
        hs.CAPIControlHandler(capiControl);
    }

    #2
    Wish I knew more about scripts. Dont know what to edit in this script to fit in with my Aeon Labs LEDs - 3 groups of 6 and 5 singles. (These lights feel excellent quality but the warm light is more cool than warm)

    At the moment I have setup various events to control these lights but there must be a more efficient way.

    Wonder if anyone with know-how is developing a plug-in for these lights?
    Last edited by Chris Jackson; February 11, 2017, 05:26 PM.

    Comment


      #3
      My attempt at controlling leds thru events
      Attached Files
      Last edited by Chris Jackson; February 11, 2017, 05:15 PM. Reason: figure too large

      Comment

      Working...
      X