Using targets as conditions?

Hi all, thanks for the awesome new feature. One question I am struggling with is designing a blue print that checks a condition based on a target.
Simplified below, something along the lines of

      name: Light
            domain: light
  - condition: state
    target: !input light_target
    state: "on"
  - service: light.turn_off
    target: !input light_target

I suppose this fails because conditions cannot be contain targets, is this correct? or am I missing something. I suppose I can specify the target to be a light, but would like to incorporate the slick new target selector if I can.


FWIW, I tried your example and based on this last part of the resulting error message, I believe you are correct; it doesn’t recognize the target key.

extra keys not allowed @ data[‘condition’][0][‘target’]. Got None required key not provided @ data[‘condition’][0][‘entity_id’]. Got None

Thanks so much for trying and confirming!

I managed to circumvent the problem by taking out the target and directly specifying ‘light groups’ instead of areas, little fiddly changing the existing automations in automation.yaml, but success none the less.

Blueprints are still awesome, specifically since its the initial roll-out.

I have the same issue. The light target is actually an object w/ with the entity_id under the key “entity_id”. I haven’t figured out how to get at the actual id contained within for use in my condition.

Not being able to resolve/use targets outside of service calls is still a problem. Here are some possible ways how Home Assistant might be able to fix this.

Option 1) Allow target to be used in other locations entity_id can be provided. Resolve target to a list of entities which is transparently provided as a list to entity_id. E.g.

condition: state
target: !input my_input_target
state: 'on'

Option 2) Add a template filter/function that turns a provided target into a list of entities. Provides better flexibility to be used wherever templates can be used. E.g.

- variables:
  my_target: !input my_target_input
- service: system_log.write
    message: "{{ expand(my_target) }}"
    level: info

Option 3) Making scene.apply compatible with target might also be useful, e.g.

service: scene.apply
  target: !input my_target_input
    brightness_pct: 50

Option 4) Since a common use-case for a lot of this is probably to remove specific entities from a service call (e.g. only call light.turn_on with a specific argument on light entities in the target group that are currently on), making target’s filterable by condition, might also work, e.g.

service: light.turn_on
 input: !input my_target_input
 - condition: state
   state: on
  brightness_pct: 50

Do any of these options seem reasonable? Is this something we could get with an upcoming release of HA?

1 Like