danobot / entity-controller

Home Assistant Entity and lighting controller for managing devices with timers, scripts, and sun-based time restrictions.
https://danobot.github.io/ec-docs/
GNU General Public License v3.0
289 stars 41 forks source link

Feature Request: Check override entities when entity controller starts #285

Open ndbroadbent opened 1 year ago

ndbroadbent commented 1 year ago

I saw your comment about the current behavior: https://github.com/danobot/entity-controller/issues/231#issuecomment-1172165847

But I would like to request a change to this behavior. If I am working on my entity controller config at night time, then I have to be very careful about restarting Home Assistant, because the controllers will no longer be overridden. So motion sensors will cause our bedroom lights to turn on, which is not good if my wife is sleeping. I think it would be reasonable to start the entity controllers in an overridden state if an override sensor is on when it starts.

I've noticed a similar edge case when an entity controller goes from overidden => idle, but a motion sensor was already on. In that case I think it would be nice to transition from overridden => active timer and turn on the light.

danobot commented 1 year ago

If someone is going to implement this, I'd be happy to review and merge those changes.

ndbroadbent commented 1 year ago

Thanks @danobot! I am still very interested in this since it's still causing problems when I restart Home Assistant.

Home Assistant restarts will always cause inconsistent behaviour because HA itself is reinitialising.

Yes, the entity states getting initialized are also causing entity controllers to get triggered.

I fixed this for some of my other automations by adding initial_state: 'off', and creating another automation that waits for 45 seconds after home assistant starts before enabling those automations.

Would it be possible to set a similar delay before creating the entity controllers? Maybe could add a configuration option for "ignore state changes for x seconds after starting"

ndbroadbent commented 1 year ago

@danobot I finally came up with a solution, and this seems to be working very well for me: https://github.com/danobot/entity-controller/pull/292

Now I can safely restart Home Assistant, and entity controller will ignore all the state change events while everything is initializing. The only problem is that I needed to hard-code a startup delay in a constant. Is there any way we can configure some global settings for all entity controller instances?

danobot commented 1 year ago

I'm pretty sure there is a function Home Assistant calls on the entity after it is registered . You can run your code within that function. It's better than relying on a fixed timer.