Thanks, I ended up doing something similar but using Python and the REST API instead. It seems to be working, and with no drama about the encoding.
It might be heretical, but I can see a lot of advantages to this approach. I’ve spent a lot of time trying to decipher the nuances of the not-quite-Java, not-quite-Xtend DSL used for rules, and it’s definitely a lot easier to find answers to the same questions for Python.
Rule:
/*** Update weather from Environment Canada ***/
rule "Update EC weather"
when
Time cron "0 0/5 * * * ?"
then
executeCommandLine('python /etc/openhab2/rules/ec-weather.py', 10000)
end
Python:
import requests
from xml.etree import ElementTree
### Fetch data and extract values ###
response = requests.get('http://dd.weatheroffice.ec.gc.ca/citypage_weather/xml/ON/s0000430_e.xml')
xml = ElementTree.fromstring(response.content)
temp = xml.find('./currentConditions/temperature').text
humidity = xml.find('./currentConditions/relativeHumidity').text
windChill = xml.find('./currentConditions/windChill').text
forecastLow = xml.find('.//forecast/temperatures/temperature[@class="low"]').text
### Update OpenHAB items via REST API ###
s = requests.Session()
s.headers = {"Content-Type": "text/plain", "Accept": "application/json"}
s.put(url="http://192.168.0.121:8080/rest/items/Temperature/state", data = str(temp))
s.put(url="http://192.168.0.121:8080/rest/items/Humidity/state", data = str(humidity))
s.put(url="http://192.168.0.121:8080/rest/items/WindChill/state", data = str(windChill))
s.put(url="http://192.168.0.121:8080/rest/items/ForecastLow/state", data = str(forecastLow))