Pulling Weather data from NOAA to set colors of Hue lamps

Posted on
Wed Dec 11, 2013 3:46 pm
Ankleshanker offline
Posts: 9
Joined: Jul 12, 2013

Pulling Weather data from NOAA to set colors of Hue lamps

Perhaps it was the fact this week is the Hour of Code. Or maybe it was finally having some consistent freezing temps. Either way, I felt moved to delve in to some Python scripting.

What I want to do:
I would like to pull the temp from my local NOAA plugin and use it to determine the color of a lamp in my living room...a visual representation of the approximate temp outside my house.

Broken code I came up with based on other examples:
Code: Select all
myWeatherStation = indigo.devices[##########]
temp = myWeatherStation['temperatureF']
plug = indigo.server.getPlugin("com.nathansheldon.indigoplugin.HueLights")

indigo.server.log (myWeatherStation.states['temperatureF'])

if temp <= "32":
   if plug.isEnabled():
      plug.executeAction("setRGB", indigo.devices["Hue Lamp 1"].id, props={"red":0, "green":0, "blue":255})
if temp <= "60" and temp > "30":
   if plug.isEnabled():
      plug.executeAction("setRGB", indigo.devices["Hue Lamp 1"].id, props={"red":0, "green":125, "blue":125})
if temp <= "80" and temp > "60":
   if plug.isEnabled():
      plug.executeAction("setRGB", indigo.devices["Hue Lamp 1"].id, props={"red":0, "green":255, "blue":0})
if temp temp > "80":
   if plug.isEnabled():
      plug.executeAction("setRGB", indigo.devices["Hue Lamp 1"].id, props={"red":255, "green":0, "blue":0})


Problems I see:
1. I don't know what I'm doing.
2. I don't know if the NOAA plugin reports the temp as a numeric value, because I can't get it to print to the log.
3. I'm not sure if I need to define the plugins for NOAA and HUE before I can do any of this.

Help appreciated!

- Ben

Posted on
Fri Dec 13, 2013 9:12 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Pulling Weather data from NOAA to set colors of Hue lamp

Hi Ben,

Change this from:

Code: Select all
temp = myWeatherStation['temperatureF']

to this:

Code: Select all
temp = float(myWeatherStation.states['temperatureF'])


And remove the quotes around the numbers in all of your conditionals:

Code: Select all
if temp <= "32":


to:

Code: Select all
if temp <= 32:


I'm not sure if there are other errors or not (I don't have a Hue). But if it doesn't work or gives an error then post the specifics about the error into a reply.

Image

Posted on
Mon Dec 16, 2013 9:19 pm
Ankleshanker offline
Posts: 9
Joined: Jul 12, 2013

Re: Pulling Weather data from NOAA to set colors of Hue lamp

Thank you for your help Matt,

With those changes I now get this error in the log:

Code: Select all
Dec 16, 2013 10:16:30 PM
Script Error                    embedded script: 'DeviceCmds' object is unindexable
Script Error                    Exception Traceback (most recent call shown last):

embedded script, line 1, at top level
TypeError: 'DeviceCmds' object is unindexable

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 11 guests