Last active
December 9, 2020 10:22
-
-
Save gousiosg/ee942ceb91095875f526 to your computer and use it in GitHub Desktop.
Set color of a Hue lightbulb based on fine-grained rain information
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'open-uri' | |
require 'json' | |
require 'hue' | |
delft="http://www.buienradar.nl/Json/RainForecast3Hours?lat=52.006&lon=4.355&weatherstationid=6344&streetlevel=false" | |
percipitation = JSON.parse(open(delft).read)['forecasts'][1]["precipation"] | |
sat = if percipitation < 2 | |
0 | |
elsif percipitation > 2 and percipitation <= 10 | |
percipitation * 10 + 50 | |
else | |
220 | |
end | |
client = Hue::Client.new | |
living_room = client.lights.find{|l| l.name == "Living room"} | |
if living_room.on? | |
living_room.set_state({:saturation => sat, :hue => 46920 }, 20) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will set the colour of the living room lightbulb to a shade of blue based on fine grained shower ('bui') information available at 5-min resolution from buienradar.nl. To extract the url for your city, go to buienradar.nl, search for your city and watch the browser do Ajax calls to URLs that look like the one for Delft. Saturation values are currently random, as no shower is forecasted for the next 3-4 days :-)