Why there is no has_area function?

There is no way (not known to me) to get motion sensors that have detected motion and have an assigned area.

I use this to get the “motion-detected” areas:

    {{ states.binary_sensor
      | selectattr('entity_id', 'search', 'motion')
      | selectattr('state', 'eq', 'on')
      | sort(reverse=true, attribute="last_changed")
      | map(attribute='entity_id')
      | map('area_name')
      | reject('==', None)
      | unique
      | list
      | default(none)
      | join(', ') }}

Now I cannot access the entity_id anymore.

It would be a lot easier if there would be has_area(entity_id) function similar to newly introduced has_value(entity_id) which could be used like this:

    {{ states.binary_sensor
      | selectattr('entity_id', 'search', 'motion')
      | selectattr('state', 'eq', 'on')
      | sort(reverse=true, attribute="last_changed")
      | map(attribute='entity_id')
      | select('has_area')
      | list
      | default(none)
      | join(', ') }}

Update: I submitted a PR to add the missing function.

Why cant you use area_name(entity_id)?

I agree it would be easier if there was a has_area filter/test. Until your Feature Request is fulfilled (if ever), you can do it like this:

{% set ns = namespace(x=[]) %}
{% for e in states.binary_sensor
  | selectattr('object_id', 'search', 'motion')
  | selectattr('state', 'eq', 'on')
  | sort(reverse=true, attribute='last_changed')
  | map(attribute='entity_id') if area_name(e) != none %}
  {% set ns.x = ns.x + [e] %}
{% endfor %}
{{ ns.x | join(', ') }}
1 Like

It cannot be used as a filter in above example