jdejaegh / irm-kmi-ha

Home Assistant weather provider using data from Belgian IRM KMI 🇧🇪 🇱🇺 🇳🇱
MIT License
53 stars 2 forks source link

Rainsensor #25

Closed blowk closed 5 months ago

blowk commented 6 months ago

Is it possible for a rain sensor that tells you when it will be raining in minutes like described on the radar? This sensor data can be used in automations, like closing windows if it will start raining.

jdejaegh commented 6 months ago

A sensor like the one you describe will probably be implemented with a timestamp (the time at which the rain starts) rather than a countdown. Similar to the sunrise/sunset sensor. It achieves the same functionality but avoids the sensor changing state simply because time is passing.

I'll look into that

blowk commented 6 months ago

oh, waw. That sounds great. Thanks!

jdejaegh commented 5 months ago

Instead of creating a new sensor for that specific use-case, I implemented a service to return the radar data (similar to weather.get_forecasts). This way, most use-cases can be handled with this service and some templates.

Assuming that you have a weather entity setup with this integration called weather.home, add the following to your configuration.yaml:

template:
  - trigger:
      - platform: state
        entity_id: weather.home
      - platform: homeassistant
        event: start
    action:
      - service: irm_kmi.get_forecasts_radar
        data:
          include_past_forecasts: false
        target:
          entity_id: weather.home
        response_variable: response
    sensor:
      - name: Next rain time
        unique_id: next_rain_time
        state: "{{ response['weather.home'] | rejectattr('native_precipitation', 'eq', 0) | map(attribute='datetime') | first | default | as_datetime }}"
        device_class: timestamp

It will create a template sensor called sensor.next_rain_time with a timestamp showing when the next rain will happen. If it is currently raining it might be in the past (5 minutes ago) but it will never be more than 10 minutes in the past. When there is no rain on the radar forecast, the sensor is unknown.

You may want to add a time pattern trigger in the template: currently it refreshes the value only when Home Assistant starts or when the weather condition changes.

The issue will be closed once the feature is merged into main and it will be shipped in the next release. However, feel free to comment here if you need more info

jdejaegh commented 5 months ago

This is released in 0.2.12

blowk commented 5 months ago

Thank you for adding this.