ElectricBrainUK / UnraidAPI

A WIP open source Node JS API for controlling UNraid
GNU General Public License v3.0
125 stars 13 forks source link

[HA Plugin] Config not being read or saving in GUI, causing validation issue and unable to start. #32

Closed MostHated closed 3 years ago

MostHated commented 3 years ago

Describe the bug Home Assistant configuration for the Unraid API addon gets reset when attempting to save.

To Reproduce Steps to reproduce the behavior: After adding the repo, cloning, building, then once complete I go to the addon configuration page and attempt to modify any of the values, either in the input boxes or from the "edit yaml" submenu then hit "Save", the values are just reset to defaults.

I tried to go in manually and edit the file:

Details ```yaml { "name": "Unraid API", "version": "1.1", "slug": "unraid_api", "description": "An Unraid REST/MQTT Bridge for HA and other IOT platforms", "arch": ["armhf", "armv7", "aarch64", "amd64", "i386"], "startup": "before", "boot": "auto", "webui": "http://[HOST]:[PORT:80]", "options": { "MQTTBroker": "192.168.50.231", "MQTTPort": 1883, "MQTTUser": mqtt, "MQTTPass": mypass, "MQTTBaseTopic": unraidmqtt, "MQTTSecure": null, "MQTTSelfSigned": null, "MQTTRefreshRate": 5, "MQTTCacheTime": 5, "KeyStorage": config }, "schema": { "MQTTBroker": "str?", "MQTTPort": "int?", "MQTTUser": "str?", "MQTTPass": "str?", "MQTTBaseTopic": "str?", "MQTTSecure": "bool?", "MQTTSelfSigned": "bool?", "MQTTRefreshRate": "int?", "MQTTCacheTime": "int?", "KeyStorage": "str?" }, "ports": { "80/tcp": 3005 } } ```

While this is saved to disk, it is never loaded into the GUI, so the start button is not able to be pressed without failing the validation check. Permission on all the files in the plugin directory seemed to be fine, as least when comparing them to other plugins.

HomeAssistant: core-2021.3.4 supervisor-2021.03.9

Unraid API (HA plugin) Current version: 1.1

Unraid 6.9.1

Thanks, -MH

willnnotdan commented 3 years ago

Hey - thanks for this very detailed and helpful, the HA Plug in is in alpha at the moment, I will try to fix the issues as soon as possible but Im currently working on a major change for the application itself. In the mean time Id recommend using the docker on unraid as it is much more reliable

MostHated commented 3 years ago

Oh, I was under the impression that I needed both the HA plugin and the Unraid docker? I have the docker container setup and working on the Unraid side.

willnnotdan commented 3 years ago

Ah right that is great, you dont need both actually, you connect either the plug in or in this case the unraid docker to an mqtt broker. Once youve connected the unraid api to an mqtt broker you connect your home asssistant to the same broker and you should be good to go! (Let me know if you need help with the broker)

Details from Home assistant: https://www.home-assistant.io/docs/mqtt/broker/ How to connect that to the unraid api: https://github.com/ElectricBrainUK/UnraidAPI/wiki/Docker-installation (Fill in the mqtt details required)

MostHated commented 3 years ago

I have mosquito setup and running on my Unraid box already for my ZigBee devices. I would imagine that I can reuse that same instance? The information for it is what I had already put into the Unraid API docker, I just used a different MQTTBaseTopic from my Zigbee2Mqtt topic, it didn't seem to complain about it or anything. You will have to forgive me, the extent of my knowledge of MQTT begins and ends with what I needed to get my ZigBee stuff set up, lol.

Edit --- Looking at the docker logs, I see this:

> unraidapi@0.5.0 start
> cross-env NUXT_HOST=0.0.0.0 NODE_ENV=production node server/index.js
WARN mode option is deprecated. You can safely remove it from nuxt.config
Connected to mqtt broker
READY Server listening on **http://0.0.0.0:80**

So looks like that side of things is already good to go.

willnnotdan commented 3 years ago

No problem at all, my instructions should be clearer as well! That sounds like your setup is fine, but the basetopic has to be the one you have set up in home assistant for autodiscovery if you want autodiscovery to work. If you dont need it, and you want to manually configure entities you should be good to go (let me know if you need help with that, some basic details here: https://github.com/ElectricBrainUK/UnraidAPI/wiki/Home-Assistant-Integration)

MostHated commented 3 years ago

Ah yes, that makes sense about the discovery. It definitely looks like I am on the right path at least. I may just set up the entities manually and see how it goes. I am not sure if there would be any sort of issue having the two things share the same topic. It doesn't seem like it would, but I suppose I can just make some backups of things and give it a whirl.

I definitely appreciate the quick and informative replies. Your help has been much appreciated. I will see what I can work out and just message back here if I have any issues. :ok_hand:

**Edit - looking at Zigbee2Mqtt, it looks like it has it's own discovery capability built-in, as I never set/specified a discovery topic. So perhaps I can simply set one, and then continue to have both working just fine.

willnnotdan commented 3 years ago

I dont think it should be a problem either, I use zigbee2mqtt as well No problem, let me know how you get on!

MostHated commented 3 years ago

Looks like I am in business!

willnnotdan commented 3 years ago

Great news!

MostHated commented 3 years ago

It's not much, but at least it's all working. :+1:

One thing I noticed, though, was after a while of trying to get the dash to work, eventually the topics and data in MQTT for unraid was no longer there. I restarted the Unraid API docker and then it all showed up again. Is there an adjustment I need to make somewhere for update/retention?

willnnotdan commented 3 years ago

The environment variables MQTTRefreshRate (handles in seconds how frequently updates are scanned for and sent) & MQTTCacheTime (handles in minutes how long before all entities are updated) Are what you are after