Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Home Assistant 2023.8 MQTT #20

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

amadeo-alex
Copy link

@amadeo-alex amadeo-alex commented Aug 11, 2023

This PR:

  • Adds changes required to be compatible with MQTT requirements of Home Assistant 2023.8 and up (Bug: MQTT entity name starts with the device name in your config - HA 2023.8  HASS.Agent#337)
    • adds "object_id" property support to the discovery message (which is used by HA to generate entity ids)
    • modifies the MQTT topic to use the "object_id" instead of "name" property (details below)
      • "object_id" will be composed of device name and sensor name if not explicitly assigned (details below)
    • removes all explicit device name additions in Multi Value Sensors
    • adds a warning message when a new sensor/command is to be created with name containing the device name, and the HASS.Agent is connected to HA version 2023.8 and up
  • Adds "compat_names" launch argument which will
    • convert all compatible sensors and commands to use new naming scheme (details below)
    • republish the MQTT discovery topics
    • exit
  • Modifies HassApiManager to expose public HaVersion property
  • Adds CompatHelper class which should contain all compatibility related functions
  • Adds "Compatibility Task" interface and form to easily handle any future compatibility tasks

"object_id" logic:
Unless explicitly assigned in given sensor's or command's code, it will follow "_" scheme

Sensor/command conversion logic:

  • if the current sensor/command doesn't contain device name it will be skipped and has to be renamed manually
  • if the current sensor/command contains device name and uses pre 2023.8 naming i.e. "SOME-PC_cpuload" it will be converted to "cpuload"
  • if the current sensor/command contains device name and uses custom naming i.e. "someprefix_SOME-PC_cpuload" it will be skipped and has to be renamed manually

Compatibility interface running the name change task:
obraz

Warning message when trying to add a sensor/command containing the device name, and HASS.Agent is connected to HA version 2023.8 and up:
obraz


Comparison between "normal" and converted sensors/commands:

Before:
obraz
obraz

After:
obraz
obraz

Since the entity IDs stay the same (conversion task has a check for this) the entity history is preserved for HA:
(examples are taken after conversion task was run on 11.08.2023)
obraz
obraz
(please note that the "cpuload" sensor values are garbage due to performance counter bug - #16)

@bcutter
Copy link

bcutter commented Jul 22, 2024

Will this EVER make its way into a stable HASS agent release (still following LAB02-Research/HASS.Agent#337) ?

@amadeo-alex
Copy link
Author

As this is my PR I'll allow myself to answer.
With our best knowledge, not soon? Sam is currently MIA - we have a fork that we try to keep updated and put a new feature here and there: https://github.com/hass-agent/HASS.Agent?tab=readme-ov-file#fork

@bcutter
Copy link

bcutter commented Jul 22, 2024

As this is my PR I'll allow myself to answer. With our best knowledge, not soon? Sam is currently MIA - we have a fork that we try to keep updated and put a new feature here and there: https://github.com/hass-agent/HASS.Agent?tab=readme-ov-file#fork

Got it, started migrating already an hour ago, still on the first client. I now have plenty of MQTT topics: many with the old naming and few already with the new naming (formerly: Devicename_sensorname, now: DeviceUniqueID_sensorname). A bit of a mess in MQTT and therefore doubled entities (with _2 suffix) in Home Assistant... so it's a lot of work to clean everything and I still don't know if there's a more efficient way to do so (how to get rid of the old/original integrations' MQTT topics?).

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