Block entities for actions

Hi guys,

I was wondering if there is any option to block entities for actions.

Possible use case:

  • Having a group of covers being moved if sun automations think they should
  • One cover is the door to terrace and should not be moved if door is open

Probably I could go for having each cover in one action with a simple condition asking some sensors that could prevent the moving of this cover. This approach would expect to have all possible blocking conditions in every automation. This feels more like a workaround, since a blocking feature is state of the art in the industrial grade automation bus systems (like knx).

Do I miss something, or is it not possible to create such blocking behavior at this time ?

My approach was to create some kind of python scripts, but before moving on with this I would like you to let me know if there is any better way.

For the records, a python script to add an attribute “blocked” to a group of entities or a entity itself:

entity_id = data.get('entity_id')
if(entity_id.startswith('group')):
  for entity_id in hass.states.get(entity_id).attributes['entity_id']:
    attributes = hass.states.get(entity_id).attributes.copy()
    attributes['blocked'] = True
    logger.error("Block entity %s" % entity_id)
    hass.states.set(entity_id, None, attributes)
else:
  logger.error("Block entity %s" % entity_id)
  attributes = hass.states.get(entity_id).attributes.copy()
  attributes['blocked'] = True
  hass.states.set(entity_id, None, attributes)

and a poc to make some actions based on the attribute blocked:

entity_id = data.get('entity_id')
if(entity_id.startswith('group')):
  for entity_id in hass.states.get(entity_id).attributes['entity_id']:
    if hass.states.get(entity_id).attributes.get('blocked'):
      logger.error("Entity %s is blocked" % entity_id)
    else:
      logger.error("Entity %s is not blocked, go on" % entity_id)
else:
  if hass.states.get(entity_id).attributes.get('blocked'):
    logger.error("Entity %s is not blocked" % entity_id)
  else:
    logger.error("Entity %s is not blocked, go on" % entity_id)

Regards,
Andreas

Hey @atomic have you worked further on this topic. I am searching for something really similar to lock an entity. Thanks and nice holidays!