Rain Forecast for next hour

It is very useful to know if it will or not rain in the next 60 minutes. Typically you can setup notifications if doors and windows are open before it starts to rain.

We can make use of the free weather API from the norwegian yr.no, altough it cannot be used directly with Home Assistant. It presents a lot of data, and in XML format.

I've created an API wrapper at:

https://api.solweb.no/yr  

Find your location ID

Navigate through Yr to find you desired location and take a look at the URL. In example you can end up on a page like this:

https://www.yr.no/sted/Norge/Buskerud/Kongsberg/Kongsberg/  

Use the location part Norge/Buskerud/Kongsberg/Kongsberg, URL encode it, and check if it works with the API wrapper (not all locations work):

http://api.solweb.no/yr?location=Norge%2FBuskerud%2FKongsberg%2FKongsberg  

If it returns JSON it works!

Configure the sensor and template

Then add this RESTful sensor and template to your Home Assistant configuration:

sensor:  
  - platform: rest
    resource: 'http://api.solweb.no/yr?location=Norge%2FBuskerud%2FKongsberg%2FKongsberg'
    name: "Rain Kongsberg"
    headers:
      User-Agent: 'Home Assistant'
      Accept: 'application/json'
    json_attributes:
      - rain
    value_template: '{{ value_json.value }}'
  - platform: template
    sensors:
      rain_forecast_kongsberg:
        friendly_name: "Rain 1h"
        unit_of_measurement: 'mm'
        value_template: >-
          {{ states.sensor.rain_kongsberg.attributes.rain }}
        icon_template: >-
          {% if is_state('sensor.rain_kongsberg', 'on') %}
            mdi:weather-rainy
          {% else %}
            mdi:weather-cloudy
          {% endif %}

It should now show up as a boolean sensor:

Lovelace UI

And you can use the template in the Lovelace UI to indicate whether rain is expected or not:

  - title: Ute
    cards:
      - type: weather-forecast
        entity: weather.yweather
      - type: glance
        entities:
          - sensor.netatmo_ute_temperature
          - sensor.netatmo_ute_humidity
          - sensor.yr_symbol
          - sun.sun
          - sensor.netatmo_regn_rain
          - sensor.weather_wind_speed
          - sensor.weather_wind_direction
          - sensor.rain_forecast_trondheim
          - sensor.rain_forecast_kongsberg

Use automation

And you can do automations that is triggered when rain is expected:

- alias: 'Regnvarsel verandadør'
  trigger:
    - platform: state
      entity_id: sensor.rain_forecast_kongsberg
      to: 'on'
  condition:
    - condition: state
      entity_id: binary_sensor.door2_veranda
      state: 'on'
  action:
    - service: notify.notify
      data:
        message: "Close the door! Rain ahead!"