Make derivative sensor unavailable when source sensor is unavailable#147468
Conversation
|
Hey there @afaucogney, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
| Decimal(restored_data.native_value), # type: ignore[arg-type] | ||
| self._round_digits, | ||
| ) | ||
| except SyntaxError as err: |
There was a problem hiding this comment.
I can't figure out why this was here or what would ever thrown this Error.
|
I initially started out with For some reason when I shutdown HA and the sensor was Unavailable, when I booted it up again it would always restore to it's last-known-good-state, which doesn't seem like the right thing to do as the source sensor was still unavailable on boot, and it didn't seem right to put a valid-looking value there. When I shutdown HA and the value is Unknown, then it correctly restores as Unknown, which I think is what I want. |
frenck
left a comment
There was a problem hiding this comment.
This is not the correct behavior IMHO, I think we should make this sensor unavailable when the source sensor is unavailable as well.
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
|
Ok, changed to make it unavailable instead of unknown. Behavior is something like this:
I think that's my best idea of how the rules should work, but let me know if I've misunderstood anything. |
Proposed change
Make the derivative sensor unknown when its source sensor is non-numeric. The previous behavior just persists the previous value from the most recent time before the sensor had a bad value.
While the derivative sensor state is
Unknownduring the period its source sensor is non-numeric, as soon as the source sensor becomes available again, it calculates the derivative as if there was no gap in the source sensor, allowing brief periods of unavailability to not distort longer term derivative calculations.Based on this revert PR this feature is one of the last missing pieces to re-enable statistics for Derivative sensor, which was previously reverted partially for this reason.
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: