Many entities are subjected to more than one automation. When a light, for instance, is set by one automation, it may then become overrided by another automation in a way that is undesirable.
For example, imagine a “Movie Time” automation that turns off the lights above the TV. If another automation is triggered to turn on the lights at sunset, the lights above the TV will turn on, even though that isn’t desirable as the TV is still on.
A workaround would be to set multiple automations with differing conditions to account for permutations that may be anticipated. However, this is complicated and creates extra automations that essentially do the same thing.
As a better solution, I suggest a way to lock entities so that they cannot be modified unless they are explicitly unlocked.
Examples
In our TV example, the lights above the TV would be turned off and locked. No other automation would be able to change the state or attributes of the lights above the TV unless they specifically unlocked them first. In this way, the single sunset automation would be prevented from turning the lights above the TV on. However, once the TV is switched off and the lights are unlocked by automation or manually, they can be manipulated again.
Other examples:
- Lock the deck canopy from opening if the wind is too strong.
- Manually lock the lawn sprinklers from running from the entity UI because you’re gardening.
- Lock a motion sensor to stop detecting motion in the back yard to stop the light coming on.
- Alternatively, you could lock the light from turning on from the motion sensor if you’re not using it for anything else.
Implementation
In the UI, a padlock could be displayed in the entity popup sheet to let the user lock and unlock with a touch
HA could have services for locking and unlocking entities, to varying levels of granularity as desired:
entity.lock
Service data attribute | Optional | Description |
---|---|---|
entity_id |
No | Mandatory for locking entities to prevent accidentally locking everything at the same time. |
duration |
Yes | If you only need to lock an entity for a set time duration. |
exclude_state |
Yes | Using this would allow the state to be changed, but not the attributes. |
exclude_attributes |
Yes | A list of attributes that you want to be able to modify still (e.g. brightness, but not colour); without a list, all attributes are excluded. |
include_attributes |
Yes | A list of attributes you want to lock; all other attributes will be left unlocked; this is implied without a list by default. |
If you want to make changes to how an entity is locked, you just re-run entity.lock
with the new parameters you want to set
entity.unlock
Service data attribute | Optional | Description |
---|---|---|
entity_id |
Yes | Unlocks a particular entity. If not specified, all locked entities are unlocked. |