neilenns/ambientweather2mqtt

Last Rain (& possibly other calculated sensors) unknown

tankdeer opened this issue · 2 comments

We had a short power outage yesterday - a couple of hours. After everything came back online, I noticed the Last Rain sensor is showing as unknown.

image

I believe this is because it has not rained since then. You can see nothing has been transmitted.

image

However if you look at the logbook, it was getting updated earlier yesterday morning just fine.
image

Looking at other calculated fields, I think they may have experience a similar issue, but because they are updated much more frequently, it wasn't noticed at the time. However looking at history I can see small gaps after the power came back on, but before a new value was sent - usually just a couple minutes. The gap can be seen here on the Feels Like sensor, and it shows similarly in the others as well.

image

I have not noticed this with restarts or anything like that in the past, although I can experience once we get some rain. I am curious if there is something we can do about this though. Shouldn't it retain the previous values even in this scenario? Would it be as simple as setting the retain flag on the MQTT message, assuming it's not already set? Or is there something else that we would need to do.

Thanks

I'm explicitly not setting the retain value on any of the sensors, and I don't persist any state in the add-on. I'm honestly not sure if setting retain on sensor values is something that's advisable?

Probably not on all of them simply due to the update frequency, but specifically in the instance of Last Rain, it seems like retain is essential to it's function. Depending on where one lives, there could easily be months between rainfall events. You wouldn't want to lose that value just because you rebooted or something during that time.

I started looking through my other MQTT devices and while not all, a number of them do appear to have retain set for sensor values.