Change RGB bulb color based on local outside temperature


#21

I love this piston, it works great using my outdoor temperature sensor and one Trådfri RGB-light.

The only thing I would like to change and that I can’t accomplish is how to skip the green range of colors?

My temperature range is -20C to +30C and the hottest and coldest 10-15 degrees are great since they move within the blue and red color space. If possible I would like cold white color at 0 degrees C and everything below shoud go from white to dark blue and everything above from white through yellow to red.

Is this possible using rainbowValue or combining it with something else?


#22

Hmm, you might try framing the expression into two segments. One rainbowvalue for everything between -30C (-22F) and ~15C (60F), and another between 15C (60F) and 38C (100F). Basically you could skip past the green stuff with a new rainbowvalue path.


#23

Thank you for your reply!

I have tried, but most of the time it just gets stuck at what I’m guessing #FFFFFF. What way through the colorspace does rainbowvalue take? Is it through a color wheel or something else?

Any advice on what hex to use for blue to white and white through yellow to red? :slight_smile:


#24

I think it’s just ROYGBIV… So if you want blue–>white–>yellow–>red, you might split it into 3 parts.

Part one blue to white #0000FF thru #FFFFFF
Part two white to yellow: #FFFFFF thru #FFFF00
Part three yellow to red: #FFFF00 thru #FF0000 (this will also pass through orange)

Those are pure colors, btw, if you want any particular shade you’d have to customize a bit.


#25

Thank you very much for your help!
I’m not good at this so I really appreciate it. :slight_smile:

This expression runs without errors, but I’m guessing I have to do it another way since the light stays white no matter what the temperature is. If I just use one rainbowvalue it changes color so the rest of the Piston is set up correcly. Do I have to make three different expressions to get it running?

Cheers!


#26

I’m not able to experiment at the moment but I think you can put it all in one expression using a ternary operator:

https://wiki.webcore.co/Expressions#Ternary_operator_.28_c_.3F_t_:f.29

Paging @bangali


#27

try this for the set color to statement:

(temp > 0 ? rainbowValue(temp, 0, ‘#FFFFFF’, 30, ‘#FF0000’) : rainbowValue(temp, -20, ‘#0000FF’, 0, ‘#FFFFFF’))


#28

Big thanks! That did the trick.


#29

can you post the whole code? :slight_smile:


#30

Of course!


#31

Thanks :slight_smile:


#32

Hello,

i need help with my RGB controllers.

  1. If one RGB Controller change the color to …
  2. All RGB Controllers also going to switch to the same color.

Any Idea´s to realice this in a Piston?


#33

Great job


#34

Thanks for this. It was really helpful for a similar issue I was having with webcore. Google brought me here.


#35

Hey, I’m working with your piston and I was trying to understand if it will actually update the color once the light is on or will it remain the same color even as the temp changes? I was trying to tweak yours to make sure it updates on temp changes but have not had any luck.


#36

No, it will only set the color when the switch changes to on. If you want it to change dynamically you could probably use a “while” statement. Or set it to change every 10 minutes while on.


#37

I have been having trouble trying to get it to update at a set interval or on temp changes. Were you able to get it to work on yours? Either solution would work for me I just can’t seem to get it to work.


#38

I have not tried it here, since my light is usually only on for no more than 20 minutes at a time. Can you post your piston?


#39

I think I got it working now. It turns on the RGB bulb when any of my Harmony events is on (tv, playstation, music) and sets the color based on the current temperature in relation to the forecast low and high for the day. I tweaked that to give more variety throughout the day. It then updates the color every 5 minutes while the bulb is still on.

I haven’t run it for a full day yet so I don’t know how well it will run.


#40