kabbi / zigbee2mqtt-adapter

zigbee2mqtt adapter for WebThings gateway
Mozilla Public License 2.0
21 stars 13 forks source link

Configuration for "homeassistant: true" Not Persisting #47

Closed ben-digitalhive closed 2 years ago

ben-digitalhive commented 2 years ago

Hi, Really like the addon and have had it working beautiful as a gateway transmitting to homeassistant in the past. Now that I wish to push forward with my project I cannot figure out how I got it to work previously and I think there is something awry with the configuration files.

I have things connected and correctly transmitting to home assistant and the home assistant integration is sniffing the payloads off the broker (example below). But the formatting of them is I believe not what homeassistant is expecting. The original z2m project has a configuration for this to make it easy to pass data through to HA but when I manually adjust the configuration.yaml this is continually overwitten.

Here is an example of a payload not in HA format:

Message 219 received on zigbee2mqtt/0x60a423fffe3d56ca at 10:21 PM:
{
    "battery": 73,
    "humidity": 71.47,
    "linkquality": 131,
    "temperature": 21.18,
    "voltage": 2800
}

Here is an example of a payload showing the bridge configuration - note homeassistant: false even though I have configured it.

Message 200 received on homeassistant/bridge/info at 10:21 PM:
{
    "commit": "41b67fd",
    "config": {
        "advanced": {
            "adapter_concurrent": null,
            "adapter_delay": null,
            "availability_blacklist": [],
            "availability_blocklist": [],
            "availability_passlist": [],
            "availability_timeout": 10,
            "availability_whitelist": [],
            "cache_state": true,
            "cache_state_persistent": true,
            "cache_state_send_on_startup": true,
            "channel": 11,
            "elapsed": false,
            "ext_pan_id": [
                221,
                221,
                221,
                221,
                221,
                221,
                221,
                221
            ],
            "homeassistant_discovery_topic": "homeassistant",
            "homeassistant_legacy_entity_attributes": true,
            "homeassistant_legacy_triggers": true,
            "homeassistant_status_topic": "hass/status",
            "ikea_ota_use_test_url": false,
            "last_seen": "disable",
            "legacy_api": false,
            "log_directory": "/home/pi/.webthings/data/zigbee2mqtt-adapter/log",
            "log_file": "Zigbee2MQTT-adapter-%TIMESTAMP%.txt",
            "log_level": "debug",
            "log_output": [
                "console",
                "file"
            ],
            "log_rotation": true,
            "log_symlink_current": false,
            "log_syslog": {},
            "pan_id": 6754,
            "report": false,
            "soft_reset_timeout": 0,
            "timestamp_format": "YYYY-MM-DD HH:mm:ss"
        },
        "ban": [],
        "blocklist": [],
        "device_options": {
            "legacy": false,
            "simulated_brightness": {
                "delta": 2,
                "interval": 100
            }
        },
        "devices": {
            "0x60a423fffe3d56ca": {
                "friendly_name": "0x60a423fffe3d56ca"
            }
        },
        "experimental": {
            "output": "json"
        },
        "external_converters": [],
        "groups": {},
        "homeassistant": false,
        "map_options": {
            "graphviz": {
                "colors": {
                    "fill": {
                        "coordinator": "#333333",
                        "enddevice": "#CCCCCC",
                        "router": "#666666"
                    },
                    "font": {
                        "coordinator": "#ffffff",
                        "enddevice": "#000000",
                        "router": "#ffffff"
                    },
                    "line": {
                        "active": "#5d9bc7",
                        "inactive": "#554444"
                    }
                }
            }
        },
        "mqtt": {
            "base_topic": "homeassistant",
            "force_disable_retain": false,
            "include_device_information": false,
            "server": "............[.....]
ben-digitalhive commented 2 years ago

As per the debug log it looks like it creates a new config file everytime

2021-10-31 15:59:44.330 INFO   : zigbee2mqtt-adapter: - USB stick spotted at: /dev/ttyACM0
2021-10-31 15:59:44.332 INFO   : zigbee2mqtt-adapter: line: 
2021-10-31 15:59:44.334 INFO   : zigbee2mqtt-adapter: this.zigbee2mqtt_data_dir_path =  /home/pi/.webthings/data/zigbee2mqtt-adapter
2021-10-31 15:59:44.335 INFO   : zigbee2mqtt-adapter: this.zigbee2mqtt_dir_path =  /home/pi/.webthings/data/zigbee2mqtt-adapter/zigbee2mqtt
2021-10-31 15:59:44.337 INFO   : zigbee2mqtt-adapter: this.config.local_zigbee2mqtt = true
2021-10-31 15:59:44.338 INFO   : zigbee2mqtt-adapter: zigbee2mqtt folder existed.
2021-10-31 15:59:44.340 INFO   : zigbee2mqtt-adapter: in run_zigbee2mqtt
2021-10-31 15:59:44.341 INFO   : zigbee2mqtt-adapter: Checking if config file exists
2021-10-31 15:59:44.343 INFO   : zigbee2mqtt-adapter: basic configuration.yaml file was succesfully created!
2021-10-31 15:59:45.382 INFO   : Finished updating add-ons
flatsiedatsie commented 2 years ago

I don't quite follow. Home Assistant? You're connecting your Webthings Gateway to Home Assistant somehow? Are you using this addon to run Zigbee2MQTT on the same system as a home assistant install?

The addon indeed creates a new configuration file every time. The addon is designed for WYSIWYG users, and you're not supposed to make manual changes to the configuration file.

ben-digitalhive commented 2 years ago

Hello - In the Z2M configuration there is a standard option in the configuration.yaml

''' homeassistant = false

It used to be that I could set this to true via SSH until more recent updates of your addon.

What it does is format the MQTT messages that get sent/received so they seamlessly get picked up by Home Assistant.

Im unfortunatley not a coder otherwise I could have a crack at this myself but an answer to this would be to add a configuration option in the WYSIWYG for this "homeassistant" setting or better yet allow in the code for a fully custom configuration.yaml e.g. you could almost have an advanced option to just paste into a multiline box the required configuration file and then use that as your configuration?

flatsiedatsie commented 2 years ago

Ah I see.

Could you perhaps do a small test for me?

This command will allow you to edit the addon's code without the security features blocking the now modified addon. mkdir ~/.webthings/addons/zigbee2mqtt/.git

Around line 336 you will see: let base_config = "homeassistant: false\n" +

Then reboot.

Does the addon still function normally with the change?

flatsiedatsie commented 2 years ago

This should be fixed. If the issue persists, please re-open this issue.