Filter problem

Hi everyone,
When I use this code,


{% set Person = 'parent M' %}
{% set Person1 = 'child V' %}
{% set ConType = 'band5, band2_4' %}

{% set Person = state_attr('sensor.data_' + Person.split(' ')|join('_'),'FirstName')|lower %}
{% set ConType = ConType|replace(', ', '|')|replace(',', '|')|lower %}

{% set Present = states
|selectattr('domain', '==', 'device_tracker')
|selectattr('entity_id', 'search', 'iphone')
|selectattr('entity_id', 'search', Person)
|selectattr('attributes.connectiontype','search', ConType) 

|selectattr('entity_id', 'search', 'deco') 
|map(attribute='entity_id')
|list %} 

{% if Present == [] %}
not_home
{% else %}
{{Present[0].split('_')[-2]|uppercase}}
{% endif %}

I get the following error message

'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'connection_type'

Can someone tell me why this is happening and how I can solve it?

Thanks in advance.

Two or three issues…

For search you need a pipe or it will search for the whole thing as a single string:

{% set ConType = 'band5|band2_4' %}

Select for the attribute being defined first:

{% set Present = states.device_tracker
|selectattr('entity_id', 'search', 'iphone')
|selectattr('entity_id', 'search', Person)
|selectattr('attributes.connectiontype', 'defined')
|selectattr('attributes.connectiontype','search', ConType) 

|selectattr('entity_id', 'search', 'deco') 
|map(attribute='entity_id')
|list %} 
...

Also, double check the attribute ID… on mine its connection_type.