Ability to temporarily "lock" an entity to prevent modifications

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.

This is something I’ve often thought about and would love to see. Not sure how it would be implemented but would definitely make some situations more ideal instead of having to code around when you want to prevent things from happening.

Your examples are great and I can think of many more!

That sounds like a problem with a simple solution: spend more time thinking about the design of one’s automations.

If someone is unwilling to invest this ‘design time’, I fail to see how they will invest the time to learn and use entity locks.

Conversely, someone who understands how to use entity locks already knows how to avoid having their automations work at cross purposes.

If this was an easy addition to Home Assistant then I’d say ‘Sure, why not!’ However, the proposed locking concept would require significant changes to Home Assistant’s current operations (i.e. many breaking changes).

2 Likes

I agree, that this may be too complicated. Instead, think about using input booleans and template switches. I guess, it should be pretty straight forward to implement some kind of locking with these two components, as long as the number of entities/groups to be locked is not too large.

I know this is an old thread, but in my opinion this is the thing that home assistant is really missing. I’m manually implementing locking on certain entities. Locking makes automations way simpler and also people living in the house happier, because performing a manual action locks the entity and automations can’t touch it until it’s unlocked or turned off. This same way one automation cannot collide with other because only one of them can obtain lock on entity in one time.

I found this thread, because I was searching for some custom integration that could implement locking, but no luck.