Change RGB bulb color based on local outside temperature


#1

I posted this on the old forum, but thought I’d repost it here. This uses an RGB bulb to change color based on the temperature outside. It uses SmartWeather device as the temperature sensor. Colors advance through the spectrum from 0F-100F, getting bluer for cold, redder for hot, and all in between. If it’s below 0 or above 100, the bulb flashes three times.

***** Edit:** There is a better updated version here that uses the rainbow value to make a gradient: Change RGB bulb color based on local outside temperature


Set Lamp Color Based on Temperature
#2

Go to the ST forum and search for rainbow - driving and can’t do much now - or other users around here can help, like @ahndee


#3

No help needed, this is an example piston :crazy_face:


#4

There is a better way, a function that gives you the color automatically - give it a range of values, a range of colors, and a current value, and it gives you a nice color from a rainbow spectrum.


#5

Aha, cool. Having trouble finding it…


#6

It’s rainbowValue(). The Weather Tiles on the wiki use it for the rule background color: https://wiki.webcore.co/Samples#Weather_Tiles


#7

Coooooool. Does this look correct?

that would be:

rainbowValue(useCelsius ? avg($weather.forecast10day.forecast.simpleforecast.forecastday[$index].low.celsius,$weather.forecast10day.forecast.simpleforecast.forecastday[$index].high.celsius) : avg($weather.forecast10day.forecast.simpleforecast.forecastday[$index].low.fahrenheit,$weather.forecast10day.forecast.simpleforecast.forecastday[$index].high.fahrenheit), value_coldestTemp,color_coldestTemp,value_hottestTemp,color_hottestTemp)


#8

Okay, so this is cool, taking the 10-day average and converting it to a color, but is there a way to use the rainbow value on a current temperature? For instance, if it’s 80 degrees during the day here, and 50 at night, can the rainbowValue reflect that in “real time” ?

I’m not well versed in expressions yet, and having a tough time reading it.


#9

I had a similar desire, though I want a color temp bulb to become more towards the blue (this is at work) as the day progresses and then around 4 start shifting back towards warm - to motivate me to actually go home on time… :stuck_out_tongue:

Couldn’t get it to properly ‘transition’ over a multi-hour period - need to find a way to map values to number ranges that aren’t necessarily the same, i.e. 0-100 mapped to 0-255 etc.


#10

With my limited expression knowledge, it looks like it stores the 10 days temperatures into an index and then maps that between the two high/low values and colors. For a more current temperature display, we would need to narrow the window I think, but I’m not sure how to get it to choose from a gradient for only the current temp.


#11

try this for current temp. the first one is colors i use and the second is colors from your example piston:

rainbowValue($weather.conditions.current_observation.temp_f, 30, ‘#3d41ac’, 120, ‘#bf4545’)
OR
rainbowValue($weather.conditions.current_observation.temp_f, 30, ‘#e784ff’, 120, ‘#ff2020’)


#12

120? Do you live in Phoenix?


#13

i wanted it turn real red only if it gets that high which it never does. so, turns reddish but never red. :smile:


#14

Yep


#15

Works like a charm, thanks!


#16

you are welcome.


#17

@KiloWatts can you show us the finish webcore piston? Thanks I like it.


#18

Works like a charm. I have my colors on the richer side, but you can change the range to suit your needs.


Question about weather forecasts
#19

@KiloWatts Thanks for sharing. I have import the last one and it working good and I like the colors I also like the richer side as you said. Thanks


#20

I really like the concept of this piston, but I’d like to use the forecast high for the day. However, when you do the forecast, it returns 3 days and not just today.

$weather.forecast.forecast.simpleforecast.forecastday.high will return [[celsius:32, fahrenheit:89], [celsius:33, fahrenheit:92], [celsius:34, fahrenheit:94], [celsius:34, fahrenheit:94]]

Ideally I’d just use the .fahrenheit at the end to just get that, but I’m not sure how to handle the grouping like that. I was also looking to do an alert if there is rain/sleet/snow as well. Hopefully figuring out how to handle the list will help with that too.
Thanks!