Skip to content

Fix truncated energy counter in Domoticz MQTT payload - #1278

Merged
gskjold merged 1 commit into
mainfrom
fix/domoticz-energy-truncation
Oct 15, 2026
Merged

gskjold merged 1 commit into
mainfrom
fix/domoticz-energy-truncation

Conversation

@ArnieO

@ArnieO ArnieO commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Problem

In DomoticzMqttHandler::publish(), the energy device payload "<power W>;<energy Wh>" is formatted into char val[16]. snprintf silently truncates at 15 characters, dropping trailing digits of the counter. Example with a counter of 123 456 kWh:

  • 850 W → 850.0;12345600 → correct
  • 1250 W → 1250.0;1234560 → counter reported as 1/10 of the actual value

This happens with a counter ≥ 100 000 kWh and power ≥ 1000 W, or a counter ≥ 10 000 kWh and power ≥ 10 kW. Domoticz then logs huge negative/positive energy deltas each time power crosses the threshold.

Reported in discussion #1277

Fix

  • Energy buffer: val[16] → val[32]
  • Current buffer ("%.1f;%.1f;%.1f"): val[16] → val[32], since it would also truncate when any phase current is ≥ 100 A
  • All snprintf / snprintf_P calls use sizeof(val) instead of a hardcoded 16

Voltage buffers are unchanged in size; their content is at most 7 characters.

Testing

Not tested on hardware. Suggested check: Domoticz output enabled with a meter counter above 100 000 kWh, import power above and below 1000 W. Verify that the svalue in domoticz/in keeps the full counter value.

Targeted for v2.6.0.

@ArnieO
ArnieO requested a review from gskjold October 3, 2026 12:43
@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown

🔧 PR Build Artifacts

Version: da8a22a

All environments built successfully. Download the zip files:

Artifacts expire after 7 days. View workflow run

@gskjold
gskjold merged commit e2b46b1 into main Oct 15, 2026
8 checks passed
@gskjold
gskjold deleted the fix/domoticz-energy-truncation branch October 15, 2026 06:27
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