hsakoh/switchbot-mqtt

device configuration file missing.

marcomow opened this issue · 13 comments

Hi! I'm getting this error

SwitchBotMqttApp.Logics.DeviceConfigurationManager[0] device configuration file missing.

I have no idea what needs to be fixed, any suggestions?

hsakoh commented

This error occurs when the device configuration file is missing at the launch of the internal service of the add-on.

After installing the add-on, it's necessary to configure your devices from the Ingress page.

Initially, set the 'AutoStartServices' in the add-on settings to 'false', open the Ingress page, enumerate your devices, and configure them.

Have you followed the steps below?
https://github.com/hsakoh/switchbot-mqtt/blob/main/INSTALLATION.md#device-configuration

Afterward, try starting the services from the Service Management tab. Once you confirm that it is detected as an MQTT device, it is recommended to set the 'AutoStartServices' option in the addon settings to 'true'.

I did as written, just repeated now with a clean install, clicking on "Fetch devices" doesn't have any effect (no devices get listed) and when I check the logs I still have the same error.
AutoStartServices is set on false

hsakoh commented

There is a possibility that the device cannot be obtained from SwitchBotAPI or some error has occurred.

Set the log level of the add-on to trace and try pressing the "Fetch Devices By SwitchBotApi" button again.
Then, please paste here what kind of log is output. (Please mask sensitive information such as MAC ID.)

Thanks for your help!

Here's the dump

23:25:08 warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35] No XML encryptor configured. Key {...} may be persisted to storage in unencrypted form.
23:25:08 info: Microsoft.Hosting.Lifetime[14] Now listening on: http://[::]:8098
23:25:08 info: Microsoft.Hosting.Lifetime[14] Now listening on: http://[::]:8099
23:25:08 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down.
23:25:08 info: Microsoft.Hosting.Lifetime[0] Hosting environment: Production
23:25:08 info: Microsoft.Hosting.Lifetime[0] Content root path: /app/
23:26:04 info: SwitchBotMqttApp.Logics.DeviceConfigurationManager[0] device configuration file missing.
23:26:05 info: SwitchBotMqttApp.Logics.DeviceConfigurationManager[0] device configuration file missing.

hsakoh commented

Normally, the following types of logs are generated:

05:28:02 trce: SwitchBotMqttApp.Logics.SwitchBotApiClient[0] Send GET, devices
05:28:03 trce: SwitchBotMqttApp.Logics.SwitchBotApiClient[0] Response GET, https://api.switch-bot.com/v1.1/devices ....
There is a possibility that an error is occurring in the process of generating a token from the API key and secret before calling the SwitchBot API. I will be distributing a version with enhanced log output, so please wait for approximately 30 minutes. I will post an update here when it's released.

Until then, please review your API key and secret settings.

hsakoh commented

@marcomow
I have released v1.0.4. Please try running it again and let me know what is output in the logs.

Thank you!

Not much have changed...

07:03:53 warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35] No XML encryptor configured. Key {...} may be persisted to storage in unencrypted form.
07:03:54 info: Microsoft.Hosting.Lifetime[14] Now listening on: http://[::]:8098
07:03:54 info: Microsoft.Hosting.Lifetime[14] Now listening on: http://[::]:8099
07:03:54 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down.
07:03:54 info: Microsoft.Hosting.Lifetime[0] Hosting environment: Production
07:03:54 info: Microsoft.Hosting.Lifetime[0] Content root path: /app/
07:05:56 info: SwitchBotMqttApp.Logics.DeviceConfigurationManager[0] device configuration file missing.

hsakoh commented

Perhaps, there may be a client-side issue where button-click events on the page are not being transmitted to the server. The Ingress page is created using BlazorServerApp, so a modern browser with capabilities like WebSocket support is required. What kind of browser are you using to access the page? Is it a modern browser like Chrome for PC?

When you open the following URL or press the buttons:

http://homeassistant:8123/hassio/ingress/cafb8c58_switchbot_mqtt

Do you see any errors or issues in the console in the F11 developer tools?

Actually I was using Chrome on Android, but now I tested with Chrome on Windows, same situation. Here what I see in the dev console
image

hsakoh commented

I've discovered one difference in your setup compared to mine. You are opening the Ingress page via HTTPS.

I have set up HA OS on my local network and I'm testing it via HTTP using a host name resolved to a private IP.

Would it be possible for you to try it with HTTP?

I'm still not sure how to secure the local environment with TLS...

It works when using http!

To access my HA instance I'm currently using the Cloudflared add-on that creates a Cloudflare Tunnel, that's why I needed to be on the local network to make the test.

Do you think it is possible to make the add-on work also on https?

hsakoh commented

The issue at hand was that the Ingress page used to configure device information does not work with HTTPS. As I understand it, the problem may be related to issues with the reverse proxy, such as Cloudflare Tunnel, not properly offloading WebSocket.

I believe that if the reverse proxy is configured correctly, it should be possible to run the Ingress page with HTTPS.

Within the addon, the Ingress page is used only when configuring devices and manually stopping/restarting internal services. In terms of runtime, if you have automatic startup of internal services, the Ingress page should not be necessary. In this context, it should not affect usability even if it doesn't operate over HTTPS.