Openweathermap rain sensor text vs numerical value


This sensor has a unit of “mm” when its raining. But when its not raining the sensor says “not raining” this messes with graphs, get gaps, and stuck on 1mm after its stopped raining.
The units also should be more correctly mm/hr for millimetres per hour.
I think i can probably fix my installation by using a template sensor or automation to change it to zero.
Would the community regard this as a bug that should be reported?

I have found the code that does this in the integration, so its not coming from API. I have no idea why they do it though.

@staticmethod
    def _get_rain(rain):
        """Get rain data from weather data."""
        if "all" in rain:
            return round(rain["all"], 0)
        if "1h" in rain:
            return round(rain["1h"], 0)
        return "not raining"

I dont know python, but I’m guessing that changing the last line to

return 0

may fix it?

Yes, that would fix it but as soon as you update OpenWeatherMap it would break again. You could also create a custom sensor that performs the conversion for you that would survive upgrades. The downside is another entity, but the upside is not having to always change the code when something gets updated.

I tried an automation, doesn’t seem to work reliably, maybe I have to wait, its not a good solution because immediately changing the state of a sensor still leaves “not raining” in the database.
I made a template sensor instead as I did not feel like raising a bug in case its like that by design for reasons I dont understand. My template sensor:

rainfall:
        friendly_name: "openweathermap rain mm/h"
        unique_id: rainfall
        value_template: >-
          {% if is_state('sensor.openweathermap_rain', "not raining") %}
          0
          {% else %}
          {{ states('sensor.openweathermap_rain') }}
          {% endif %}

Thanks, I went for second option. Immune from changes down the line when I have forgotten what I did

I am migrating away from Darksky because the API is being turned off at the end of the year since Apple bought them. The rain data provided by Darksky seems to be a smoothed/averaged version Openweathermap data. The timing is the same, so either they use same source or Darksky uses Openweathermap

it appears that this has been fixed in home assistant its zero when not raining now. The units are still incorrect though mm instead of mm/hour