Skip to content

Instantly share code, notes, and snippets.

@gousiosg
Last active December 9, 2020 10:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gousiosg/ee942ceb91095875f526 to your computer and use it in GitHub Desktop.
Save gousiosg/ee942ceb91095875f526 to your computer and use it in GitHub Desktop.
Set color of a Hue lightbulb based on fine-grained rain information
#!/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
@gousiosg
Copy link
Author

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 :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment