It's an old thread, but I'm taking a look at doing something like this so 
wanted to post some of my observations (from doing the same thing for my 
Airspace whole house fan earlier today). I'm probably going to take a stab 
at modifying this code when I get a few spare cycles.

There are two big challenges with sending data to the ISY:

   1. You can't use named variables
   2. You can only send integer and boolean data

The first thing I had to do with my airspace code was to get a list of all 
of the variables currently in use on my ISY, you get that from querying the 
/rest/vars/definitions/x endpoint, where 'x' is 1 for integer variables and 
2 for booleans. That will give you an XML blob back that you can parse to 
get the variable indices the you need in order to send data.

Once you have those, you can then post data to the /rest/vars/set/x/y/z 
endpoint. X has the same values as above (eg. 1 for integer), y is the 
index of the variable, and z is the integer value.

As an example, here is the XML I get back if I query for integer variables 
on my ISY. You'll notice these are all named whf_foo, since those are my 
whole house fan vars:
<CList type="VAR_INT"><e id="1" name="whf_house_temp" /><e id="2" name=
"whf_attic_temp" /><e id="3" name="whf_oa_temp" /><e id="4" name=
"whf_setpoint" /><e id="5" name="whf_timeremaining" /><e id="6" name=
"whf_fanspd" /></CList>
So for me to set the attic temperature to 106 (which it was an hour or so 
ago), I would use /rest/vars/set/1/2/106.

All of the ISY REST endpoints are authenticated as well, so that adds 
another layer of fun to using urllib2.

On Tuesday, December 15, 2015 at 6:51:07 PM UTC-8, mwall wrote:
>
> On Tuesday, December 15, 2015 at 8:54:50 PM UTC-5, Mike Dove wrote:
>>
>>
>> Thanks for the quick reply.  I have the ISY side handled (I push in other 
>> data into ISY variables all the time via 
>> /rest/vars/set/<var-type>/<var-id>/<value>), 
>> so the question posed is really about the best way to retrieve specific 
>> weather data from weewx or the sqlite database directly (for example, the 
>> last archived value for extraTemp1).  Once I have the data, I know what to 
>> do with it, I'm simply using it to set a state variable (SpaTemperature) 
>> which an existing ISY program will use to turn on/off the spa.
>>
>
> you must decide whether you want isy to pull the data (in which case you 
> would write an extension to isy or have weewx emit something that is 
> compatible with an existing isy module), or weewx to push the data (in 
> which case you probably want a weewx restful service).
>
> a weewx restful service that pushes all of the archive observations at 
> each archive interval looks something like the code below (untested).  if 
> you want data more often, it is trivial to push all loop observations 
> whenever you get new data from the station.  the example below uploads each 
> observation separately; it would be better to upload them all in a single 
> GET request, but it is not clear from the ISY docs whether that is possible.
>
> import Queue
> import time
> import urllib
> import urllib2
>
> import weewx
> import weewx.restx
> import weewx.units
> from weeutil.weeutil import to_bool, accumulateLeaves
>
> # define the ISY uploader class.  to use it, specify a section in
> # weewx config file like this:
> #
> # [ISY]
> #     server_url = http://isy.example.com
> #
> class ISYUploader(weewx.restx.StdRESTbase):
>     def __init__(self, engine, config_dict):
>         super(ISYUploader, self).__init__(engine, config_dict)
>         try:
>             site_dict = config_dict['StdRESTful']['ISY']
>             site_dict = accumulateLeaves(site_dict, max_level=1)
>             site_dict['server_url']
>         except KeyError, e:
>             logerr("Data will not be posted: Missing option %s" % e)
>             return
>         site_dict['manager_dict'] = weewx.manager.get_manager_dict(
>             config_dict['DataBindings'], config_dict['Databases'], 
> 'wx_binding')
>         self.archive_queue = Queue.Queue()
>         self.archive_thread = ISYThread(self.archive_queue, **site_dict)
>         self.archive_thread.start()
>         self.bind(weewx.NEW_ARCHIVE_RECORD, self.new_archive_record)
>
>     def new_archive_record(self, event):
>         self.archive_queue.put(event.record)
>
> # define the thread that does the actual uploads.  this simply adds the
> # server_url field to the base class RESTThread.
> class ISYThread(weewx.restx.RESTThread):
>     def __init__(self, queue, server_url, manager_dict,
>                  post_interval=None, max_backlog=sys.maxint, stale=None,
>                  log_success=True, log_failure=True,
>                  timeout=60, max_tries=3, retry_wait=5):
>         super(ISYThread, self).__init__(queue,
>                                         protocol_name='ISY',
>                                         manager_dict=manager_dict,
>                                         post_interval=post_interval,
>                                         max_backlog=max_backlog,
>                                         stale=stale,
>                                         log_success=log_success,
>                                         log_failure=log_failure,
>                                         max_tries=max_tries,
>                                         timeout=timeout,
>                                         retry_wait=retry_wait)
>         self.server_url = server_url
>
>     def process_record(self, record, dbm):
>         r = self.get_record(record, dbm)
>         # post each observation in a var-type called 'weather'.  for 
> example,
>         # weather/inTemp/45.6 or weather/windSpeed/32.6
>         for k in r:
>             url = "%s/rest/vars/set/weather/%s/%s" % (self.server_url, k, 
> r[k])
>             req = urllib2.Request(url)
>             req.get_method = lambda: 'GET'
>             req.add_header("User-Agent", "weewx/%s" % weewx.__version__)
>             self.post_with_retries(req)
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to