Page 1 of 1

Setting temperature variables from a raspberry pi

PostPosted: Thu Jan 01, 2015 6:52 pm
by noel1983
Hi all,
I'm sure this must be answered somewhere but afraid Im not finding it!
I'm looking to use some one wire temperature sensors running into a raspberry pi that I want to send into indigo variables.

My question is how do I get the data from the pi into indigo? Is there an easy way to do this?

It's likely that this is proof of concept and if it all works I may then invest in sensors and interfaces to begin a zwave journey however until I know the temperature variance I can't tell if it warrants investing in sensors and controls to save heating bills etc! Although it's all good fun regardless!

Any advice greatly appreciated
Thanks
Noel

Re: Setting temperature variables from a raspberry pi

PostPosted: Fri Jan 02, 2015 10:29 am
by jay (support)
In general, there are two approaches: have the rPi push the data to Indigo or have Indigo pull the data from the rPi.

The first would require you to use Indigo's RESTful API to push values to Indigo variables. This is probably the easiest if you already have some code running on the rPi that triggers based on input changes.

There are a bunch of different ways to do the second (script, plugin, etc), all of which requires the rPi to present some kind of API that Indigo can call. If you have a web server running on the rPi that you can hit to get the data, then you can just create a script that periodically polls the URL and updates variables with the data.

Re: Setting temperature variables from a raspberry pi

PostPosted: Fri Jan 02, 2015 12:01 pm
by noel1983
Thanks Jay,
Suspect the second option be better as I'm slightly more comfortable with scripting that things on the pi.

Have you any examples or pointers of anything similar?
Thanks
Noel

Re: Setting temperature variables from a raspberry pi

PostPosted: Fri Jan 02, 2015 2:00 pm
by forestfield
I've just done this very thing on my pi, using a variable on the indigo

Note that I'm not (yet) using any authentication on the server; so the extract below doesn't account for this

python snippet...

Code: Select all

import urllib2

INDIGO_SET = 'http://indigo-server:8176/variables/{}?_method=put&value={}'

temp = someValue
indigoName = 'my%20temp'     # Note spaces in variable names are url escaped

url = INDIGO_SET.format(indigoName, value)
print ("Url: {}".format(url))

try:
  result = urllib2.urlopen(url)
  print("Result: {}".format(result.info()))
except Exception as e:
  print("Error setting Indigo variable {}".format(e))



I'm sure there are better ways to do this, like build a device, but I haven't climbed that learning curve yet

Re: Setting temperature variables from a raspberry pi

PostPosted: Fri Jan 02, 2015 2:33 pm
by jay (support)
noel1983 wrote:
Thanks Jay,
Suspect the second option be better as I'm slightly more comfortable with scripting that things on the pi.

Have you any examples or pointers of anything similar?


Without knowing how you communicate over the network with the rPi then I can't really point you to anything...

Re: Setting temperature variables from a raspberry pi

PostPosted: Fri Jan 02, 2015 2:42 pm
by noel1983
Hi forest field
Awesome thank you, could you add a little more info around what you are using on the pi to record the temps?

My pi knowledge is almost zero but I can ssh and get to grips with most things with the right Google searches!!

On the pi itself are you saving the code above as a script of some kind then setting a corn job to run it repeatedly?

Thanks again
Noel

Re: Setting temperature variables from a raspberry pi

PostPosted: Fri Jan 02, 2015 5:55 pm
by forestfield
Hi Noel,

The script I grabbed that snippet from is actually a 500+ line monster that reads several sensors on several pi's. I wrote it as an exercise in learning python, and using threading to handle each sensor separately. As a result it's pretty horrible, and perhaps off topic for the forum, though I'm happy to talk about the pi bits off-line (pm me). Also I actually don't have any 1-wire sensor's - I'm using either analog sensor's (DHT22), or an i2c board (TMP102), so I can't help with the 1-wire bit.

However there's a good example of some python code at https://learn.adafruit.com/downloads/pdf/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing.pdf. Have a look at the adafruit document, it's pretty much what you want to do; you'd just need to repave the final print with the urllib2 bit from my snippet.

Running the script as a cron job is a good idea initially - I started with a simple script that did this, and then it grew like topsy!

Hope that's been of some help.

-- Paul --