Why does 'state.entity.last_changed' work but not state_attr

I’m trying to find out which users have been active recently by monitoring browser_mod devices. My code didn’t work and one problem seems to be that

{{ state_attr('sensor.dji_laptop_chrome_browser_user','last_changed') }} 
{{ states.sensor.dji_laptop_chrome_browser_user.last_changed }}

produce different results; the former = none & the latter is producing a valid date_time. I know the former is recommended and indeed the only one I can use in the code below which correctly lists all the entities I want to monitor (work-in-progress - I intended to go on and count recent users):

{%- set devices = states | map(attribute='entity_id') | map('device_id') | unique | reject('eq',None) | list %}
{%- set ns = namespace(entities = []) %}
{%- for device in devices %}
  {%- set ids = device_attr(device, 'identifiers') | list | first | default %}
  {%- if ids[0] == 'browser_mod' %}
    {%- set this = 'sensor.'~ids[1]|lower~'_browser_user' %}
    {{ states(this,'last_changed')}}
    {%- set ns.entities = ns.entities + [this] %}
  {%- endif %}
{%- endfor %}
{% set ents = ns.entities %}

Can anyone spare a minute to help me out?

Only for attributes, and last_changed is not an attribute it is a property of the state object. So you can not use that method.

See petro’s explanation here:

Thanks Tom that’s very clear. However, can
I loop through an array of entity ids to get an array of last_updateds?

{%- set devices = states | map(attribute='entity_id') | map('device_id') | unique | reject('eq',None) | list %}
{%- set ns = namespace(entities = []) %}
{%- for device in devices %}
  {%- set ids = device_attr(device, 'identifiers') | list | first | default %}
  {%- if ids[0] == 'browser_mod' %}
    {%- set this = 'sensor.'~ids[1]|lower~'_browser_user' %}
    {{ states[this].last_changed }}
    {%- set ns.entities = ns.entities + [this] %}
  {%- endif %}
{%- endfor %}
{% set ents = ns.entities %}

Brilliant - thanks so much! It looked good, but I just got

TemplateError: Invalid entity ID 'sensor.bad75b2f-90f0f6cc_browser_user'

So I changed to

{%- set this = 'sensor.'~ids[1]|lower|replace('-','_')~'_browser_user' %}

which does indeed give me a list of date_times. I now need to investigate why so many of them are the same, about 2 days ago.

or

    {%- set this = ('sensor.'~ids[1]~'_browser_user') | slugify %}

Thanks again. Nearly there now, but I had to change that to

 {%- set this = ('sensor.'~ids[1] | slugify~'_browser_user') %}

otherwise I just got an array of none’s.
Now all I need to do is some date filtering and counting.
As most of these sensors are for currently inactive users, is there an easy way of seeing the user name (ie state) of it when is was last something other that ‘unavailable’? I’ve read that it can be done with SQL sensors but that looks like it would need a SQL for each entity not something that can be processed in a loop.