Skip to content

Uptime as boot timestamp, clearer icons, and less recorder bloat - #416

Open
milandzuris wants to merge 1 commit into
meshcore-dev:mainfrom
milandzuris:meshcore-improvements
Open

milandzuris wants to merge 1 commit into
meshcore-dev:mainfrom
milandzuris:meshcore-improvements

Conversation

@milandzuris

Copy link
Copy Markdown

Uptime as boot timestamp, clearer icons, and less recorder bloat

This PR has three parts. Each part only touches its own lines, so any of them can be dropped on request.


1. Uptime as a boot timestamp

What

The repeater Uptime sensor and the companion self-diagnostic Uptime sensor now use device_class: timestamp and hold the node's boot time. Before, they were a duration in minutes.

Why

  • The duration changed on every poll, so the entity always showed "changed x minutes ago" and its history was an ever-rising line.
  • HA core integrations (e.g. Shelly) expose uptime as a timestamp. The frontend shows it as relative time ("3 days ago"), and the state only changes when the device restarts, which makes restarts easy to spot in history and automations.

How

  • New helper boot_time_from_uptime() in utils.py computes boot = now - uptime, truncated to whole seconds.
  • The previous boot time is kept while a new estimate is within 60 s of it. Uptime arrives over LoRa a few seconds after the node sampled it, and the node clock drifts slightly. Without this tolerance the timestamp would jitter and write a new state on every poll.
  • A malformed sample (uptime 0 or missing) keeps the last known boot time.
  • Rate and utilization sensors still read the raw uptime seconds from the status payload, so they are unaffected.

Breaking change

  • The state is now an ISO timestamp, not minutes. Templates that read the number need to change, e.g. (now() - states('sensor.xxx_uptime') | as_datetime).total_seconds().
  • The sensor no longer has a state class, so HA will offer to delete the old long-term statistics in Developer tools → Statistics.

2. Icons

These sensors used the same generic icon (mdi:radio, mdi:battery, mdi:percent), so you couldn't tell them apart on a dashboard. Each now has an icon that matches what it measures:

Sensor Before After
Battery Voltage (repeater + companion) mdi:battery mdi:battery-charging
Battery Percentage mdi:battery (none: HA's dynamic battery-level icon)
Airtime / TX Airtime mdi:radio mdi:upload
RX Airtime mdi:radio mdi:download
Airtime Utilization, RX Airtime Utilization mdi:percent mdi:gauge
Neighbor Seen mdi:counter mdi:eye-outline
Frequency mdi:radio mdi:sine-wave
Bandwidth mdi:radio mdi:arrow-expand-horizontal
Spreading Factor mdi:radio mdi:chart-bell-curve
TX Power mdi:power mdi:flash

Telemetry sensors:

  • last_updated is removed because it changes on every reading.
  • raw_value is removed because it duplicates the state.
  • voltage is removed from the battery % sensor, because a separate Battery Voltage telemetry sensor is always created next to it.
  • Static attributes (channel, lpp_type, pubkey_prefix, node_type, node_name, field) stay, since the recorder deduplicates them.

Device tracker: last_updated is removed because it changes on every GPS reading.

Neighbor sensors are untouched; they already only change last_updated when the data changes (#410).

Not affected

  • No entity ID, unique ID, unit or value changes.
  • Availability still uses the internal timestamp, so sensors still go unavailable on timeout as before.
  • I checked RikoDEV/ha-meshcore-cards and jpettitt/meshcore-card. Neither reads any of the removed attributes.

Heads-up for card authors

jpettitt/meshcore-card decides whether a repeater is online from the state's last_updated on the Uptime entity. That value only moved on every poll because the attributes changed. After parts 1 and 3 it only moves on a restart. The request_successes counter goes up on every successful status poll and is a more reliable signal.


Tests

Full test suite passes, ruff check is clean.

- Uptime (repeater + companion) is now a timestamp sensor holding the boot
  time, stable between polls (60 s tolerance for LoRa latency and drift).
- Distinct icons for sensors that shared mdi:radio / mdi:battery / mdi:percent.
- Drop attributes that changed on every poll or duplicated other entities
  (repeater sensors, telemetry, device tracker) to stop recorder bloat.

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

This branch has not been deployed

No deployments
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.

1 participant