Area conditions?

Just wondering why it’s not possible to use area’s as conditions? I’d like to, for example, check if any lights are on in a configured area. Is there currently a different way to check if any lights have been left on in a specified area?

You can do it with a template condition.

condition:
  - "{{ trigger.entity_id in area_entities('your_area_name_here') }}"

Ah thanks for the hint! Brought me to the following to check the number of lights on:

{% set lights_on = expand(area_entities('your_area_name_here')) %}
{{ lights_on | selectattr('state', 'eq', 'on') | list | count > 0 }}

3 Likes

Great but you asked for a condition not a count of lights on in an area. It helps if you actually ask for what you want in future.

Not sure how the above isn’t answering that? I was looking for a condition that would tell me if lights are left on in an area. Using the template above will give back a count of how many lights are on if used as a condition.

1 Like

Conditions evaluate to true or false, not numbers.

Kind of confused here but doesn’t this evaluate either true or false?

 - condition: template
   value_template: >-
     {% set lights_on = expand(area_entities('your_area_name_here')) %}
     {{ lights_on | selectattr('state', 'eq', 'on') | list | count > 0 }}
5 Likes

Sure but it is way more complicated.

ah that makes sense. Reason why I ended up with this is because im using a time trigger. I saw the trigger.entity_id bit and figured (and maybe unrightfully so) that it wouldn’t be part of the area as the trigger is a time value. So started playing with the template and landed on this.

That makes sense.

The sass :slight_smile: To be fair, you didn’t answer their original question:

1 Like

Yeah. I did. It’s just that my solution was not applicable to their situation. This could have been avoided by providing the actual use case required I.e. the configuration of the automation where it was needed.

See: How to help us help you - or How to ask a good question

Maybe I’m just missing how this would be used to check if any lights have been left on in an area?

1 Like

If you are using a state trigger (which Yardco was not), whichever light triggered the automation will have its entity id stored in trigger.entity_id. The condition checks if this entity id is in the list of entities associated with the area.

I indeed did not ask a “good” question, my apologies for that. You probably assumed that my automation would be triggered by a light (which I could have been more clear about) but your first reply did point me in the right direction, and to a solution that works. So again, thank you for that.

I’ll ask a more complete question next time with clear intent so that we don’t land in a similar discussion about what the “correct” solution is.

3 Likes