Australian Weather Forecast using BOM Public FTP

Rather than trying to add forecast scraping directly in homeassistant, I thought it might be helpful to split the code out into a separate python library and then use that.

Here’s a first attempt: https://github.com/aguinane/bomweather

Would love some help / feedback / testing.

1 Like

is this me, a temporary glitch, or something else:

2019-03-14 12:20:31 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 240, in async_update_ha_state
    device_attr = self.device_state_attributes
  File "/home/homeassistant/.homeassistant/custom_components/bom_forecast/sensor.py", line 350, in device_state_attributes
    ATTR_ICON: self._bom_forecast_data.get_reading('icon', self._index),
  File "/home/homeassistant/.homeassistant/custom_components/bom_forecast/sensor.py", line 392, in get_reading
    return ICON_MAPPING[state.text]
KeyError: '18'

HA version 0.88.2

I got the same error for most of the day, but now it’s gone. I have lost my ‘max temp’, though, from here:

{{ states.sensor.bom_forecast_sydney_0.attributes[‘Max Temp C’] }}

(it doesn’t show up in the attributes anymore)

Edit: Now working after no changes.

same.

oh well.

and is a problem again.

2019-03-15 16:44:10 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 240, in async_update_ha_state
    device_attr = self.device_state_attributes
  File "/home/homeassistant/.homeassistant/custom_components/bom_forecast/sensor.py", line 350, in device_state_attributes
    ATTR_ICON: self._bom_forecast_data.get_reading('icon', self._index),
  File "/home/homeassistant/.homeassistant/custom_components/bom_forecast/sensor.py", line 392, in get_reading
    return ICON_MAPPING[state.text]
KeyError: '18'

So looking at the xml file on the BOM FTP server, and searching for 18…

<element type="forecast_icon_code">18</element>

And looking at the code for “icon”

ICON_MAPPING = {
    '1': 'mdi:weather-sunny',
    '2': 'mdi:weather-night',
    '3': 'mdi:weather-partlycloudy',
    '4': 'mdi:weather-cloudy',
    '6': 'mdi:weather-sunset',
    '8': 'mdi:weather-rainy',
    '9': 'mdi:weather-windy',
    '10': 'mdi:weather-sunset',
    '11': 'mdi:weather-rainy',
    '12': 'mdi:weather-pouring',
    '13': 'mdi:weather-sunset',
    '14': 'mdi:weather-snowy',
    '15': 'mdi:weather-snowy',
    '16': 'mdi:weather-lightning',
    '17': 'mdi:weather-rainy'
}

And checking http://reg.bom.gov.au/info/forecast_icons.shtml suggests we should have 18 and 19 as codes…

changing to

'17': 'mdi:weather-rainy',
'18': 'mdi:weather-rainy',
'19': 'mdi:weather-hurricane'
}

fixes it.

1 Like

Top detective work there - fixed it for me!

Hi Brendan,
I just noticed this message in my Home Assistant Log:
“Integrations need to be in their own folder. Change sensor/bom_forecast.py to bom_forecast/sensor.py. This will stop working soon.”

This is a user required action

if you dont have anything other than bom_forcast.py in the sensor folder do the following.
rename sensor folder to bom_forecast
then rename bom_forecast.py to sensor.py

Thanks aidbish. I’ve got 3 py files in the sensor folder. Do I just create a new folder for each and rename each to sensor.py?

yeah mate that the deal
just make sure the names of folder is exactly the same as the py file name excluding the py

the rename the py file to sensor.py in each folder

hope that makes sense

Thanks mate!

After having this on my to-do list for sometime I’ve finally implemented it, great work @BrendanMoran and those that have contributed to the project.

What’s the situation when a product is derived from two IDs. Using the main forecast for Sydney isn’t as accurate as the readings added by the précis forecast?

I’m in the same situation. I can’t use my local BOM station, but I use a forecast for one about 25 minutes away which is slightly out at time.

awesome…thanks @BrendanMoran . Great to have some local content.
Thanks…love it

Firstly thanks @BrendanMoran for putting this together.

I am new to templating so looking for some help. I have this at the moment:

  todaymaxtemp:
    friendly_name: "Today Maximum Temperature"
    value_template: "{{ state_attr('sensor.bom_forecast_brisbane_0', 'Max Temp C') }}"
    icon_template: mdi:weather-sunny

which as we know goes to None in the afternoon. I would like to have it so that if the value is None then the value is replaced by the value from here:
sensor.wupws_temp_high_1d

Thanks in advance!

This template should do it:

value_template: >
  {% if state_attr('sensor.bom_forecast_brisbane_0', 'Max Temp C') not in ['unavailable', 'unknown', 'None' ] %}
     {{ state_attr('sensor.bom_forecast_brisbane_0', 'Max Temp C') }}
  {% else %}
     {{ states('sensor.wupws_temp_high_1d') }}
  {% endif %}

I liked the look of it but sadly didn’t work… The IF is evaluating true even though the state is showing “Unknown” on the card and “None” in the states list. I tried “unknown” and “Unknown”

Any other ideas?

I have the same sensor. Let me check the template editor…

EDIT:

Ok I cant see what Im doing wrong.

This:

{{ state_attr('sensor.bom_forecast_hobart_0', 'Max Temp C') }}

Evaluates to None (’-’ in the dev tools states page, I tried that too, no joy).

Yet this:

{% if state_attr('sensor.bom_forecast_hobart_0', 'Max Temp C') == 'None' %}
     True
  {% else %}
     False
  {% endif %}

Evaluates to False. Hmmm.

EDIT 2:

Fixed it. The attribute is not a string! It’s a number. This should work:

value_template: >
  {% if state_attr('sensor.bom_forecast_brisbane_0', 'Max Temp C') | string not in ['unavailable', 'unknown', 'None' ] %}
     {{ state_attr('sensor.bom_forecast_brisbane_0', 'Max Temp C') }}
  {% else %}
     {{ states('sensor.wupws_temp_high_1d') }}
  {% endif %}

No doesn’t seem to be working for me :frowning: I will follow up more tomorrow but any more ideas are welcome…

That’s strange. This (today’s sensor, no value):

  {% if state_attr('sensor.bom_forecast_hobart_0', 'Max Temp C') | string not in ['unavailable', 'unknown', 'None' ] %}
     {{ state_attr('sensor.bom_forecast_hobart_1', 'Max Temp C') }}
  {% else %}
     Other sensor
  {% endif %}

Gives me Other Sensor but this (tomorrow’s sensor which has a value):

  {% if state_attr('sensor.bom_forecast_hobart_1', 'Max Temp C') | string not in ['unavailable', 'unknown', 'None' ] %}
     {{ state_attr('sensor.bom_forecast_hobart_1', 'Max Temp C') }}
  {% else %}
     Other sensor
  {% endif %}

Gives me 25

Are you using mode: friendly for your BoM sensor?