Skip to content

fix: use UTC-aware timestamps in mqtt_uploader.py #258

@LaurisGale

Description

@LaurisGale

mqtt_uploader.py uses datetime.now().isoformat() in three places, which produces naive local-time timestamps with no timezone indicator (e.g. 2026-06-04T23:46:42.123456). On any Home Assistant host running in a non-UTC timezone, these timestamps are offset from UTC but carry no suffix to indicate that — so receiving brokers have no way to interpret them correctly.

This causes the following error on MeshCore-compatible brokers (e.g. CoreScope / LetsMesh(?) ):

Naive observer clock — timing is being clamped
This observer is emitting zone-less local-time timestamps and its clock is
currently Xh ahead of UTC. Per-packet rxTime for this observer is being
collapsed to ingest time, which muddies propagation-delay analytics.

Note: logbook.py is unaffected — it already correctly uses dt_util.utcnow().

Fix

Import timezone from the standard library and pass it to all three datetime.now() calls in mqtt_uploader.py:

# Before
from datetime import datetime
...
datetime.now().isoformat()   # lines 822, 1019, 1148
# After
from datetime import datetime, timezone
...
datetime.now(timezone.utc).isoformat()   # lines 822, 1019, 1148

This produces offset-aware ISO 8601 timestamps (e.g. 2026-06-05T17:46:42.123456+00:00) that brokers can unambiguously interpret as UTC.

Files changed

  • custom_components/meshcore/mqtt_uploader.py — 4 lines (1 import, 3 call sites)

Testing

Reproduced on a Home Assistant host in Europe/Vilnius (UTC+3). After this fix, broker clamp events stop and the error banner clears within 24 hours.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions