Last night, I accidentally turned on the lights in the bedroom, which wasn’t a popular action. I knew this was bound to happen at some point, either manually through a UI or through some automation that I’ve made.
I think a helpful feature would be something that can filter or firewall service calls. This would allow me to set a filter up for light.turn_on on specific lights, and prevent those from passing if some condition holds (like nighttime). More advanced, it could be allowed to dim lights if they’re already on - but primarily I’d like to prevent all turning on of those lights through HA.
Turning the lights on through a switch would still work in my instance, as the switch physically controls the light. Other setups may also need to allow turning on the lights if the call comes from a specific switch.
I don’t know what to search for, if this already exists
So what do you envision would be needed to prevent you from accidentally doing that again? The “filter service calls” suggestion in your original post isn’t possible so perhaps a Condional card could be used to hide all lights displayed in the UI that shouldn’t be accessible during the night.
Because it doesn’t exist.
Be advised that ChatGPT has a reputation for answering questions about Home Assistant with authoritative-sounding suggestions that are factually incorrect.
It being not possible makes it a good candidate for a feature request.
Hiding the entity in the ui does not prevent automations or other things. For example, if one were to make a scene that did something, it could inadvertently turn on the light that mustn’t turn on in this instance.
Is it possible to capture the service call in an event and manipulate it there?
Could a custom component overwrite the service call logic (they must all go through the same code before ending in their respective domains) and do something before handing off to the original service call logic?
So I did some digging and I did find the core point where service calls come through.
In this, it’s obvious that:
Events cannot manipulate the service call
There don’t seem to be any hooks or extension points that I can interact with
But, I did find that the service registry can register service calls - and it doesn’t test if they exist already. So in principle, if, when HA is ready, I made a bit of code that called register(.., 'light', 'turn_on', ..) which then wrapped whatever was already registered as a handler - it could manipulate / filter / do stuff before the current service call.
Part of my issue is that this seems possible, and it seems like something others would have needed. This could be for my use case, or others like security (“only X can call lock.unlock”) - but my search keywords come up empty.