lolouk44 / hassio-addons

Xiaomi Mi Scale Add On for Home Assistant
MIT License
126 stars 42 forks source link

Addon doesnt start [Supervisor Installation] #67

Closed MariusHerget closed 1 year ago

MariusHerget commented 1 year ago

Select Add-On (place a lowercase x for the relevant add-on)

Describe the bug When starting the addon, everything seems normal with no errors, but the addon does not start / it crashes directly after.

To Reproduce Reproducible by (re-)starting the addon. Unfortunately, there are no errors and there seems to be no logging scheme that prints more (no "verbose" option). If I refresh the addon page in HA, it says "Start" again (indicating that it has terminated).

Expected behaviour Startup and stay up.

Logs No real error logs. Only this in the supervisor:

22-10-06 18:27:58 INFO (SyncWorker_7) [supervisor.docker.addon] Starting Docker add-on lolouk44/xiaomi-mi-scale-ha-add-on with version 0.3.4
22-10-06 18:28:02 ERROR (SyncWorker_7) [supervisor.docker.interface] Container addon_79ff755f_xiaomi_mi_scale is not running

AddOn Log:

-------------------------------------
2022-10-06 18:27:58 - Starting Xiaomi mi Scale...
2022-10-06 18:27:58 - Loading Config From Add-On Options...
2022-10-06 18:27:58 - Config Loaded...
2022-10-06 18:27:58 - MQTT Discovery Setup Completed...
-------------------------------------
2022-10-06 18:27:58 - Initialization Completed, Waiting for Scale...

Scale (please complete the following information):

Device running Home Assistant (please complete the following information):

Additional context hcitool

16:33:30 › hcitool dev
Devices:
        hci0    XX:XX:XX:XX:XX:X

Comment

lolouk44 commented 1 year ago

Can you share your [redacted] config please? I've removed the no longer required MISCALE_VERSION, wondering if it's still in it and maybe stopping the container from running?

MariusHerget commented 1 year ago
HCI_DEV: hci0
BLUEPY_PASSIVE_SCAN: true
MISCALE_MAC: XXX
MQTT_PREFIX: miscale
MQTT_HOST: localhost
MQTT_USERNAME: XXX
MQTT_PASSWORD: "XXX"
MQTT_PORT: 1883
MQTT_RETAIN: true
MQTT_DISCOVERY: true
MQTT_DISCOVERY_PREFIX: homeassistant
MQTT_TLS_CACERTS: Path to CA Cert File
MQTT_TLS_INSECURE: false
TIME_INTERVAL: 5
USERS:
  - NAME: XXX
    SEX: male
    GT: 60
    LT: 150
    HEIGHT: XXX
    DOB: "XXX"
lolouk44 commented 1 year ago

Not really sure what's wrong as others appear to have it working... I'm in the process of adding more logging anyway so if you give me a couple of days hopefully we can reveal a bit more of what's going on behind the curtains. QQ did it work on V0.3.3 or it just never worked since V0.3.x when I switched to bleak?

MariusHerget commented 1 year ago

No worries @lolouk44, I am gone for the weekend anyway :) I have one entry in my database from the 5th. I think that was 3.3, but I am not sure.

If you need any beta tester on Monday or afterwards, just mention me here! Thanks again :)

magiva commented 1 year ago

due to many breaking changes when bluetooth changed over i had something similar. check the diagnostic file from the bluetooth adapter in devices to see if your mac address is in it, if not, its probably a bluetooth issue before it gets to the addin. my fix was to stop and start the bluetooth device from a putty console

check with service bluetooth status image

then bluetooth stop, bluetooth start, bluetooth restart if needed

lolouk44 commented 1 year ago

@MariusHerget just pushed 0.3.5, which should be on docker in the next ~10-15min. The new verson adds more logging. Defaults to INFO level, I'd suggest you set it to DEBUG so we get more info (check the doc for more) Also after moving to bleak I realised I had forgotten to take care of multiple HCI interfaces, this has now been restored, in case it was your issue. Let me know how you get on.

MariusHerget commented 1 year ago

@lolouk44 thanks! Before my first insights: I restarted my server this morning (unrelated to hassio) and afterwards it worked again. Now I did another restart and it stopped working again.

Regarding the log level: On my side it defaults to error in the config after updating, setting it to DEBUG worked fine.

Log

2022-10-10 13:37:02 - Loading Config From Add-On Options...
2022-10-10 13:37:02 - (INFO) -------------------------------------
2022-10-10 13:37:02 - (INFO) Starting Xiaomi mi Scale v0.3.5...
2022-10-10 13:37:02 - (INFO) Loading Config From Options.json...
2022-10-10 13:37:02 - (INFO) Logging Level Set to DEBUG...
2022-10-10 13:37:02 - (DEBUG) MISCALE_MAC read from config: <*****>
2022-10-10 13:37:02 - (DEBUG) MQTT_USERNAME read from config: <*****>
2022-10-10 13:37:02 - (DEBUG) MQTT_PASSWORD read from config: ***
2022-10-10 13:37:02 - (DEBUG) MQTT_HOST read from config: localhost
2022-10-10 13:37:02 - (DEBUG) MQTT_RETAIN read from config: True
2022-10-10 13:37:02 - (DEBUG) MQTT_PORT read from config: 1883
2022-10-10 13:37:02 - (DEBUG) MQTT_TLS_CACERTS read from config: Path to CA Cert File
2022-10-10 13:37:02 - (DEBUG) MQTT_TLS_INSECURE read from config: False
2022-10-10 13:37:02 - (DEBUG) MQTT_PREFIX read from config: miscale
2022-10-10 13:37:02 - (DEBUG) MQTT_DISCOVERY read from config: True
2022-10-10 13:37:02 - (DEBUG) MQTT_DISCOVERY_PREFIX read from config: homeassistant
2022-10-10 13:37:02 - (DEBUG) HCI_DEV read from config: hci0
2022-10-10 13:37:02 - (DEBUG) BLUEPY_PASSIVE_SCAN read from config: False
2022-10-10 13:37:02 - (INFO) Config Loaded...
2022-10-10 13:37:02 - (INFO) MQTT Discovery Setup Completed...
2022-10-10 13:37:02 - (INFO) -------------------------------------
2022-10-10 13:37:02 - (INFO) Initialization Completed, Waiting for Scale...
2022-10-10 13:37:02 - (DEBUG) Using selector: EpollSelector
2022-10-10 13:37:02 - (ERROR) Unable to connect to Bluetooth: [org.freedesktop.DBus.Error.AccessDenied] An AppArmor policy
 prevents this sender from sending this message to this recipient; type="method_call", sender="(null)" (inactive) 
 interface="org.freedesktop.DBus" member="AddMatch" error name="(unset)" requested_reply="0" 
 destination="org.freedesktop.DBus" (bus)

So it definitely looks like a special bug for the supervised Hassio installations. I looked a little bit in the Hassio documentation and found this: https://developers.home-assistant.io/docs/add-ons/presentation/#apparmor

I am not experienced in any Hassio AddOn development or their underlying infrastructure, but it seems that we need an apparmor.txt in the repo with the correct permission settings (maybe something in the direction of this?).

lolouk44 commented 1 year ago

Thanks @MariusHerget . At least now we're heading somewhere 😃 Never dealt with this side of things so may not be a quick fix. Are you able to install a local add-on to help me test? For some reason I can't install it locally without posting it on docker.com 😞

MariusHerget commented 1 year ago

@lolouk44 Sure thing! Any preferred way for a more direct communication than Issue comments (Discord, signal, etc)?

lolouk44 commented 1 year ago

@MariusHerget discord is probably best: lolouk44#7180

mesut3000 commented 1 year ago

Hi,

I have same error. Here is my DEBUG mode log, still can not reach my scale.

2022-10-10 20:18:16 - Loading Config From Add-On Options... 2022-10-10 20:18:16 - (INFO) ------------------------------------- 2022-10-10 20:18:16 - (INFO) Starting Xiaomi mi Scale v0.3.5... 2022-10-10 20:18:16 - (INFO) Loading Config From Options.json... 2022-10-10 20:18:16 - (INFO) Logging Level Set to DEBUG... 2022-10-10 20:18:16 - (DEBUG) MISCALE_MAC read from config: 50:FB:19:38:11:CA 2022-10-10 20:18:16 - (DEBUG) MQTT_USERNAME read from config: mqtt 2022-10-10 20:18:16 - (DEBUG) MQTT_PASSWORD read from config: *** 2022-10-10 20:18:16 - (DEBUG) MQTT_HOST read from config: core-mosquitto 2022-10-10 20:18:16 - (DEBUG) MQTT_RETAIN read from config: True 2022-10-10 20:18:16 - (DEBUG) MQTT_PORT read from config: 1883 2022-10-10 20:18:16 - (DEBUG) MQTT_TLS_CACERTS read from config: Path to CA Cert File 2022-10-10 20:18:16 - (DEBUG) MQTT_TLS_INSECURE read from config: False 2022-10-10 20:18:16 - (DEBUG) MQTT_PREFIX read from config: miscale 2022-10-10 20:18:16 - (DEBUG) MQTT_DISCOVERY read from config: True 2022-10-10 20:18:16 - (DEBUG) MQTT_DISCOVERY_PREFIX read from config: homeassistant 2022-10-10 20:18:16 - (DEBUG) HCI_DEV read from config: hci1 2022-10-10 20:18:16 - (DEBUG) BLUEPY_PASSIVE_SCAN read from config: False 2022-10-10 20:18:16 - (INFO) Config Loaded... 2022-10-10 20:18:16 - (INFO) MQTT Discovery Setup Completed... 2022-10-10 20:18:16 - (INFO) ------------------------------------- 2022-10-10 20:18:16 - (INFO) Initialization Completed, Waiting for Scale... 2022-10-10 20:18:16 - (DEBUG) Using selector: EpollSelector

MariusHerget commented 1 year ago

I have same error. Here is my DEBUG mode log, still can not reach my scale.

I am currently working on a fix for the supervised installations. Are you running one?

mesut3000 commented 1 year ago

I have same error. Here is my DEBUG mode log, still can not reach my scale.

I am currently working on a fix for the supervised installations. Are you running one?

I am running my Home Assistant on Raspberry Pi 4 hardware, but I am not sure is it an answer to your question.

MariusHerget commented 1 year ago

I am running my Home Assistant on Raspberry Pi 4 hardware, but I am not sure is it an answer to your question.

Ok, then I would suggest waiting until @lolouk44 has validated and tested my solution and then updated the plugin. Hopefully, that fixes it for you aswell :)

mesut3000 commented 1 year ago

I am running my Home Assistant on Raspberry Pi 4 hardware, but I am not sure is it an answer to your question.

Ok, then I would suggest waiting until @lolouk44 has validated and tested my solution and then updated the plugin. Hopefully, that fixes it for you aswell :)

With "Bluetooth Low Energy Monitor" integration i can read from scale, so this means is no problem with bluetooth connection. I hope to fix it because i like this addon.

MariusHerget commented 1 year ago

I am running my Home Assistant on Raspberry Pi 4 hardware, but I am not sure is it an answer to your question.

Ok, then I would suggest waiting until @lolouk44 has validated and tested my solution and then updated the plugin. Hopefully, that fixes it for you aswell :)

With "Bluetooth Low Energy Monitor" integration i can read from scale, so this means is no problem with bluetooth connection. I hope to fix it because i like this addon.

It was an permission problem of accessing and communicating via the system bus with MQTT and BlueZ. If it works on BLE it is most likely the same issue on your side so just wait a little bit ;)

lolouk44 commented 1 year ago

Just pushed 0.3.6. Should be available within 15-20min. Thanks a bunch @MariusHerget for your help.

MariusHerget commented 1 year ago

I can confirm the updated version works for me!

mesut3000 commented 1 year ago

Mine situation didn't change. Not sure what am I doing wrong :(

MariusHerget commented 1 year ago

Mine situation didn't change. Not sure what am I doing wrong :(

Can you set the debug level to DEBUG and then send the full (redacted) log for the following stuff:

mesut3000 commented 1 year ago

Hi,

Here is my LOG:

(But I am not sure where to write "journalctl -e --no-pager | grep xiaomi_mi_scale")

Xiaomi Mi Scale 2022-10-10 23:49:35 - Loading Config From Add-On Options... 2022-10-10 23:49:35 - (INFO) ------------------------------------- 2022-10-10 23:49:35 - (INFO) Starting Xiaomi mi Scale v0.3.6... 2022-10-10 23:49:35 - (INFO) Loading Config From Options.json... 2022-10-10 23:49:35 - (INFO) Logging Level Set to DEBUG... 2022-10-10 23:49:35 - (DEBUG) MISCALE_MAC read from config: 50:FB:19:38:11:CA 2022-10-10 23:49:35 - (DEBUG) MQTT_USERNAME read from config: mqtt 2022-10-10 23:49:35 - (DEBUG) MQTT_PASSWORD read from config: *** 2022-10-10 23:49:35 - (DEBUG) MQTT_HOST read from config: core-mosquitto 2022-10-10 23:49:35 - (DEBUG) MQTT_RETAIN read from config: True 2022-10-10 23:49:35 - (DEBUG) MQTT_PORT read from config: 1883 2022-10-10 23:49:35 - (DEBUG) MQTT_TLS_CACERTS read from config: Path to CA Cert File 2022-10-10 23:49:35 - (DEBUG) MQTT_TLS_INSECURE read from config: False 2022-10-10 23:49:35 - (DEBUG) MQTT_PREFIX read from config: miscale 2022-10-10 23:49:35 - (DEBUG) MQTT_DISCOVERY read from config: True 2022-10-10 23:49:35 - (DEBUG) MQTT_DISCOVERY_PREFIX read from config: homeassistant 2022-10-10 23:49:35 - (DEBUG) HCI_DEV read from config: hci0 2022-10-10 23:49:35 - (DEBUG) BLUEPY_PASSIVE_SCAN read from config: False 2022-10-10 23:49:35 - (INFO) Config Loaded... 2022-10-10 23:49:35 - (INFO) MQTT Discovery Setup Completed... 2022-10-10 23:49:35 - (INFO) ------------------------------------- 2022-10-10 23:49:35 - (INFO) Initialization completed, step on scale to wake it up and get a weight value sent... Make sure the scale is within reach... 2022-10-10 23:49:35 - (DEBUG) Using selector: EpollSelector

MariusHerget commented 1 year ago

But I am not sure where to write \"journalctl -e --no-pager | grep xiaomi_mi_scale\

You need to connect to your raspberry pi via SSH and enter it there.

lolouk44 commented 1 year ago

Closing as working and New issue created by @mesut3000