Skip to content

MQTT Publisher publishes incorrect TZ offset. Might be an issue in other places! #1204

@ingoratsdorf

Description

@ingoratsdorf

Is there an existing issue for this?

The issue occurs in the following browsers. Select at least 2.

  • Firefox
  • Chrome
  • Edge
  • Safari (unsupported) - PRs welcome
  • N/A - This is an issue with the backend

Current Behavior

I noticed some odd behaviour after the change to summer time today.
The MQTT sensors last connected are an hour ahead and the MQTT explorer shows some really weird timezone offset.

Image

I looked up the code in the MQTT publisher plugin and pasted it into the python console and sure enough it produces the same nonsense:

>>> dt=datetime.fromisoformat("2025-09-28 14:44:23")
>>> print(dt)
2025-09-28 14:44:23
>>> print(dt.tzinfo)
None
>>> dt=dt.replace(tzinfo=timezone("Pacific/Auckland"))
>>> print(dt)
2025-09-28 14:44:23+11:39

Totally wrong offset. We are now UTC+13:00

I googled some pytz issues and found this:
https://stackoverflow.com/questions/6410971/python-datetime-object-show-wrong-timezone-offset
UPDATE: Actually, the official pytz website states that you should always use localize or astimezone instead of passing a timezone object to datetime.datetime.

So I replicated the same in Python console:

>>> tz = timezone('Pacific/Auckland')
>>> print(tz)
Pacific/Auckland
>>> dt=datetime.fromisoformat("2025-09-28 14:44:23")
>>> dt=tz.localize(dt)
>>> print(dt)
2025-09-28 14:44:23+13:00

Correct result!

I'll update the MQTT publisher but this may be an issue in other places.

Expected Behavior

2025-09-28 14:44:23+13:00

Steps To Reproduce

No response

app.conf

docker-compose.yml

What installation are you running?

Production (netalertx)

app.log

No response

Debug enabled

  • I have read and followed the steps in the wiki link above and provided the required debug logs and the log section covers the time when the issue occurs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Docker 🐋Docker relatedbug 🐛Something isn't workingnext release/in dev image 🚀This is coming in the next release or was already released if the issue is Closed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions