Now that Osram Lightly fully works, i would like to randomly change the color of my garden lights every few hours when the sun is down. Is there away to do this?
I have been thinking of doing something similar to this (but have a light have a different color every day, instead)
I don’t actually have the light connected to HASS yet, but when I do, this is how I think I would tackle this problem:
I would have an external script (python or other) generate a random color, which HASS would read as a sensor value.
The sensor would be hidden, of course.
Then it’s simply a matter of setting the light to the sensor value.
As far as I know, HASS does not have a randomizer component/function.
Good luck, and if you find another way, plese let me know!
Chris
Getting the sensor working was way too easy.
Did you ever get this to work @spoonman ? I have the gardenspots too and I’d love to be able to do this!
Maybe a bit late, but here’s my implementation:
Firstly, I have a python script which generates a random color for each minute of the day, gravitating towards combinations of two colors. (purple, cyan, etc).
This returns a json encoded string containing r, g,b values.
#!/usr/bin/python
import random
import datetime
r=0
g=0
b=0
#select which colors are created
seed=(datetime.datetime.today().day*datetime.datetime.today().month+datetime.datetime.today().year/(datetime.datetime.today().hour+1))*(datetime.datetime.today().minute+1)
random.seed(seed)
maincolor=random.randint(1,3)
secondcolor=random.randint(1,3)
thirdcolor=random.randint(1,3)
if maincolor==1:
r=random.randint(200,255)
elif maincolor==2:
g=random.randint(200,255)
else:
b=random.randint(200,255)
if secondcolor!=maincolor:
if secondcolor==1:
r=random.randint(0,255)
elif secondcolor==2:
g=random.randint(0,255)
else:
b=random.randint(0,255)
if thirdcolor!=maincolor:
if thirdcolor!=secondcolor:
if thirdcolor==1:
r=random.randint(0,125)
elif thirdcolor==2:
g=random.randint(0,125)
else:
b=random.randint(0,125)
print "{\"r\":\""+str(r)+"\",\"g\":\""+str(g)+"\",\"b\":\""+str(b)+"\"}"
Then in my configuration.yaml:
sensor 3:
- platform: command_line
name: random_red
command: "/home/chris/randomcolor.py"
value_template: '{{ value_json.r }}'
- platform: command_line
name: random_green
command: "/home/chris/randomcolor.py"
value_template: '{{ value_json.g }}'
- platform: command_line
name: random_blue
command: "/home/chris/randomcolor.py"
value_template: '{{ value_json.b }}'
As the script will return the same value for an entire minute, the r, g, b values are coherent (meaning they remain the same relation created by the script).
Then I have the following automation:
automation:
- alias: Turn on led strip when the sun sets
trigger:
platform: sun
event: sunset
offset: "02:30:00"
condition:
condition: state
entity_id: group.residents
state: 'home'
action:
service: script.turn_on
entity_id: script.random_bed_led
Which calls the following script:
script:
random_bed_led:
sequence:
- service: light.turn_on
data_template:
entity_id: light.bed_led_strip
rgb_color: ['{{states.sensor.random_red.state}}','{{states.sensor.random_green.state}}','{{states.sensor.random_blue.state}}']
brightness: 225
The reason I put this in a separate script is because I also want to be able to reapply a random color outside of the automation, and calling this script applies the colour generated for this minute.
You can obviously tailor this to suit your needs.
I hope this helps
Kind regards,
Chris
Who cares if you’re ‘late’? I’m appreciative that you took the time to post this and I’m going to try it out! Thanks!!
My HASS installation has pretty much been running ‘as-is’ for a while as I didn’t have much time to tinker with it. But now I’ve got more time I’ve subsequently opened up the forum again.
Let me know if you’ve managed to get it to work!
I justed checked the code of osramlightify component, and there is a random effect implemented. I dont have set up anythin yet, but you can test it with the Services developer tool at the bottom left (the remote) of tha HA webinterface.
Domain: light Service: turn_on Service data: {"entity_id" : "light.beamer", "effect":"random"}
adjust entity_id
to your needs or leave it out and click: Call Service
I wonder if this would work when called via an automation? I’ll have to try this.
I think it will. I will look into how I can make a button with this soonish.
okay, this gives you a button in the gui to change the color randomly
script:
random_color:
sequence:
- service: light.turn_on
data:
effect: random
Going to try this later and will report back. No point until sundown anyway!
I just realized tonight when looking at my lights (at the same color as yesterday) that this wouldn’t work for me because my lights go through a Wink Hub instead of the Lightify Gateway. Unless I get the gateway - which I have been considering - the only method for me would be templating the color value.
I’m starting to think about how to do this with AppDaemon…
Thanks for you advice though!
I’m sorry for being a newb but how do i actually create the script. i see a file named scripts.yaml should it start with script: or should it start with the name of my script at the top of the file?
I just got some osrams and am trying to get them to randomize but cant figure it out and this seems to be the closest solution for my needs/ wants lol.
Thanks if you’re still out there!