cmroche / OctoPrint-HomeAssistant

Home Assistant plugin for OctoPrint, enabling MQTT discovery of you device and sensors
110 stars 18 forks source link

Base topic is hardcoded #34

Closed short-circuit closed 3 years ago

short-circuit commented 4 years ago

Are there no settings for this plugin? It pretty much looks to me that the base topic is hardcoded and cannot be changed. I, for example, do not use the default base topic. Any way to change it?

By base topic I obviously mean the discovery topic for discover in Home Assistant (default: homeassistant/).

Example: image

EDIT: Just realized that even the printer name is hardcoded and defaults to "OctoPrint". So I suppose that all changes are to be done directly in code?

cmroche commented 4 years ago

hi @short-circuit the base topic can be set by modifying the base topic on the Octoprint-MQTT plugin settings. That's the setting used for the sensor data, and those are the settings used by this plugin to read/publish the sensor data.

The "homeassistant" topic is used only to announce the service to HA using it's own discovery protocol. As of current, there is no way for this to work with any other topic path so there is really no reason to make this topic configurable.

Not sure what you mean about the name being hard coded, this is definitely not the case. We'll use whatever name is configured for the OctoPrint server in the settings.

Could you clarify for me please why it is you want to change the homeassistant topic?

short-circuit commented 4 years ago

The "homeassistant" topic is used only to announce the service to HA using it's own discovery protocol. As of current, there is no way for this to work with any other topic path so there is really no reason to make this topic configurable.

It is possible. I use a custom discovery topic on my home assistant which is a different base topic than "homeassistant/". This is needed for multiple instances as I keep only one MQTT server. Each homeassistant has its own discovery topic:

Code_8LUmArT0xU

I modified the code directly in the plugin folder as a workaround and it works, which means I have to do it for every update of the plugin itself. A way to configure this would be nice.

Not sure what you mean about the name being hard coded, this is definitely not the case. We'll use whatever name is configured for the OctoPrint server in the settings.

For some reason, it doesn't take my Octoprint set name. Might have to try again later.


Thank you for the awesome plugin BTW 😃

cmroche commented 4 years ago

Thanks for the info. I didn't think it was actually possible to change this.

This plugin doesn't have a config template yet, fixing this would require that... so it isn't a trivial change. If you are interested in adding that feature, I'd be happy to take a pull request, otherwise I will look into it as my personal time permits.

ax42 commented 4 years ago

I have the same issue (I also use a custom discovery prefix), so would appreciate a fix.

edekeijzer commented 3 years ago

I ran into the same and have just created a fix and submitted a pull request. Currently it requires you to change the topic in config.yaml, but I'll look into adding a Settings page later.

cmroche commented 3 years ago

I've included your changes to release 2.2.1 @edekeijzer

If you do have some time to contribute a setting UI for this as well, it would be greatly appreciated. Thanks again though.

Apocrathia commented 3 years ago

Without UI controls, @edekeijzer's requires editing a configuration file (not a big deal). I'm using the OctoPi image, so I've never even touched any of the configuration files. What is the path to this file? I can push some documentation updates for anyone else in my situation.

Apocrathia commented 3 years ago

Answering my own post in case anyone else comes across this: The configuration file on the OctoPi image is located at ~/.octoprint/config.yaml. OctoPrint uses a single config.yaml, and the configuration for the discovery value is at

plugins:
  homeassistant:
    discovery_topic:

Thanks for your contributions. I have been looking at the OctoPrint plugin development guide for how to implement UI controls, and it doesn't look to hard. I might try and give it a shot later if I have time.