I’m just sharing a little Appdaemon script I came up with. I’m a bit proud, as this is my first Python script (ever), but also thought it may help others.
The hardware: I have two BR30 (can-style) front porch lights, into which I recently installed two OSRAM Lightify RGB BR30 bulbs connected to their gateway.
The challenge: In a few weeks, our Christmas decorations will go up, and my wife asked me if I could make our house a bit more festive by having the porch lights toggle between red and green.
I looked into doing this with normal HASS automation, but it seemed tricky, and I’ve been wanting to get my feet wet in Python and Appdaemon anyway.
Here’s the setup:
-
When the holiday light switch is switched on (which is an outdoor GE ZWAVE switch that goes to the string lights, inflatable Santa, etc), begin the red/green sequence, changing the color every 2 seconds (red for 2 seconds, then green for 2 seconds, etc).
-
When the holiday light switch is turned off (usually midnight), return the porch lights to soft white light (2700k) until a normal HASS automation turns them off just before sunrise.
I have both the individual bulbs in a group (group.porch_group).
It may not be the cleanest way to do this, but it does work. Hope it helps and comments welcome.
import appdaemon.appapi as appapi
class XmasPorchLights(appapi.AppDaemon):
def initialize(self):
self.showover = 0
self.listen_state(self.StartSequence, "switch.holiday_lights_switch")
def StartSequence(self, entity, attribute, old, new, kwargs):
if new == "on" :
self.showover = 0
self.run_in(self.ChangeToRed, 1)
if new == "off" :
self.showover = 1
def ChangeToRed(self, kwargs):
if self.showover == 0:
self.turn_on("group.porch_group", rgb_color = [255 , 0 , 0], brightness = 255)
self.run_in(self.ChangeToGreen, 2)
else:
self.turn_on("group.porch_group", kelvin = "2700", brightness_pct = 100)
def ChangeToGreen(self, kwargs):
if self.showover == 0:
self.turn_on("group.porch_group", rgb_color = [0 , 255 , 0], brightness = 255)
self.run_in(self.ChangeToRed, 2)
else:
self.turn_on("group.porch_group", kelvin = "2700", brightness = 255)