HA and zigbee2mqtt UI

Hi

I am running HA in docker by using a docker-compose file. Relevant configuration is like this:

version: '3.7'
services:
  homeassistant:
    container_name: homeassistant
    image: "ghcr.io/home-assistant/home-assistant:stable"
    volumes:
      - ${STORAGE}/homeassistant_data:/config
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
    privileged: false
    environment:
      - TZ=Europe/Stockholm
    network_mode: host
 
  zigbee2mqtt:
    container_name: zigbee2mqtt
    restart: unless-stopped
    privileged: false
    image: koenkk/zigbee2mqtt
    volumes:
      - ${STOR
      - /run/udev:/run/udev:ro
    ports:
      - 8080:8080
    environment:
      - TZ=Europe/Stockholm
    devices:
      -  /dev/ttyACM0:/dev/ttyACM0

In HA configuration file I have added a panel_iframe like this:

 default_config:
 mqtt:
   broker: localhost
   port: 1883

 panel_iframe:
   zigbee2mqtt:
     title: zigbee2mqtt
     icon: mdi:wrench
     url: http://172.18.0.2:8080/
     require_admin: false

Zigbee2Mqtt is like this:

# Home Assistant integration (MQTT discovery)
homeassistant: true
# allow new devices to join
permit_join: false
# MQTT settings
mqtt:
  # MQTT base topic for zigbee2mqtt MQTT messages
  base_topic: zigbee2mqtt
  # MQTT server URL
  server: 'mqtt://localhost'
  # MQTT server authentication, uncomment if required:
  # user: my_user
  # password: my_password
# Serial settings
serial:
  # Location of CC2531 USB sniffer
  port: /dev/ttyACM0

From a web browser I can access zigbee2mqtt UI by:


http://x.y.z.ĂĄ:8080

I was assuming it should be possible to access to the same web page by clicking on the icon in HA . It is not, not for me at least.

Also, please notice that in the HA configuration file, I have hard coded the IP address “172.18.0.2:8080” whereas when connecting to the mqtt host, I can write localhost and from the beginning I assumed that I could write http://localhost:8080, but I get a message that localhost can not be resolved.

So, I assume I am doing something wrong, but have looked at my lines of code to long …

Can anyone help?

The iframe is an iframe, it is not being proxied by Home Assistant. Thus you need to use whatever IP address you use to access the zigbee2mqttui in the browser. It is just like using a bookmark.
Localhost of course doesn’t work, because localhost is 127.0.0.1 so will only be access resources on the computer you are actually using the Home Assistant web interface on.

Yeah, localhost don’t work but zigbee2mqtt does not work either. I was reluctant to use IP because I am afraid that any change in docker-compose file can change allocated IP

But, that is how it is… I still cant access zigbee2Mqtt UI page from within HA. I get e timeout error.

You don’t have an option. Again - it is NOT being proxied by Home Assistant, it is no different to using a bookmark. You have to use whatever IP address you use to access it from any other device on the network. You cannot access it via it’s internal docker IP address nor can you access it via localhost.

If however you spin up NginxProxyManager it can be used to proxy the interface.

Not was I meant. I can live with using IP.

Still, using this setting:

panel_iframe:
zigbee2mqtt:
title: zigbee2mqtt
icon: mdi:wrench
url: http://172.18.0.2:8080/
require_admin: false

The host 172.18.0.2 is running zigbee2mqtt. Accessing it from within HA, I get a timeout.
Why ?

Because that IP address is only available on the same physical computer that is running the docker containers. If you are accessing the Home Assistant Web interface from a DIFFERENT computer - then it has no knowledge of that IP address, nor any way to reach it.

That’s the container’s internal IP. You need to point the iframe to the HA host’s external IP or name. Basically what you written here:

That’s the target url from the iframe.

1 Like

Thanks guys, now I got it.

But this also means that I have unwanted dependencies in my configuration file.

What I mean is, at the moment I am testing new stuff on my development computer.
When I move this configuration to my server I need to edit configuration files.

Is there a clever way to avoid this, like using environment variables or simular?

Sure. Change configuration to:

 panel_iframe:
   zigbee2mqtt:
     title: zigbee2mqtt
     icon: mdi:wrench
     url: !env_var HA_Z2M_UI_URL
     require_admin: false

and your compose file to

services:
  homeassistant:
    container_name: homeassistant
    environment:
      HA_Z2M_UI_URL: 'http://x.y.z.ĂĄ:8080'
    image: "ghcr.io/home-assistant/home-assistant:stable"
    volumes:
      - ${STORAGE}/homeassistant_data:/config
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
    privileged: false
    environment:
      - TZ=Europe/Stockholm
    network_mode: host
1 Like

Ahh great. Getting better and better :grinning:

I followed the steps you provided but got safe mode. this is my config file.

version: '3'
services:
  homeassistant:
    container_name: homeassistant
    environment:
      HA_Z2M_UI_URL: 'http://localhost:8099'
    image: "ghcr.io/home-assistant/home-assistant:stable"
    volumes:
      - /home/nanopim4/docker/homeassistant:/config
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
    privileged: false
    environment:
      - TZ=Asia/Shanghai
    network_mode: host

template: !include template.yaml
panel_iframe:
  zigbee2mqtt:
    title: zigbee2mqtt
    icon: mdi:wrench
    url: !env_var HA_Z2M_UI_URL
    require_admin: false
#panel_iframe: !include panel_iframe.yaml
light: !include light.yaml

This is log

2022-03-07 15:54:37 WARNING (SyncWorker_0) [homeassistant.util.yaml.loader] YAML file /config/sensor.yaml contains duplicate key "value_template". Check lines 224 and 225
2022-03-07 15:54:37 ERROR (SyncWorker_0) [homeassistant.util.yaml.loader] Environment variable HA_Z2M_UI_URL not defined
2022-03-07 15:54:37 ERROR (MainThread) [homeassistant.bootstrap] Failed to parse configuration.yaml: HA_Z2M_UI_URL. Activating safe mode
2022-03-07 15:54:42 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'None' has no attribute 'dynasty' when rendering

Somehow your environment variable defined in the compose file does not make it into the container. Did you use docker-compose up -d to re-create the stack?

Yes ,I stop ha,and rm ha, then i run docker-compose up -d.The problem is still

The error is caused by your compose file where you define the environment twice. The later definition counts and superseeds the first appearance. You can check the outcome of compose file interpretation by running docker-compose config.

Join the two sections into one:

environment:
  HA_Z2M_UI_URL: 'http://localhost:8099'
  TZ: Asia/Shanghai

PS: No need to stop the container and remove it, as docker-compose up -d will take care of it.

in the zigbee2mqtt/data/configuration.yaml do you have?

frontend: true