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

Sensor not appearing in HA #8

Open
nerumo opened this issue Feb 5, 2025 · 8 comments
Open

Sensor not appearing in HA #8

nerumo opened this issue Feb 5, 2025 · 8 comments

Comments

@nerumo
Copy link

nerumo commented Feb 5, 2025

Hi
Thanks for this work. I'm testing some things out and I see the data in mqtt. But unfortunatly, I don't get any entities automatically discovered in HA. Is it supposed to support automatic discovery? Or is it meant to added manually? (even though I wouldn't know how :) )

In MQTT I see

{"availability_topic":"arch-container.marco-xps-15-9510/connected","device":{"identifiers":"linux_ha_bridge_arch-container.marco-xps-15-9510"},"name":"Do not disturb","payload_available":"on","payload_not_available":"off","payload_off":"false","payload_on":"true","state_topic":"arch-container.marco-xps-15-9510/dnd","unique_id":"linux_ha_control_arch-container.marco-xps-15-9510_dnd"}

and further, if I toggle the DND, I see the value flip flopping

Image

Is this more of an HA issue? Do I need to activate something in HA for discovery?

And again, thank you for your work.

@nerumo
Copy link
Author

nerumo commented Feb 5, 2025

Ah, I just found that HA has an (advanced) option for MQTT, where only certain prefixes are automatically discovered. By default, this is "homeassistant" :)

Here's an example of a topic from another project:

Topic: homeassistant/switch/train-motor-9C9AC000FBF2/config

{"name": "train-motor-9C9AC000FBF2", "state_topic": "homeassistant/switch/train-motor-9C9AC000FBF2/state", "availability_topic": "homeassistant/switch/train-motor-9C9AC000FBF2/available", "unique_id": "train-motor-9C9AC000FBF2", "device": {"name": "MoveHub", "identifiers": ["movehub-9C9AC000FBF2"]}, "command_topic": "homeassistant/switch/train-motor-9C9AC000FBF2/set", "payload_off": "off", "payload_on": "on"}

So if it's just that: could you make the prefix configurable?

@davidedmundson
Copy link
Owner

It is supposed to support automatic discovery.

There are HA related settings to having auto discovery on. Docs at: https://www.home-assistant.io/integrations/mqtt/#mqtt-discovery

I'm afraid you'll have to do a bit more digging your side.

@davidedmundson
Copy link
Owner

So if it's just that: could you make the prefix configurable

Sure.

@nerumo
Copy link
Author

nerumo commented Feb 5, 2025

Ok, for anyone finding this thread, here's a manual working config for HA (configuration.yaml)

mqtt:
  - binary_sensor:
      state_topic: "arch-container.marco-xps-15-9510/dnd"
      name: "marco-xps-15-9510 Do Not Disturb"
      payload_on: "true"
      payload_off: "false"
      qos: 0
      device_class: running

Nice, thank you. So...as soon as my meeting starts (DND on), a light outside my home office door will turn red :)

@jclsn
Copy link

jclsn commented Feb 9, 2025

I configured Mosquitto with a dedicated MQTT user, which I added to the kiotrc. Then I could add a new MQTT device and kiot appeared as "Unkown device".

@nerumo
Copy link
Author

nerumo commented Feb 17, 2025

It also appears for me now with the latest changes. The structure for HA autodiscovery isn't 100% right yet. The component name (aka device name in HA) is "unknown". I can have a look at that, might be the path of the topic. I'd say that the host name would be a good component name. What do you think?

@davidedmundson
Copy link
Owner

I can have a look at that,

Please do.

I just changed my hostname and also go the unknown device name too. I must have had some stray data from before in a refactor

The way it's meant to work is the entity info is sent once in:
ConnectedNode::ConnectedNode
then every other node has the same device (Entity::sendRegistration) and HA groups it all together.

I think you maybe just need to move

' config["device"] = QVariantMap({{"identifiers", "linux_ha_bridge_" + hostname() }});'

into the if statement above.

@davidedmundson
Copy link
Owner

I just pushed something that fixes device information being submitted

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

No branches or pull requests

3 participants