Custom Component: AEMET (Spanish Meteorological Agency)

Hi all,

This is my first custom component and my first project in Python.

I have published it on GitHub: https://github.com/outon/HomeAssistant-AEMET

I have been learning Python while developing this component. It has been an interesting project and I have reformatted all the code several times while learning different ways to do it, but I guess it is now ready to share with you and of course get all your feedback.

To use this component in your HA you will need to obtain a personal API KEY from AEMET Open Data.

This is the Spanish Weather & Forecast agency so you will find all the information in Spanish. You can only obtain weather info for Spanish locations.

Configuration:

  • Copy files in aemet directory from GitHub to your custom_component folder.
  • On your configuration.yaml file you need to enter:
weather:
  - platform: aemet
    name: AEMET
    api_key: !secret aemet_api_key
    mode: daily

I hope you like my work as much as I’ve had joy doing it.

All feedback is welcome, from code stylish … to bugs, any criticism is welcomed

2 Likes

Hi,

Tried to copy files on custom_components/aemet/ or custom_components/weather/aemet/

both doesn’t work. First, gives an error:

2019-08-27 11:01:14 ERROR (SyncWorker_0) [homeassistant.loader] Error parsing manifest.json file at /config/custom_components/aemet/manifest.json: Expecting value: line 5 column 20 (char 154)

Second path seems can’t load the component

Thanks

Hi,

I fixed the typo error. Please try it now.

I do not know why I added “weather” in dependencies and without any quotes.

I have changed the following file:

Thank you.

Hi

Thanks for the updated file. Now It works but it seems cannot obtain the forecast:

Another question, How can I specify a location?

This component obtains location automatically from location defined on HA. But you can also specify your location by adding latitude and longitude parameters.

weather:
  - platform: aemet
    name: AEMET
    latitude: nn.dddddd
    longitude: nn.ddddd
    api_key: !secret aemet_api_key
    mode: daily

Forecast information is retrieved, but you need the weather card to see the information. It contains several “objects” with date, temperature, humidity… those objects are json data.

It is possible to see the information by clicking on button

it will open a card with weather info:

You can also may click on “weather.aemet” and on top of screen will appear the json with all information:

Thanks! I’ll try to play with some locations

Hi, is this still working? I have some errors. Thanks for the help!

aemet: Error on device update!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 312, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 476, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/util/__init__.py", line 240, in wrapper
    result = method(*args, **kwargs)
  File "/config/custom_components/aemet/weather.py", line 396, in update
    self._aemet.update()
  File "/usr/src/homeassistant/homeassistant/util/__init__.py", line 240, in wrapper
    result = method(*args, **kwargs)
  File "/config/custom_components/aemet/aemet.py", line 1139, in update
    api_client=self.api_client,
  File "/usr/src/homeassistant/homeassistant/util/__init__.py", line 240, in wrapper
    result = method(*args, **kwargs)
  File "/config/custom_components/aemet/aemet.py", line 860, in update
    data = self._update_forecast()
  File "/config/custom_components/aemet/aemet.py", line 848, in _update_forecast
    clean_data = self._refactor_forecast(raw_data)
  File "/config/custom_components/aemet/aemet.py", line 789, in _refactor_forecast
    transformed_data[fecha][horas] = value
KeyError: '2020-04-02T00:00:00'