Integrating my weather station with openHAB REST API (via pywws)

800 views
Skip to first unread message

Ben Jones

unread,
May 30, 2013, 7:20:03 PM5/30/13
to ope...@googlegroups.com
Hey guys,

Thought I would share this. I have a weather station of the type that interfaces with pywws via USB. I had been integrating this with openHAB by configuring pywws to upload hourly weather data to Wunderground, and then querying this back into openHAB using the HTTP binding and XSLT transforms.

However I decided this wasn't the ideal solution since I had all the data on my local network so why send it all the way to Wunderground only to query it back again!? Also, there was no way of retrieving the indoor temp/humidity since the Wunderground API doesn't report it back when querying.

So I hacked into the pywws code and added an extra 'task' to the processing loop. So now every hour when pywws retrieves the weather station data, processes it, and uploads to Wunderground, it also sends a series of REST API status updates to openHAB to update my weather items directly.

You can configure what data to send to openHAB and which item they should be sent to, via configuration in the weather.ini file.

I.e. temp_in = WeatherTempIn
      temp_out = WeatherTempOut

where WeatherTempIn and WeatherTempOut are openHAB items.

I still query Wunderground for forecasts and 'condition icons' however all my temps, humidities and rainfalls come directly from pywws.

Cheers,
Ben

Richard Trenchard

unread,
Oct 14, 2013, 11:01:11 AM10/14/13
to ope...@googlegroups.com
Hi Ben

Can you tell me how you hacked the pywws code please as this sound exactly what im lookking for

Cheers

Rich

Ben Jones

unread,
Oct 14, 2013, 3:04:57 PM10/14/13
to ope...@googlegroups.com
You will need to copy the attached files to your pywws install;

* Copy Tasks.py to /usr/local/lib/python2.7/dist-packages/pywws/
* Copy toopenhab.py to /usr/local/lib/python2.7/dist-packages/pywws/

Tasks.py overrwrites the existing one (so maybe make a backup first!). This will call the toopenhab.py python script which handles the updating of the openHAB REST API.

Finally, update your weather.ini file by adding the following (replacing None with the openHAB item names you want to update for each of the weather variables);

[openhab]
host = <openhab_host>
port = <openhab_port>
temp_in = None
hum_in = None
hum_out = None
temp_out = None
abs_pressure = None
wind_ave = None
wind_gust = None
wind_dir = None
rain = None
status = None
illuminance = None
uv = None

It has been a long time since I wrote this stuff, and it has been running without any intervention since, so I am going on memory here!

Good luck!!
Ben
toopenhab.py
Tasks.py

richard

unread,
Oct 15, 2013, 3:33:42 AM10/15/13
to ope...@googlegroups.com
Thanks very much I will give it a go 

Rich..
--
You received this message because you are subscribed to the Google Groups "openhab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openhab+u...@googlegroups.com.
To post to this group, send email to ope...@googlegroups.com.
Visit this group at http://groups.google.com/group/openhab.
For more options, visit https://groups.google.com/groups/opt_out.

nick balch

unread,
Aug 13, 2014, 10:45:41 AM8/13/14
to
Hi - sorry to re-awaken this old thread ... but I wanted to follow this procedure and enable OpenHab to be directly enabled by my (Maplin) weather station.

I get a couple of errors, however.

1) running the toopenhab.py command I get:

python -m toopenhab ~/weather/data
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/local/lib/python2.7/dist-packages/pywws/toopenhab.py", line 79, in <module>
    from . import DataStore
ValueError: Attempted relative import in non-package

2) the log file for pywws contains the following
15:35:07:pywws.DataLogger:Computer and weather station clocks disagree by 0:07:00 (H:M:S).
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/local/lib/python2.7/dist-packages/pywws/Hourly.py", line 111, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/pywws/Hourly.py", line 108, in main
    return Hourly(args[0])
  File "/usr/local/lib/python2.7/dist-packages/pywws/Hourly.py", line 79, in Hourly
    hourly_data, daily_data, monthly_data).do_tasks():
TypeError: __init__() takes exactly 6 arguments (8 given)


I upgraded to the latest version of pywws which overcame some usb IO errors
Am running on a raspberryPi (original image from http://www.weather.dragontail.co.uk/index.php?page=rasp_image , but upgraded via APT-GET etc)

Any pointers much appreciated

Ben Jones

unread,
Aug 13, 2014, 3:34:57 PM8/13/14
to ope...@googlegroups.com
Sorry been over a year since I used this code. The toopenhab.py library is designed to be run as a task/service from within pywws. Not sure it will work by just calling it directly.

nick balch

unread,
Aug 14, 2014, 4:44:54 AM8/14/14
to ope...@googlegroups.com
Hi - thanks Ben, thanks for replying.  It looks like the code in tasks.py (for example) has been refactored significantly compared to the one you modified and it's beyond me to understand the diff.

I am exploring setting up an OpenHab "service" via the template feature to submit to OpenHab's REST API.  I am not entirely sure how to construct that, but have asked over on the PYWWS group to see.

I have got something working using http URLs with CMD  though I don't think this is a recommended approach.

Ben Jones

unread,
Aug 14, 2014, 5:15:30 AM8/14/14
to ope...@googlegroups.com
Ok - hopefully they can help. Sorry but it was a bit of a hack to get it to work the first time - but from memory was just adding the toopenhab hook to the task handler code. Don't use pywws anymore so can't really help sorry. Good luck!
Reply all
Reply to author
Forward
0 new messages