This config beside entries from my previous post was running quite long.
I have no clue what I am doing wrong. I have compered everything with z2m docs, restarted HA , server few times and was manually putting offline value for homeassistant/status (according to docs). Weird thing is that there is no such message by itself in that topic.
You are lucky I do not have attribute or hidden entity “last_seen”.
If You have that attribute this all that blueprint is about.
Avaiabilty is not just that good since this is presented in documentation.
My colegue also tested this settings and has last_seen in debug for devices that are out of network.
It is strange that you don’t at least have the last_seen attribute because this is what the last_seen: ISO_8601_local gives you. Sorry for the obvious question, but are you running the latest Z2M (1.25.0) and HA (I’m on 2022.3.x - I’ll try 2022.4 just in case)?
My problem is that sensor.motion_bed4_last_seen entity remains hidden (along with all the other 124 Z2M devices), unless I manually enable it within HA. For me I’d rather have them all enabled automatically, which is what I hoped the `device_options’ method would do.
This weirdness comes from fact that Z2M config is moving from config to WebUI. See supervisor log for proof. Check Z2M WebUI > Settings > Generated Configuration (do not know how it is signed in your UI language) and then look for enabled_by_ default. Id it is not there edit ..\share\zigbee2mqtt\configuration.yaml
manually. That helped me with attributes.
I have set this up and am seeing the last_seen attribute on all my Z2M devices, but I’m not seeing what I expected. Perhaps I have misunderstood the functionality that this automation provides.
I have a device in Z2M which has been in an ‘off’ state for over 20 hours now (intentionally).
I’ve set the automation to run every day (option 0) at a set time. It is set to report on device that have a last_seen time of over 1 hour.
I’ve set a basic push notification to come through on thre HA app on my phone.
If I run the automation manually, I get the push notification but it doesn’t show any devices or information.
Is this because my device isn’t ‘sensor’?
Ah I understand now, thank you for explaining
I’ve enabled that previously disabled entity for the one device that has been offline, and added {{sensors}} to the start of the notification message, and ran the automation - works perfectly
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”.
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:
Not really - this is for grabbing device name for notify - I’m using ‘last seen’ entity with name like ‘device last seen’, so I want to cut ’ last seen’ part from it (notice that regex_replace is done on state.name not state.entity_id)
It’s also worth noting the lack of a timestamp when a device is unavailable due to having set availability: true in Z2M. Just mentioning it in case it helps anyone else who sees the same thing.
Something is wrong with your setup, because your devices have name/friendly name the same as entity_id. Default behaviour in Z2M is to add ‘last seen’ (and other sufixes) with spaces in name/friendly name
Z2M has so many options and legacy hangovers that it doesn’t surprise me that my setup is probably missing something. I’ll have a look through the docs to see if I can find something related.
Hey, thank you for this. I’m observing something strange, though: The z2m_last_seen_entities entity reports its value as “unknown”, even though I can use the template editor to get the state value of 0.
Does a state of 0 equal unknown?
Strike that. It’s working now. Took a couple of minutes.