gieljnssns / buienalarm-sensor-homeassistant

Buienalarm custom_component for Home-Assistant
MIT License
36 stars 6 forks source link

State change: next rain forecast and Precipitation forecast average #24

Closed dutch-erik closed 3 years ago

dutch-erik commented 3 years ago

Not 100% sure, but below changed couple of days ago. See next rain forecast and Precipitation forecast average.

afbeelding

TyzzyT commented 3 years ago

I'm seeing the same issue on both my test and prod environment. Running HA core 2021.7.4 I used this 'Next rain forecast' sensor to send me a notification when rain is ahead and a window is still open, but now that the sensor is not in minutes anymore but it's showing a real time it's a lot harder to trigger any automation.

Cafun commented 3 years ago

+1 I also used the next rain forecast, bt than for my awning. I hope it can changed to minutes again instead of a timestamp.

peternijssen commented 3 years ago

That explains why I didn't get any notifications anymore... I guess this is an unintended change as the unit of measurement is still minutes.

cc @StevenLooman

StevenLooman commented 3 years ago

Yes, this is an unintended change. Although, Home Assistant does state that timestamps should be used instead of relative times. Can't find the 'official statement', but the [release page of 2020.12] does state the following for some sensors:

In order to optimize stability and performance of Home Assistant, sensors should use only absolute time values (store the date of the event) and not relative time values (seconds from event) so the value doesn’t change each second.

A users posted in their comments, lower at that page, that this can be worked around by using a template sensor:

      - condition: template
        value_template: "{{ (((as_timestamp(now()) - as_timestamp(states('sensor.uptime'))) % 3600) / 60) | int > 1 }}"

The example it is for the uptime-integration/sensor, but I'm sure it'll work for the buienalarm integration/sensor too.

I don't mind adding another sensor, or renaming the current next-rain-forecast sensor and adding a relative sensor, but this shouldn't be needed. Your call...

peternijssen commented 3 years ago

Well, that's up to @gieljnssns. Something has to change at least as the unit of measurement does not match the actual sensor data.

StevenLooman commented 3 years ago

Something has to change at least as the unit of measurement does not match the actual sensor data.

Agreed. Also, the sensors should do some rounding where relevant.

Cafun commented 3 years ago

Anyone had any luck to create a template sensor to calculate te minutes till rain? I tried, but didn't had any luck.

StevenLooman commented 3 years ago

I'll try to do some work on this, this weekend.

Cafun commented 3 years ago

I'll try to do some work on this, this weekend.

Thank you!

StevenLooman commented 3 years ago

The README includes an example:

template:
  - sensor:
    - name: "Buienalarm Next rain forecast (min)"
      unit_of_measurement: "min"
      state: >
        {% if as_timestamp(states('sensor.buienalarm_next_rain_forecast')) %}
          {{ ( ( as_timestamp(states('sensor.buienalarm_next_rain_forecast')) - as_timestamp(now()) ) / 60 ) | round }}
        {% else %}
          {{ states('nonexistent') }}
        {% endif %}

Be sure to upgrade the integration. Please let me know if you run into anything.

Cafun commented 3 years ago

Thank you!

StevenLooman commented 3 years ago

I think this issue can be close, @gieljnssns ?