Hi Mark
Can you share what you’ve used? I cant seem to get anything more than the current temps/rain etc…
items/rules/Widget?
Ive been trying to piece together something but none of the solutions work out fo the box for me.
Cheers
Hi Mark
Can you share what you’ve used? I cant seem to get anything more than the current temps/rain etc…
items/rules/Widget?
Ive been trying to piece together something but none of the solutions work out fo the box for me.
Cheers
No worries - most of this is cribbed from people higher up in the thread, so no claim that it’s my work…
Widget code:
<div ng-init="ServerPath='//192.168.1.148:8081/static'; IconSet='underground'">
<link rel="stylesheet" type="text/css" href="{{ServerPath}}/layouts/example.css" />
</div>
<table id="weather-forecast-table" border=0 width="100%" style="table-layout: fixed">
<tr>
<td width=25% colspan=2 style="font-weight:bold;">Current Conditions</td>
<td rowspan=11 width=3%> </td>
<td> </td>
<td style="font-weight:bold;">Today</td>
<td style="font-weight:bold;">{{itemValue('ObservationTime_1') | date:'EEEE'}}</td>
<td style="font-weight:bold;">{{itemValue('ObservationTime_2') | date:'EEEE'}}</td>
<td style="font-weight:bold;">{{itemValue('ObservationTime_3') | date:'EEEE'}}</td>
</tr>
<tr><td> </td></tr>
<tr>
<td align="center" colspan=2><img width="100" src="{{ServerPath}}/images/{{IconSet}}/{{itemValue('CommonId').replace(' ','-') | lowercase }}.png"/>
<p style="font-weight:bold;">{{itemValue('Condition')}}</p></td>
<td> </td>
<td>
<img width="100" src="{{ServerPath}}/images/{{IconSet}}/{{itemValue('CommonId').replace(' ','-') | lowercase }}.png"/>
<p style="font-weight:bold;">{{itemValue('BOM_Precis_0')}}</p>
</td>
<td>
<img width="100" src="{{ServerPath}}/images/{{IconSet}}/{{itemValue('CommonId_1').replace(' ','-') | lowercase }}.png"/>
<p style="font-weight:bold;">{{itemValue('BOM_Precis_1')}}</p>
</td>
<td>
<img width="100" src="{{ServerPath}}/images/{{IconSet}}/{{itemValue('CommonId_2').replace(' ','-') | lowercase }}.png"/>
<p style="font-weight:bold;">{{itemValue('BOM_Precis_2')}}</p>
</td>
<td>
<img width="100" src="{{ServerPath}}/images/{{IconSet}}/{{itemValue('CommonId_3').replace(' ','-') | lowercase }}.png"/>
<p style="font-weight:bold;">{{itemValue('BOM_Precis_3')}}</p>
</td>
</tr>
<tr>
<td align=right width=7%>Temp: </td><td align=left> {{'%.1f' | sprintf:itemValue('WS2355_Temperature')}} °C</td>
<td style="text-align:right;color:#fff">Maximum </td>
<td class="col-xs-4" style="color:#fff">{{'%.0f' | sprintf:itemValue('BOM_Temp_Max_0')}} °C</td>
<td class="col-xs-4" style="color:#fff">{{'%.0f' | sprintf:itemValue('BOM_Temp_Max_1')}} °C</td>
<td class="col-xs-4" style="color:#fff">{{'%.0f' | sprintf:itemValue('BOM_Temp_Max_2')}} °C</td>
<td class="col-xs-4" style="color:#fff">{{'%.0f' | sprintf:itemValue('BOM_Temp_Max_3')}} °C</td>
</tr>
<tr>
<td align=right>Humidity: </td><td align=left> {{'%.0f' | sprintf:itemValue('WS2355_Humidity')}} %</td>
<td style="text-align:right;color:#fff">Minimum </td>
<td class="col-xs-4" style="color:#fff"></td>
<td class="col-xs-4" style="color:#fff">{{'%.0f' | sprintf:itemValue('BOM_Temp_Min_1')}} °C</td>
<td class="col-xs-4" style="color:#fff">{{'%.0f' | sprintf:itemValue('BOM_Temp_Min_2')}} °C</td>
<td class="col-xs-4" style="color:#fff">{{'%.0f' | sprintf:itemValue('BOM_Temp_Min_3')}} °C</td>
</tr>
<tr>
<td align=right>Rain today: </td><td align=left> {{'%.1f' | sprintf:itemValue('Rain_Today')}} mm</td>
<td style="text-align:right">Chance of Rain </td>
<td class="col-xs-4" style="color:#fff">{{itemValue('BOM_Precipitation_0')}}</td>
<td class="col-xs-4" style="color:#fff">{{itemValue('BOM_Precipitation_1')}}</td>
<td class="col-xs-4" style="color:#fff">{{itemValue('BOM_Precipitation_2')}}</td>
<td class="col-xs-4" style="color:#fff">{{itemValue('BOM_Precipitation_3')}}</td>
</tr>
<tr>
<td align=right>Wind: </td><td align=left> {{itemValue('WS2355_WindSpd')}} km/h {{itemValue('WS2355_WindDir')}}</td>
<td style="text-align:right">Pollen levels </td>
<td class="col-xs-4" style="color:#fff">{{itemValue('MelbPollen_today')}}</td>
<td class="col-xs-4" style="color:#fff">{{itemValue('MelbPollen_tomorrow')}}</td>
<td class="col-xs-4" style="color:#fff">{{itemValue('MelbPollen_f2')}}</td>
<td class="col-xs-4" style="color:#fff">{{itemValue('MelbPollen_f3')}}</td>
</tr>
<tr>
<td align=right>UV Index: </td><td align=left> {{'%.2f' | sprintf:itemValue('openuv_uvreport_local_UVIndex')}} ({{itemValue('UV_Range')}})</td>
<td style="text-align:right">Sunrise </td>
<td class="col-xs-4" style="color:#fff">{{itemValue('astro_sun_local_rise_start') | date:'HH:mm'}}</td>
<td class="col-xs-4" style="color:#fff"></td>
<td class="col-xs-4" style="color:#fff"></td>
<td class="col-xs-4" style="color:#fff"></td>
</tr>
<tr>
<td align=right>Air Quality: </td><td align=left> {{itemValue('AQ_description')}}</td>
<td style="text-align:right">Peak UV </td>
<td class="col-xs-4" style="color:#fff">{{itemValue('openuv_uvreport_local_UVMaxTime') | date:'HH:mm'}}</td>
<td class="col-xs-4" style="color:#fff"></td>
<td class="col-xs-4" style="color:#fff"></td>
<td class="col-xs-4" style="color:#fff"></td>
</tr>
<tr>
<td align=right></td><td align=left></td>
<td style="text-align:right">Sunset </td>
<td class="col-xs-4" style="color:#fff">{{itemValue('astro_sun_local_set_end') | date:'HH:mm'}}</td>
<td class="col-xs-4" style="color:#fff"></td>
<td class="col-xs-4" style="color:#fff"></td>
<td class="col-xs-4" style="color:#fff"></td>
</tr>
</table>
BOM items:
/*weather BOM */
Number BOM_AirTemp "Current Temp [%.1f °C]" <temperature> { http="<[http://www.bom.gov.au/fwo/IDV60901/IDV60901.95936.json:60000:JSONPATH($.observations.data[0].air_temp)]" }
Number BOM_ApparentTemp "Apparent Temp [%.1f °C]" <temperature> { http="<[http://www.bom.gov.au/fwo/IDV60901/IDV60901.95936.json:60000:JSONPATH($.observations.data[0].apparent_t)]" }
DateTime BOM_Date_0 "Observation time [%1$td.%1$tm.%1$tY %1$tH:%1$tM]"
DateTime BOM_Date_1 "Observation time [%1$td.%1$tm.%1$tY %1$tH:%1$tM]"
DateTime BOM_Date_2 "Observation time [%1$td.%1$tm.%1$tY %1$tH:%1$tM]"
DateTime BOM_Date_3 "Observation time [%1$td.%1$tm.%1$tY %1$tH:%1$tM]"
DateTime BOM_Date_4 "Observation time [%1$td.%1$tm.%1$tY %1$tH:%1$tM]"
DateTime BOM_Date_5 "Observation time [%1$td.%1$tm.%1$tY %1$tH:%1$tM]"
DateTime BOM_Date_6 "Observation time [%1$td.%1$tm.%1$tY %1$tH:%1$tM]"
DateTime BOM_Date_7 "Observation time [%1$td.%1$tm.%1$tY %1$tH:%1$tM]"
Number BOM_Temp_Max_0 " max Today [%.2f °C]" <temperature> (Weather)
Number BOM_Temp_Min_0 " min Today [%.2f °C]" <temperature> (Weather)
//String BOM_Precipitation_Range_0 " Rain today [%s]" (Weather)
String BOM_Precipitation_0 "Precip probability today [%s]" (Weather)
Number BOM_Forecast_Icon_Code_0 " Icon Code Today [%d]" (Weather)
String BOM_Precis_0 " Condition Today [%s]" (Weather)
Number BOM_Temp_Max_1 "Forecast max tomorrow [%.2f °C]" <temperature> (Weather)
Number BOM_Temp_Min_1 "Forecast min tomorrow [%.2f °C]" <temperature> (Weather)
String BOM_Precipitation_Range_1 "Forecast Rain tomorrow [%s]" (Weather)
String BOM_Precipitation_1 "Precip probability tomorrow [%s]" (Weather)
Number BOM_Forecast_Icon_Code_1 "Forecast Icon Code tomorrow [%d]" (Weather)
String BOM_Precis_1 "Forecast Condition tomorrow [%s]" (Weather)
Number BOM_Temp_Max_2 "Forecast max tomorrow [%.2f °C]" <temperature> (Weather)
Number BOM_Temp_Min_2 "Forecast min tomorrow [%.2f °C]" <temperature> (Weather)
String BOM_Precipitation_Range_2 "Forecast Rain tomorrow [%s]" (Weather)
String BOM_Precipitation_2 "Precip probability tomorrow [%s]" (Weather)
Number BOM_Forecast_Icon_Code_2 "Forecast Icon Code tomorrow [%d]" (Weather)
String BOM_Precis_2 "Forecast Condition tomorrow [%s]" (Weather)
Number BOM_Temp_Max_3 "Forecast max tomorrow [%.2f °C]" <temperature> (Weather)
Number BOM_Temp_Min_3 "Forecast min tomorrow [%.2f °C]" <temperature> (Weather)
String BOM_Precipitation_Range_3 "Forecast Rain tomorrow [%s]" (Weather)
String BOM_Precipitation_3 "Precip probability tomorrow [%s]" (Weather)
Number BOM_Forecast_Icon_Code_3 "Forecast Icon Code tomorrow [%d]" (Weather)
String BOM_Precis_3 "Forecast Condition tomorrow [%s]" (Weather)
Number BOM_Temp_Max_4 "Forecast max tomorrow [%.2f °C]" <temperature> (Weather)
Number BOM_Temp_Min_4 "Forecast min tomorrow [%.2f °C]" <temperature> (Weather)
String BOM_Precipitation_Range_4 "Forecast Rain tomorrow [%s]" (Weather)
String BOM_Precipitation_4 "Precip probability tomorrow [%s]" (Weather)
Number BOM_Forecast_Icon_Code_4 "Forecast Icon Code tomorrow [%d]" (Weather)
String BOM_Precis_4 "Forecast Condition tomorrow [%s]" (Weather)
Number BOM_Temp_Max_5 "Forecast max tomorrow [%.2f °C]" <temperature> (Weather)
Number BOM_Temp_Min_5 "Forecast min tomorrow [%.2f °C]" <temperature> (Weather)
String BOM_Precipitation_Range_5 "Forecast Rain tomorrow [%s]" (Weather)
String BOM_Precipitation_5 "Precip probability tomorrow [%s]" (Weather)
Number BOM_Forecast_Icon_Code_5 "Forecast Icon Code tomorrow [%d]" (Weather)
String BOM_Precis_5 "Forecast Condition tomorrow [%s]" (Weather)
Number BOM_Temp_Max_6 "Forecast max tomorrow [%.2f °C]" <temperature> (Weather)
Number BOM_Temp_Min_6 "Forecast min tomorrow [%.2f °C]" <temperature> (Weather)
String BOM_Precipitation_Range_6 "Forecast Rain tomorrow [%s]" (Weather)
String BOM_Precipitation_6 "Precip probability tomorrow [%s]" (Weather)
Number BOM_Forecast_Icon_Code_6 "Forecast Icon Code tomorrow [%d]" (Weather)
String BOM_Precis_6 "Forecast Condition tomorrow [%s]" (Weather)
Number BOM_Temp_Max_7 "Forecast max tomorrow [%.2f °C]" <temperature> (Weather)
Number BOM_Temp_Min_7 "Forecast min tomorrow [%.2f °C]" <temperature> (Weather)
String BOM_Precipitation_Range_7 "Forecast Rain tomorrow [%s]" (Weather)
String BOM_Precipitation_7 "Precip probability tomorrow [%s]" (Weather)
Number BOM_Forecast_Icon_Code_7 "Forecast Icon Code tomorrow [%d]" (Weather)
String BOM_Precis_7 "Forecast Condition tomorrow [%s]" (Weather)
BOM rules:
rule "Get weather from BOM"
when
Time cron "0 0 */1 ? * *"
then
executeCommandLine("/usr/local/bin/python3@@/volume1/public/openHAB/conf/scripts/bom.py@@")
end
BOM.py script (placed in /conf/scripts/ folder)
import urllib.request
from lxml import etree
urlBase = 'http://192.168.1.148:8081/basicui/CMD?'
url = 'ftp://ftp.bom.gov.au/anon/gen/fwo/IDV10450.xml'
def setFWOItem(BOMName,OpenHABName,day,nodeType):
try:
value = tree.xpath("//forecast/area[@aac='VIC_PT042']/forecast-period[@index='" + day + "']/" + nodeType + "[@type='" + BOMName + "']/text()")[0]
OpenHABName = OpenHABName + "_" + day
value = value.rstrip('.')
print(" " + OpenHABName + "=" + value)
value = urllib.parse.quote_plus(value, safe='', encoding=None, errors=None)
rawPage = urllib.request.urlopen(urlBase + OpenHABName + '=' + value)
except IndexError:
print(" Error with " + BOMName + "::" + nodeType + "::" + day)
#value = "999"
#OpenHABName = OpenHABName + "_" + day
#value = value.rstrip('.')
#print(" " + OpenHABName + "=" + value)
#value = urllib.parse.quote_plus(value, safe='', encoding=None, errors=None)
#rawPage = urllib.request.urlopen(urlBase + OpenHABName + '=' + value)
def setFWODateItem(BOMName,OpenHABName,day):
try:
value = tree.xpath("//forecast/area[@aac='VIC_PT042']/forecast-period[@index='" + day + "']/@" + BOMName)[0]
OpenHABName = OpenHABName + "_" + day
print(" date? " + OpenHABName + "=" + value)
value = urllib.parse.quote_plus(value, safe='', encoding=None, errors=None)
rawPage = urllib.request.urlopen(urlBase + OpenHABName + '=' + value)
except:
print(" errrr Error with " + BOMName + "::" + day)
print('Requesting file...')
rawPage = urllib.request.urlopen(url)
print('File received...')
read = rawPage.read()
tree = etree.XML(read)
print('Updating OpenHAB...')
setFWODateItem("start-time-local","BOM_Date","0")
setFWODateItem("start-time-local","BOM_Date","1")
setFWODateItem("start-time-local","BOM_Date","2")
setFWODateItem("start-time-local","BOM_Date","3")
setFWODateItem("start-time-local","BOM_Date","4")
setFWODateItem("start-time-local","BOM_Date","5")
setFWODateItem("start-time-local","BOM_Date","6")
setFWODateItem("start-time-local","BOM_Date","7")
setFWOItem("air_temperature_maximum","BOM_Temp_Max","0","element")
setFWOItem("air_temperature_minimum","BOM_Temp_Min","0","element")
setFWOItem("forecast_icon_code","BOM_Forecast_Icon_Code","0","element")
setFWOItem("precis","BOM_Precis","0","text")
setFWOItem("probability_of_precipitation","BOM_Precipitation","0","text")
setFWOItem("air_temperature_maximum","BOM_Temp_Max","1","element")
setFWOItem("air_temperature_minimum","BOM_Temp_Min","1","element")
setFWOItem("precipitation_range","BOM_Precipitation_Range","1","element")
setFWOItem("forecast_icon_code","BOM_Forecast_Icon_Code","1","element")
setFWOItem("precis","BOM_Precis","1","text")
setFWOItem("probability_of_precipitation","BOM_Precipitation","1","text")
setFWOItem("air_temperature_maximum","BOM_Temp_Max","2","element")
setFWOItem("air_temperature_minimum","BOM_Temp_Min","2","element")
setFWOItem("precipitation_range","BOM_Precipitation_Range","2","element")
setFWOItem("forecast_icon_code","BOM_Forecast_Icon_Code","2","element")
setFWOItem("precis","BOM_Precis","2","text")
setFWOItem("probability_of_precipitation","BOM_Precipitation","2","text")
setFWOItem("air_temperature_maximum","BOM_Temp_Max","3","element")
setFWOItem("air_temperature_minimum","BOM_Temp_Min","3","element")
setFWOItem("precipitation_range","BOM_Precipitation_Range","3","element")
setFWOItem("forecast_icon_code","BOM_Forecast_Icon_Code","3","element")
setFWOItem("precis","BOM_Precis","3","text")
setFWOItem("probability_of_precipitation","BOM_Precipitation","3","text")
setFWOItem("air_temperature_maximum","BOM_Temp_Max","4","element")
setFWOItem("air_temperature_minimum","BOM_Temp_Min","4","element")
setFWOItem("precipitation_range","BOM_Precipitation_Range","4","element")
setFWOItem("forecast_icon_code","BOM_Forecast_Icon_Code","4","element")
setFWOItem("precis","BOM_Precis","4","text")
setFWOItem("probability_of_precipitation","BOM_Precipitation","4","text")
setFWOItem("air_temperature_maximum","BOM_Temp_Max","5","element")
setFWOItem("air_temperature_minimum","BOM_Temp_Min","5","element")
setFWOItem("precipitation_range","BOM_Precipitation_Range","5","element")
setFWOItem("forecast_icon_code","BOM_Forecast_Icon_Code","5","element")
setFWOItem("precis","BOM_Precis","5","text")
setFWOItem("probability_of_precipitation","BOM_Precipitation","5","text")
setFWOItem("air_temperature_maximum","BOM_Temp_Max","6","element")
setFWOItem("air_temperature_minimum","BOM_Temp_Min","6","element")
setFWOItem("precipitation_range","BOM_Precipitation_Range","6","element")
setFWOItem("forecast_icon_code","BOM_Forecast_Icon_Code","6","element")
setFWOItem("precis","BOM_Precis","6","text")
setFWOItem("probability_of_precipitation","BOM_Precipitation","6","text")
setFWOItem("air_temperature_maximum","BOM_Temp_Max","7","element")
setFWOItem("air_temperature_minimum","BOM_Temp_Min","7","element")
setFWOItem("precipitation_range","BOM_Precipitation_Range","7","element")
setFWOItem("forecast_icon_code","BOM_Forecast_Icon_Code","7","element")
setFWOItem("precis","BOM_Precis","7","text")
setFWOItem("probability_of_precipitation","BOM_Precipitation","7","text")
print('End')
That should cover most of it. Let me know if you need more help. Mark
Thanks Mark, ill give this a whirl in the next day or so and see if I cna get more luck with it!
Where are the Images coming from? The PNGs?
Just make sure that the
executeCommandLine("/usr/local/bin/python3
is correct… That’s the path to python3 on my server, but might not match yours.
Thats OK, my script is OK. Its the widget that appears lacking… I can see you’ve got PNGs and an IconSet, where does that come from? Are you using a Weather binding?
I got them from somewhere in this forum, but can’t remember for sure…
Might have been Template Example: Weather Binding ?
Some of those items are ones that I have from other bindings… Have you changed them all to match your items?
Hi Mark
Ive made a few changes, now the script seems to be failing. I checked your XML from BoM vs Mine and it has the 7 days forecast, same start-local-time.
Not sure why
kris@openhab2:/etc/openhab2/scripts$ ./weather.py
Requesting file...
File received...
Updating OpenHAB...
date? BOM_Date_0=2018-11-09T09:06:20+11:00
Did you update your location code?
here:
value = tree.xpath("//forecast/area[@aac='VIC_PT042']/forecast-period[@index='" + day + "']/" + nodeType + "[@type='" + BOMName + "']/text()")[0]
and here:
value = tree.xpath("//forecast/area[@aac='VIC_PT042']/forecast-period[@index='" + day + "']/@" + BOMName)[0]
I did.
I think the crux of the issue is my XML file is wrong…How did you find the right one for you? Im just after Sydney
urlBase = 'http://192.168.1.1:8080/basicui/CMD?'
url = 'ftp://ftp.bom.gov.au/anon/gen/fwo/IDN10064.xml'
def setFWOItem(BOMName,OpenHABName,day,nodeType):
try:
value = tree.xpath("//forecast/area[@aac='NSW_PT131']/forecast-period[@index='" + day + "']/" + nodeType + "[@type='" + BOMName + "']/text()")[0]
OpenHABName = OpenHABName + "_" + day
value = value.rstrip('.')
print(" " + OpenHABName + "=" + value)
value = urllib.parse.quote_plus(value, safe='', encoding=None, errors=None)
rawPage = urllib.request.urlopen(urlBase + OpenHABName + '=' + value)
except IndexError:
print(" Error with " + BOMName + "::" + nodeType + "::" + day)
def setFWODateItem(BOMName,OpenHABName,day):
try:
value = tree.xpath("//forecast/area[@aac='NSW_PT131']/forecast-period[@index='" + day + "']/@" + BOMName)[0]
OpenHABName = OpenHABName + "_" + day
print(" date? " + OpenHABName + "=" + value)
value = urllib.parse.quote_plus(value, safe='', encoding=None, errors=None)
rawPage = urllib.request.urlopen(urlBase + OpenHABName + '=' + value)
except:
print(" Error with " + BOMName + "::" + day)
Awesome.
Most of the remaining in that widget are from my weather station and other bindings (UV, Air Quality etc).
Glad you got it going!
yep, i can see the WSXXX items, Ill have to tweak that and work out why my icons dont load
I created the folders under HTML with the icons, im trying to use ‘colourful’
mine are in a subfolder so make sure you’ve got the uri correct:
<div ng-init="ServerPath='//192.168.1.148:8081/static'; IconSet='underground'">
<img width="100" src="{{ServerPath}}/images/{{IconSet}}/{{itemValue('CommonId').replace(' ','-') | lowercase }}.png"/>
I have this:
kris@openhab2:/etc/openhab2/html/images/colorful$ ls
blowing-snow.png freezing-drizzle.png partly-cloudy-day.png scattered-thunder.png snow-showers.png wind.png
clear-night.png freezing-rain.png partly-cloudy-night.png scattered-thundershowers.png storm.png
cloudy.png hot.png rain-and-sleet.png sleet.png sunny.png
dust.png light-snow.png rain-and-snow.png snow-and-sleet.png thunder.png
few-showers.png mostly-cloudy-day.png rain.png snow-flurries.png thundershower.png
fog.png mostly-cloudy-night.png scattered-showers.png snow.png unknown.png
kris@openhab2:/etc/openhab2/html/images/colorful$ pwd
/etc/openhab2/html/images/colorful
kris@openhab2:/etc/openhab2/html/images/colorful$
<div ng-init="ServerPath='//192.168.0.3:8080/static'; IconSet=colorful'">
<link rel="stylesheet" type="text/css" href="{{ServerPath}}/layouts/example.css" />
</div>
Have you put the /images/ somewhere in the code?
That folder needs to be either in the ServerPath or the code for each image…
Im using your code, its exactly the same. The images above you can see are under my openhab2 directory…
EDIT: Do you have the same icon names?
I mean that my code has /images/ in the img src. Have you still got that as well?
<img width=“100” src="{{ServerPath}}/images/{{IconSet}}/{{itemValue(‘CommonId’).replace(’ ‘,’-’) | lowercase }}.png"/>