Ok, hopefully the following will help other users enable the _last_seen
entity without having to manually enable them all.
After a discussion with Koenkk here, he said that setting the following in Z2M doesn’t by itself automatically make hidden _last_seen
entities become enabled because “home assistant doesn’t update this after initial discovery”.
device_options:
homeassistant:
last_seen:
enabled_by_default: true
The solution is to basically remove the MQTT integration and have HA discover all the Z2M entities again. He did however say that “this will reset all your entities in HA (icons, friendly names)”. This doesn’t luckily impact me, so I went ahead and did the following:
- stop Z2M
- remove MQTT integration in HA
- restart HA
- confirm devices/entities have been removed in HA
- start Z2M
- add and reconfigure MQTT integration in HA
- restart HA
I now have all 125 _last_seen
entities in HA!
btw, if anyone wants to test part of the blueprint in the Template Editor, I was using the following:
{% set result = namespace(sensors=[]) %}
{% for state in states.sensor | selectattr('attributes.device_class', '==', 'timestamp') %}
{% if 'last_seen' in state.entity_id and (states(state.entity_id) == 'unavailable' or ((as_timestamp(now()) - as_timestamp(states(state.entity_id))) > ((24 | int) * 60 * 60))) %}
{% set result.sensors = result.sensors + [state.name | regex_replace(find='_last_seen', replace='') ~ ' (' ~ relative_time(strptime(states(state.entity_id), '%Y-%m-%dT%H:%M:%S%z', 'unavailable')) ~ ')'] %}
{% endif %}
{% endfor %}
{{ result.sensors | join(', ') }}
@Mr_Groch it looks like you’re missing the underscores in the line below:
regex_replace(find=' last seen',