ekutner / home-connect-hass

Alternative (and improved) Home Connect integration for Home Assistant
MIT License
549 stars 54 forks source link

Keep appliance last state when device is turned off #180

Closed stickpin closed 1 year ago

stickpin commented 1 year ago

Is your feature request related to a problem? Please describe. Today when you turn off your appliance many sensors become unavailable.

Describe the solution you'd like My suggestion is to save the last appliance state in the file when you turn the appliance off, as zigbee2mqtt does for example. If the last sensor state doesn't make sense when the appliance is turned off, I would suggest changing the state to N/A for example. This will allow sensors to stay "active".

@ekutner if you agree with the proposal, I can try to implement it.

ekutner commented 1 year ago

Today the sensors become unavailable because they are. What is the benefit of keeping them active with a N/A state? On the practical side there would be two issues with implementing something like that:

  1. I believe (didn't verify) that sensors can't return a None value, so they will have to return the string "N/A", but that won't work for numeric and binary sensors.
  2. When the integration starts, after a HA reboot, it reads the current state from the HC API. Since the state is really unavailable this will create an inconsistency where the same physical state (the appliance is turned off), has two different sensor states.
stickpin commented 1 year ago

Hi @ekutner,

Well, technically you are right, sensors are "currently" unavailable because the appliance is off. The problem is that Home Assitance doesn't have this temporary state and some of the sensors can even be deleted because of this: Screenshot 2023-03-07 at 08 51 10

My idea is to have some kind of "default" values for sensors that are "currently" unavailable and was previously discovered once the appliance was on. Btw, I don't think we have a problem with binary_sensors at least on my 3 appliances all of them keeping the last_known_state or it kept by BSH (Home Connect). The only problem that I currently see is with the sensor and those can be addressed with N/A, Unknown, Inactive, etc... Whatever default value will make sense.

I think that even BSH themselves using this strategy for some sensors: Screenshot 2023-03-07 at 08 49 25

ekutner commented 1 year ago

Deleting sensors is a manual process so I doubt anyone would do that but even if they did nothing will happen because they will just be created again, with the same device_id, when the appliance reconnects.

To be honest, I don't really see the use case and I definitely don't believe sensors should show values which are known to be wrong (i.e. the previous state). That said, if other people will see value in such a behavior I'll be ok with merging a PR that did it, as long as it was optional and reliable. If you want to follow through with it I suggest you open a thread in the discussion thread and see what other people have to say about it. In the mean time you may want to think how you would implement something like that, in particular the case of publishing previous sensors after HA restart. You should find some inactive code in the init file that used to save a cache of the internal state. That should help you with what you're trying to do but know that I disabled it because it created some inconsistencies that made it just easier to live without it.