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.