Working Milight, Astro, on a sunset off at sunrise

I just wanted to share my success with getting milight, astro, and a rule to work. I’m not claiming I’m an expert or even if this is actually the right way to do this, but it is currently working.

1 - You need the binding.milight and the binding.astro file in your addons folder. DO NOT put the action.astro and action.milight file in the addons folder.

2 - Configure your .cfg

################################# Astro Binding #######################################
#
# The latitude
astro:latitude=37.284540

# The longitude
astro:longitude=-80.042137

# Refresh interval for azimuth and elevation calculation in seconds
# (optional, defaults to disabled)
astro:interval=180

################################### Milight Binding ###################################
#
# Host of the first Milight bridge to control
milight:MilightId1.host=10.0.0.194
# Port of the bridge to control (optional, defaults to 50000)
milight:MilightId1.port=8899
#
# Host of the second Milight bridge to control
#milight:<MilightId2>.host=
# Port of the bridge to control (optional, defaults to 50000)
#milight:<MilightId2>.port=

3 - items
for the items i have included a color picker, white light button, Discomode, and a speed controller. You can delete what you don’t need, but i wanted to show how to do as much as possible. I’m using the RGBW lights so i don’t think this will work exactly with just RGB, but you should only have to change a few things probably.

/////MiLight
//Front Porch Lights
Switch porchLights    {milight="MilightId1;7;whiteMode"}
Color Light_Party           {milight="MilightId1;6;rgb"}
Switch White           {milight="MilightId1;6;whiteMode"}
Dimmer DiscoMode        {milight="MilightId1;6;discoMode"}
Dimmer DiscoSpeed       {milight="MilightId1;6;discoSpeed"}

//Time - Astro
//// shows the sunrise
DateTime Sunrise_Time   "Sunrise [%1$tl:%1$tM %1$tp]"  {astro="planet=sun, type=rise, property=start"}
DateTime Sunset_Time    "Sunset [%1$tl:%1$tM %1$tp]"   {astro="planet=sun, type=set, property=end"}
Switch   Sunrise_Event                           {astro="planet=sun, type=rise, property=start, offset=0"}
Switch   Sunset_Event                            {astro="planet=sun, type=set, property=end, offset=0"}

4 - Sitemap

//Front Porch Lights
	Frame label="Front Porch Lights"{
		Switch item=porchLights label="Front Porch Lights"
		Colorpicker item=Light_Party
		Switch item=White mappings=[ON="White"]
		Switch item=DiscoMode mappings=[INCREASE='Next Disco Mode']
		Switch item=DiscoSpeed mappings=[DECREASE='Slower', INCREASE='Faster']

	}

5 - Rules

rule "Example Rule at sunrise"
when
    Item Sunrise_Event received update ON
then
    sendCommand(porchLights, OFF)
end

rule "Example Rule at sundown"
when
    Item Sunset_Event received update ON
then
    sendCommand(porchLights, ON)
end

I hope this helps someone struggling like i was and i may need to refer back to it later to fix what I’ve managed to muck up :smiley:

1 Like

Thanks for posting this.

Am using similar code for outdoor lights along with some rgbw lights wherea random color is picked along with the lights getting brighter with a small delay.

Great work, very well written.

1 Like

Thanks. :smiley: glad it was able to help.

Thanks for this guide. Do you have a script to use with milight bulbs to mimic sunrise at set time in the morning ?