Skip to content

Publish the tariff 1/2 energy counters in the Home Assistant format - #1337

Merged
gskjold merged 1 commit into
mainfrom
ha-tariff-counters
Dec 4, 2026
Merged

gskjold merged 1 commit into
mainfrom
ha-tariff-counters

Conversation

@gskjold

@gskjold gskjold commented Nov 26, 2026

Copy link
Copy Markdown
Member

Why

#1333: on an Iskra IE.5 (Croatia), the web UI shows the tariff 1/2 energy counters (1.8.1/1.8.2, 2.8.1/2.8.2, decoded for that meter since #1321), but Home Assistant doesn't get them.

The JSON format already publishes them as tPIT1/tPIT2/tPOT1/tPOT2, and the Raw format publishes them under …/accumulated/tariff1|2. The Home Assistant format's /energy payload (ha2.json) only had tPI/tPO/tQI/tQO, and no discovery sensors existed for the tariff registers.

Changes

  • ha2.json / publishList3(): add tPIT1, tPIT2, tPOT1, tPOT2 to the /energy payload, using the same keys as the JSON format.
  • HomeAssistantStatic.h: add four discovery sensors ("Accumulated active import/export tariff 1/2", kWh, energy, total_increasing). The import pair is announced once either import tariff register is non-zero, and the export pair once either export register is non-zero. This follows the pattern of the existing export sensors, so meters without tariff registers don't get sensors stuck at 0.
  • The new init flags are reset with the others on HA online and on config change.

The "choose which values to publish" part of the issue is not included.

Verification

  • pio run -e esp8266 and pio run -e esp32 build.
  • The template has no compile-time format check (PROGMEM), so I rendered ha2.json on the host with the 8 counters and 2 timestamps in the same order as the snprintf_P arguments, and checked that the result parses as JSON with the expected keys.
  • Not tested on a device or against a Home Assistant instance. That still needs a meter that reports tariff registers.

Refs #1333

🤖 Generated with Claude Code

The JSON and Raw MQTT formats already carry 1.8.1/1.8.2 and 2.8.1/2.8.2,
but the Home Assistant /energy payload only had the totals, so meters
that report per-tariff registers showed them in the web UI and not in HA.

Add tPIT1/tPIT2/tPOT1/tPOT2 (same keys as the JSON format) to the energy
payload, with discovery sensors that are announced only once a tariff
register is non-zero, so meters without them get no sensors stuck at 0.

Refs #1333

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

🔧 PR Build Artifacts

Version: c69e6a1

All environments built successfully. Download the zip files:

Artifacts expire after 7 days. View workflow run

@gskjold gskjold added this to the v2.6.1 milestone Nov 26, 2026
@chax

chax commented Nov 26, 2026

Copy link
Copy Markdown

I have tested this PR build artifact on my esp32c3 and it works, now i get Tariff counters in HomeAssistant.

@gskjold
gskjold merged commit 1a08ce4 into main Dec 4, 2026
8 checks passed
@gskjold
gskjold deleted the ha-tariff-counters branch December 4, 2026 09:15
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