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

MQTT configuration info available in the Configuration UI or corresponding YAML ? #22

Open
d2inco opened this issue Nov 6, 2024 · 19 comments

Comments

@d2inco
Copy link

d2inco commented Nov 6, 2024

Hello.

Any chance you could either make the MQTT Broker part of the Configuration UI, or alternatively, give an example of the 4 entries needed to get it up and running? I was able to locate a 'mqtt_server_address' and 'mqtt_port' in the error message and tried those, but still need to be able to get the MQTT User/Pass in there, as well

I'm running an external broker, and the reference to it in the documentation, "You can use an external broker other than the Mosquitto addon by configuring the MQTT integration with that broker's details" don't have the 4 specific yaml Keys that need to be set for an external broker. (If I understood Python better, I'd go diving into it, but... I don't).

Thank you!

@wingrunr21
Copy link
Owner

I'd like to keep to using service discovery vs storing credentials in plain text. I could add an option to the UI to fall back to the manual config options but you need the MQTT integration configured anyway for the entities to show up.

You configure the MQTT integration to use your broker:

Screenshot 2024-11-06 at 8 15 45 AM

That's mine for the mosquitto addon.

@d2inco
Copy link
Author

d2inco commented Nov 6, 2024

Ah yes, I do have the MQTT configured with my broker, port, the HASS username and pw in there. So, maybe it's just not fully getting passed to the Addon ?

@wingrunr21
Copy link
Owner

Can you post the error and your MQTT config? The Supervisor API shouldn't differentiate between using Mosquitto and something else

@d2inco
Copy link
Author

d2inco commented Nov 6, 2024

This is the MQTT Configuration for my external (within the home network):
image

This is the Config file of Xcdl-Itron-MQTT (rather than a GUI shot):

meter_port: 8081
cert_dir: /config/certs
cert_file: cert.pem
key_file: key.pem
ldfi: REDACTED

Yes, the meter_ip is confirmed and does show port 8081 open and responding.

This is the log capture after attempting to start the Xcel iTron MQTT is here:

 Add-on: Xcel iTron MQTT
 Bridge from Xcel iTron smart meters to MQTT
-----------------------------------------------------------
 Add-on version: 1.4.0
 You are running the latest version of this add-on.
 System: Debian GNU/Linux 12 (bookworm)  (amd64 / qemux86-64)
 Home Assistant Core: 2024.10.4
 Home Assistant Supervisor: 2024.10.3
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
s6-rc: info: service base-addon-banner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service base-addon-log-level: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service base-addon-log-level successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service init-xcel-itron-mqtt: starting
[09:26:38] INFO: Initializing Xcel iTron2MQTT
s6-rc: info: service init-xcel-itron-mqtt successfully started
s6-rc: info: service xcel-itron-mqtt: starting
s6-rc: info: service xcel-itron-mqtt successfully started
s6-rc: info: service legacy-services: starting
[09:26:39] INFO: Starting Xcel iTron2MQTT
[09:26:39] ERROR: Got unexpected response from the API: Service not enabled
s6-rc: info: service legacy-services successfully started
Traceback (most recent call last):
  File "/opt/xcel_itron2mqtt/main.py", line 83, in <module>
    meter = xcelMeter(INTEGRATION_NAME, ip_address, port_num, creds)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/xcel_itron2mqtt/xcelMeter.py", line 58, in __init__
    self.mqtt_client = self.setup_mqtt(self.mqtt_server_address, self.mqtt_port)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/xcel_itron2mqtt/xcelMeter.py", line 197, in setup_mqtt
    client.connect(mqtt_server_address, mqtt_port)
  File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 912, in connect
    self.connect_async(host, port, keepalive,
  File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 978, in connect_async
    raise ValueError('Invalid host.')
ValueError: Invalid host.
[09:26:40] INFO: Service Xcel iTron2MQTe exited with code 1 (by signal 0)
s6-rc: info: service legacy-services: stopping
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service xcel-itron-mqtt: stopping
s6-rc: info: service xcel-itron-mqtt successfully stopped
s6-rc: info: service init-xcel-itron-mqtt: stopping
s6-rc: info: service init-xcel-itron-mqtt successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service base-addon-log-level: stopping
...

So I'd think that there should be a client.username_pw_set(username,password) in stack trace, too, somewhere that maybe isn't being set? But again, I'm not a Python guy, so...

@wingrunr21
Copy link
Owner

The Mosquitto addon also uses a username and password, so using an external broker should not be different. But, for sake of completeness: here's where the username/password is set in the upstream project and here is where this addon extracts the credentials

The error is saying "Invalid host". It's not clear to me if that's because of that "Service not enabled" API error or if your config is incorrect. Are you using the MQTT integration for other things successfully? Have you restarted your Home Assistant instance (a quick Google showed several issues on the wmbusmeters project with the same error saying a restart fixed it for some reason).

@d2inco
Copy link
Author

d2inco commented Nov 6, 2024

Yeah, I use the MQTT successfully (407 devices, 501 entities).

I see the two code-links you provided, and it makes some sense with:

export MQTT_USER=$(bashio::services mqtt "username")
export MQTT_PASSWORD=$(bashio::services mqtt "password")
export MQTT_PORT=$(bashio::services mqtt "port")

that if the bashio::services works right, it should pull the host/port/un/pw, but without it showing up in debug logs, i can't verify that it's working... plus, like you said, it does show 'invalid host' which means it's not getting there... I'm not seeing any negative lines in the mosquitto line on the broker indicating a failed connection (or even the first line of "new connection from").

I had already restarted HA this morning, but went ahead and just did it, with no change. I'd wonder if it's a routing issue, with potentially the container not routing to non-containers, but that would not make sense since others would then be having issues with the Xcel meter not being reachable.

For what it's worth, I tried adding host port username and password that the python referenced into the config yaml under the Xcel iTron MQTT GUI/configuration tab, but no change there... still the 'invalid host' error.

on The link you sent above, is there any way to have it use the "bashio::log.info" to output the MQTT Server/Port/User (not Password) ENV variables after bashio::services has attempted to fetch them, to make sure they're even being fetched correctly? Say, after line 16?

@wingrunr21
Copy link
Owner

Sure, just pushed a commit to the next branch with the logging. Can you install off of that branch?

@d2inco
Copy link
Author

d2inco commented Nov 6, 2024

Would love to, but, naively, "how" - I ended up uninstalling then reinstalling, figuring that I would get the prompt for Main vs (other) branch there, but that didn't happen (had saved my config, hopefully it'll still work). Attempting to add a new repo of "https://github.com/wingrunr21/hassio-xcel-itron-mqtt/tree/next" failed, as well. I know i'vee seen a branch-choice dropdown before, but not seeing it under the Addon, the upper-right overflow 3-dot menu, or ... google-search is not being helpful..

@wingrunr21
Copy link
Owner

ok, this is a low-risk change so I'll just push a patch version then

@d2inco
Copy link
Author

d2inco commented Nov 6, 2024

[11:53:45] INFO: Starting Xcel iTron2MQTT
[11:53:45] ERROR: Got unexpected response from the API: Service not enabled
s6-rc: info: service legacy-services successfully started
[11:53:45] INFO: Meter config: 192.168.XcelMeterIPWasHere:8081
[11:53:45] INFO: MQTT server config: :
Traceback (most recent call last):
  File "/opt/xcel_itron2mqtt/main.py", line 83, in <module>
    meter = xcelMeter(INTEGRATION_NAME, ip_address, port_num, creds)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/xcel_itron2mqtt/xcelMeter.py", line 58, in __init__
    self.mqtt_client = self.setup_mqtt(self.mqtt_server_address, self.mqtt_port)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/xcel_itron2mqtt/xcelMeter.py", line 197, in setup_mqtt
    client.connect(mqtt_server_address, mqtt_port)
  File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 912, in connect
    self.connect_async(host, port, keepalive,
  File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 978, in connect_async
    raise ValueError('Invalid host.')
ValueError: Invalid host.
[11:53:46] INFO: Service Xcel iTron2MQTe exited with code 

So it looks like maybe its not fetching it?

@wingrunr21
Copy link
Owner

wingrunr21 commented Nov 6, 2024

Ya, seems like it. It's gotta be this: ERROR: Got unexpected response from the API: Service not enabled. I wonder if the Supervisor only enables the MQTT service when the Mosquitto addon is installed.

I have a random idea: can you install the Mosquitto addon and not start it or otherwise change your MQTT config and see if things work?

I looked up the Supervisor code and it seems they are using the addon config, not the integration config. So I'll need to add this config to the UI

@d2inco
Copy link
Author

d2inco commented Nov 6, 2024

I really don't want to do that; I don't have a dev-system to try stuff out on, and i have too many things that talk to/through MQTT and don't want to risk them saying "oh, now I have a broker install locally, let me shift to that"...

Lemme ask this - are the bash lines export MQTT_SERVER=$(bashio::services mqtt "host") pulling from the installed service broker, or are they asking the integration what the config values are, isntead?

Just saw your edit (good! really didn't want to do that!) -- is there a way to query the Intergration config-setting vs the mqtt broker Service setting?

@wingrunr21
Copy link
Owner

Ya, I can have the config lookup fall back to the services call if the UI config isn't set. I just need to add that to the UI and test it.

@robmaurizio
Copy link

any update on this?
Seems to work fine with the HA Mosquitto add-on but I cannot seem to get this Xcel iTron add-on to locate an external broker address. Tried to dig through but wasn't able to find the files from the logs.

@wingrunr21
Copy link
Owner

Yep: update is it hasn't been implemented

@robmaurizio
Copy link

Understood - thanks for the response :)

@wingrunr21
Copy link
Owner

Hi everyone,

I just pushed two updates to main:

  1. There is now an edge version of the addon where I can test things. This should be considered an unstable version
  2. The edge addon has the ability to manually configure the MQTT server. Those settings will override service discovery if you have the mosquito broker enabled as well. If folks want to give that a test and let me know if it's working for them, I'd appreciate it!

@robmaurizio
Copy link

Thanks. I've moved over to the edge add-on. Thanks!

@wingrunr21
Copy link
Owner

Is it working? I'd like to move this into the stable version but need testers

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