Skip to content

feat: optional last_seen state per device - #3051

Closed
Schimi1983 wants to merge 1 commit into
ioBroker:masterfrom
Schimi1983:feat/last-seen
Closed

Schimi1983 wants to merge 1 commit into
ioBroker:masterfrom
Schimi1983:feat/last-seen

Conversation

@Schimi1983

Copy link
Copy Markdown
Contributor

What
New option on the Settings tab: Save the time of the last message per device (last_seen) – default off, so nothing changes for existing installations.

When switched on, every incoming message writes the time of that message (device.lastSeen from herdsman) to <device>.last_seen (type number, role value.time, read-only). Same idea as zigbee2mqtt's advanced.last_seen. Users can use it in scripts/visualisations to see when a device was last heard of, e.g. to detect a battery device that stopped reporting.

  • The state is defined as common state with lazy: true: it is not created by syncDevStates, only when a device sends a message while the option is on. Option off → no new states.
  • As common state it is not treated as orphaned by the state cleanup.
  • 1 new text in words.js / 11 i18n/*.json

A follow-up PR uses last_seen for "last seen" in the device manager (currently taken from the timestamp of msg_from_zigbee) and makes msg_from_zigbee optional (#3037).

Tested on my installation (42 devices):

  • option off: no last_seen state at all
  • option on: after 2.5 min 28 devices had last_seen (number, value.time), value = time of their last message; no warnings/errors in the log
  • option off again: msg_from_zigbee keeps updating, last_seen is not written any more
  • checkbox is loaded/saved by the config page

Install for testing: https://github.com/Schimi1983/ioBroker.zigbee/tarball/feat/last-seen

🤖 Generated with Claude Code

https://claude.ai/code/session_013Q82LhA9wBMqm1L1powvy6

New option "Save the time of the last message per device (last_seen)"
(Settings tab, default off). When set, every incoming message writes the
timestamp (device.lastSeen from herdsman) to <device>.last_seen
(type number, role value.time) - like zigbee2mqtt's advanced.last_seen.
The state is lazy: it is only created for devices that send a message
while the option is on. Option off (default) = no change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Q82LhA9wBMqm1L1powvy6
@asgothian

Copy link
Copy Markdown
Collaborator

I see no value in this state. It generates additional traffic for every state that is being set, without generating additional usable info.

The functionality is already available checking the last changed characteristic of the msg_from_zigbee state, which can already be used in scripts / visualisations

As such, i would need further justification to merge this PR.

@Schimi1983

Copy link
Copy Markdown
Contributor Author

Fair point – the timestamp of msg_from_zigbee already gives this information, and an extra write per message is exactly what I want to avoid elsewhere. I'll close this PR (and drop the planned follow-up that would have made msg_from_zigbee optional, since it is the source for "last seen").

Thanks for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants