Skip to content

Fix Home Assistant discovery: entity IDs and retained config - #73

Merged
BorisBrock merged 3 commits into
BorisBrock:mainfrom
sadilek:fix/mqtt-discovery
Aug 4, 2026
Merged

BorisBrock merged 3 commits into
BorisBrock:mainfrom
sadilek:fix/mqtt-discovery

Conversation

@sadilek

@sadilek sadilek commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Two problems with the discovery messages.

All 15 payloads set default_entity_id to a bare object id, e.g. "%_charging_power". Home Assistant validates that field with cv.entity_id, which requires domain.object_id, so every payload fails validation and a fresh install gets sensor.unnamed_device, number.unnamed_device and so on. It also can't be repaired from the UI: because the integration supplies an entity id at all, HA treats the ids as explicitly chosen and "Recreate entity IDs" reports "No renamable entity IDs". The fix derives the domain from the discovery topic so the two can't drift apart. (The error quoted in #58 is against number.unnamed_device — that issue was about the value and is correctly fixed; the naming just went unremarked.)

Discovery is also published unretained. Since it is only sent from OnMqttConnect, a Home Assistant restart finds nothing under homeassistant/+/+/config. Sensors disguise this by publishing state continuously, but everything with a command_topic — both switches and the number — stays unavailable until the device reconnects.

Entity ids are sticky once registered, so this renames nothing that already exists. Affected users need to delete the MQTT device and let discovery recreate it; worth a line in the release notes.

Not included: the Enable Charging unique_id is missing the underscore every other entity has. I fixed only its default_entity_id, since changing unique_id would orphan the entity and lose its history. Happy to send that
separately.

sadilek and others added 3 commits August 3, 2026 20:52
Home Assistant validates default_entity_id with cv.entity_id, which lowercases
the value and then requires the form "domain.object_id". All 15 discovery
payloads supplied a bare object id such as "%_charging_power", so every one
failed validation and the entity fell back to Home Assistant's placeholder
name, producing sensor.unnamed_device, sensor.unnamed_device_2 and so on.

Because the integration supplies an entity id at all, Home Assistant also
treats these ids as explicitly chosen, so the device page's "Recreate entity
IDs" action reports "No renamable entity IDs" and refuses to correct them.

The domain is taken from the discovery topic each payload is published to, so
the two cannot drift apart. The switch payload for Enable Charging was also
missing the underscore separator that every other entity uses; only the
default_entity_id is corrected here, its unique_id is deliberately left alone
because changing that would orphan the entity for existing installations.

Note for existing installations: entity ids are sticky once registered, so
this does not rename anything that already exists. Affected users need to
delete the MQTT device in Home Assistant and let discovery recreate it.
Discovery is only published from OnMqttConnect, i.e. when this device connects
to the broker. Published unretained, the messages are delivered only to
subscribers that happen to be listening at that moment, so a Home Assistant
instance that restarts afterwards finds nothing under homeassistant/+/+/config.

Entities that publish state continuously appear to survive this, but everything
with a command_topic (both switches and the number) stays "unavailable" until
this device happens to reconnect, which in normal operation may not be for days.
Retained discovery is delivered as soon as Home Assistant subscribes.
@BorisBrock

Copy link
Copy Markdown
Owner

Thank you for the contribution!

@BorisBrock
BorisBrock merged commit 97f6dcf into BorisBrock:main Aug 4, 2026
3 checks passed
sadilek added a commit to sadilek/HeidelBridge that referenced this pull request Aug 4, 2026
Comment-only: trims the explanatory comments to match what was submitted
upstream, after Boris deleted the equivalent comment when merging BorisBrock#73. No
functional change, so the running firmware does not need reflashing.
@sadilek
sadilek deleted the fix/mqtt-discovery branch August 4, 2026 09:15
sadilek added a commit to sadilek/HeidelBridge that referenced this pull request Aug 4, 2026
…rock#75, BorisBrock#76) into kupa5

Our three fixes are now upstream, so the fork no longer carries them. Boris made
two edits when merging: ClampToWallboxRange and WriteCurrentLimitRegister moved
from a file-local anonymous namespace to private members of HeidelbergWallbox,
and InitialChargingCurrentLimitA is now defined as MaxChargingCurrentA instead
of repeating 16.0f.

Conflicts resolved in favour of upstream throughout, except for two items that
stay fork-specific in MQTTManager.cpp:

- The Enable Charging unique_id keeps its underscore. Upstream still has
  "%control_enable_charging"; reverting ours would orphan the existing entity in
  Home Assistant and break the automation that references it by entity id.
- The diagnostic echo to {DeviceName}/internal/last_command is kept. It is not
  upstream and is deliberately not proposed, since it adds public topic surface.

Also adopted from upstream: the discovery publish retry (publish() can silently
return 0 when the TCP send buffer is full) and the Last Will plus
availability_topic on every entity, which together complement the retained
discovery from BorisBrock#73.
sadilek added a commit to sadilek/HeidelBridge that referenced this pull request Aug 4, 2026
All three fixes are upstream now, so the "candidates for a PR" framing was
stale. Replaced with a short history keyed to BorisBrock#73/BorisBrock#74/BorisBrock#75, plus Boris's edits
when merging: the two helpers became private members, and
InitialChargingCurrentLimitA is defined as MaxChargingCurrentA.

Added an explicit list of what kupa5 still diverges on, so a future upstream
merge does not discard it: the Enable Charging unique_id underscore (reverting
would orphan the Home Assistant entity the automation references) and the
diagnostic echo topic.
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.

3 participants