Skip to content

Wrap string registers to avoid propagating null bytes, helps #736#737

Open
Gnarfoz wants to merge 5 commits into
mainfrom
wrap-string-registers
Open

Wrap string registers to avoid propagating null bytes, helps #736#737
Gnarfoz wants to merge 5 commits into
mainfrom
wrap-string-registers

Conversation

@Gnarfoz

@Gnarfoz Gnarfoz commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

As described in #736, reading the various Modbus version registers leaves some of the resulting sensors with trailing null bytes, if the string doesn't take up the full length of the registers.
This is bad because Home Assistant's recorder mechanism will try to persist these values including the null bytes. If someone is using a database backend that does not support this (like PostgreSQL), this will break recorder for them, system-wide. Recorder updates are batched, and if a batch includes an update to one of these sensors, it is effectively poisoned and will never be stored to the database.

Apart from changing the Modbus integration to provide an option to trim trailing null bytes (or do it unconditionally), wrapping the sensors in templates that do it and excluding the raw sensors from the recorder config seems like the lowest impact change to improve the situation.
I've added a warning to the installation documentation to point this out.

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