seime / openhab-esphome

ESPHome native API implementation for openHAB binding
MIT License
22 stars 4 forks source link

Reverts back to mDNS name #1

Closed xanderificnl closed 11 months ago

xanderificnl commented 11 months ago

After a restart of OpenHAB, the hostname of the ESPHome thing reverts to its mDNS name, instead of staying fixed to the IP address I specified in the configuration. This behavior is unexpected, as the IP address should persist across restarts.

As a temporary workaround, I'm using this bit of code via jrubyscripting:

esphome_smart_meter = things['esphome:device:smart-meter']
esphome_smart_meter.disable
esphome_smart_meter.configuration().put("hostname", "192.168.88.61")
esphome_smart_meter.enable

I also wanted to add that I'm particularly pleased to see this binding, thanks for your work!

seime commented 11 months ago

Hi @xanderificnl, cool that you enjoy the binding :)

I'm assuming UI based configuration? Does it happen every time you restart? I tried to reproduce this without success (disclaimer: not on my home network, might have some effect).

Could you set the log level to DEBUG and see if you can re-create the problem? In recent versions most log statements are prefixed with the config.hostname value so it should show when it happens.

I'm using the dns name for each ESP device, but have assigned a fixed IP in my router. The hostname property is also used as the representation property, so by using IP address instead of hostname the device will reappear in the inbox (unless you hide it explicitly).

Cheers

xanderificnl commented 11 months ago

Whenever OpenHAB starts, the log notes "--- new run ---" to separate instances clearly. After updating to the latest GitHub binding, I adjusted the config, removing the Thing and related automation. Following a restart, the device appears in the inbox, but struggles to connect.

Switching to the IP fixes this, but after restarting OpenHAB (second 'new run'), the binding reverts my config, causing connection issues. Finally, I reconfigured the binding with the IP again, disabled mDNS on my ESPHome device, and restarted OpenHAB again ('last new run'). This time the configuration wasn't reverted.

The mDNS advertisement seems to overrides my manual configuration.

esphome.log


In the standard setup, Fedora CoreOS (host) doesn't resolve mDNS queries, causing a similar issue for containers. I addressed this by enabling MulticastDNS in the systemd-resolved configuration. Nonetheless, I believe this bug report remains pertinent, as ~the binding~ OpenHAB continues to override manual configurations, leading to undesirable outcomes.

seime commented 11 months ago

I was able to reproduce this with GUI config.

Background mDNS discovery finds the ESP again and creates a discovery result. Somehow openhab takes the discovery result and overwrites the config property of the existing thing config with the discovery value.

Apparently a framework problem discovered a long time ago, but never fixed; https://community.openhab.org/t/is-here-anyone-using-volumio/16678/116

I reported it as a bug in openhab core; let's see what the response is. https://github.com/openhab/openhab-core/issues/3753

xanderificnl commented 11 months ago

Cheers, I'll close this issue in favour of the upstream one.