Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add port for zigbee2mqtt frontend #167

Closed
mpuff opened this issue Nov 3, 2020 · 6 comments
Closed

add port for zigbee2mqtt frontend #167

mpuff opened this issue Nov 3, 2020 · 6 comments

Comments

@mpuff
Copy link

mpuff commented Nov 3, 2020

Hello,

the latest zigbee2mqtt has a frontend now, please add this port to the config.

@Paraphraser
Copy link

Paraphraser commented Nov 3, 2020

Can you provide details? A link to the information would help.


I don't think zigbee2mqtt exposes any ports. Or, if it does, I can't see how.

As an example, I asked the Mosquitto image two questions:

  1. When was the image created?

    $ docker inspect eclipse-mosquitto | jq -r .[0].Created
    2020-10-22T02:54:57.435037136Z
    
  2. What ports does this image expose?

    $ docker inspect eclipse-mosquitto | jq -r .[0].Config.ExposedPorts
    {
      "1883/tcp": {}
    }
    

Now ask the zigbee2mqtt image the same questions:

$ docker inspect koenkk/zigbee2mqtt:latest | jq -r .[0].Created
2020-11-01T12:03:33.618785193Z

$ docker inspect koenkk/zigbee2mqtt:latest | jq -r .[0].Config.ExposedPorts
null

So, the latest zigbee2mqtt image created three days does not expose any ports.

Are you sure you are not talking about something else (eg "node-red-contrib-zigbee2mqtt")?

@mats-nk
Copy link

mats-nk commented Nov 4, 2020

I think this is the one mpuff is meaning: https://www.zigbee2mqtt.io/information/frontend.html

frontend:
port: 8080
experimental:
new_api: true

@Paraphraser
Copy link

Thanks @mats-nk - that makes sense.

I don't have CC2531 adapter so I can't test this directly, but I think this is what needs to be done. I'd appreciate it if someone else could test this and see if it works.

Step 0

Everything here assumes you are working in ~/IOTstack so your first command should be:

$ cd ~/IOTstack

Step 1

If you have not already installed zigbee2mqtt, run the menu:

$ ./menu.sh
  • Select "Build Stack:
  • Enable "zigbee2mqtt" (put the cursor on the line and hit SPACEBAR)
  • Press TAB to select <Ok> and press RETURN
  • Follow the process to the end choosing "Do not overwrite" for all other containers.

Do NOT run docker-compose up -d.

Step 2

Attach your CC2531 adapter to your Raspberry Pi.

Some reports say this should be done with a USB extension cable because connecting the adapter directly to the RPi port creates too much interference.

Make sure the adapter appears:

$ ls -l /dev/ttyACM0

If the device does not show up, you will need to work out why and fix it.

Step 3

Use your favourite text editor to open docker-compose.yml.

Find the zigbee2mqtt block. It looks like this:

  zigbee2mqtt:
    container_name: zigbee2mqtt
    image: koenkk/zigbee2mqtt
    volumes:
      - ./volumes/zigbee2mqtt/data:/app/data
    devices:
      - /dev/ttyAMA0:/dev/ttyACM0
      #- /dev/ttyACM0:/dev/ttyACM0
    restart: unless-stopped
    network_mode: host

Edit the devices area to look like this:

    devices:
      #- /dev/ttyAMA0:/dev/ttyACM0
      - /dev/ttyACM0:/dev/ttyACM0

Remember: don't use TABs in YAML files, only spaces.

Step 4

Bring up the zigbee2mqtt container:

$ docker-compose up -d zigbee2mqtt

Follow the log:

$ docker logs -f zigbee2mqtt

If zigbee2mqtt does not start normally, the container will probably restart and that terminates the logs command, returning you to the terminal session prompt. If that happens, you will need to work out what the log is telling you, fix the problem, and re-try.

However, if zigbee2mqtt starts normally and finds the CC2531 adapter, you will get a few log messages and things will appear to hang. Press Control+C to stop following the log, then take down the zigbee2mqtt container like this:

$ docker-compose stop zigbee2mqtt
$ docker-compose rm -f zigbee2mqtt

Step 5

The first run of zigbee2mqtt creates this file:

./volumes/zigbee2mqtt/data/configuration.yaml

Use sudo and your favourite text editor to open the above file. It looks like this:

# Home Assistant integration (MQTT discovery)
homeassistant: false

# allow new devices to join
permit_join: true

# 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
  1. Change the server line to look like this:

      server: 'mqtt://mosquitto'
    
  2. At the end of the file, add the following lines (the two blank lines are intentional):

    
    # Web front end
    frontend:
       port: 8080
    
    experimental:
       new_api: true
    

Remember: don't use TABs in YAML files, only spaces.

Save the file.

Now, use your favourite text editor to open docker-compose.yml and find the zigbee2mqtt block. Edit it to look like this:

  zigbee2mqtt:
    container_name: zigbee2mqtt
    image: koenkk/zigbee2mqtt
    volumes:
      - ./volumes/zigbee2mqtt/data:/app/data
    ports:
      - "8080:8080/tcp"
    devices:
      #- /dev/ttyAMA0:/dev/ttyACM0
      - /dev/ttyACM0:/dev/ttyACM0
    restart: unless-stopped

The two changes are:

  • Adding the ports area (two lines); and
  • Removing the network_mode: host line

Save the file.

For safety, you should also edit the following file to make it look the same:

./services/zigbee2mqtt/service.yml

If you don't make the same changes to service.yml, you risk losing the changes to docker-compose.yml the next time you run the menu. Keep in mind that choosing "pull full service from template" will reset both service.yml and docker-compose.yml. Be cautious!

Step 6

Bring up the zigbee2mqtt container:

$ docker-compose up -d zigbee2mqtt

As before, follow the log to look for signs of problems:

$ docker logs -f zigbee2mqtt

If everything looks OK then try connecting to your Raspberry Pi on port 8080.

Discussion

ttyACM0 vs ttyAMA0

It isn't clear why the IOTstack template for zigbee2mqtt references /dev/ttyAMA0 rather than /dev/ttyACM0. All the evidence suggests "ttyACM0" is correct.

If anyone knows of a situation where "ttyAMA0" would be appropriate, please explain and give an example.

Absent an example, it seems to me it would be appropriate to change the template to look like:

    devices:
      - /dev/ttyACM0:/dev/ttyACM0

Host mode

The template defines:

    network_mode: host

The sole reason for this seems to be the chicken-and-egg created by:

  1. zigbee2mqtt placing its configuration in the ./volumes/zigbee2mqtt/data directory rather than the more conventional (for IOTstack) ./services/zigbee2mqtt; and

  2. the initial configuration containing:

      server: 'mqtt://localhost'
    

Host mode is never a great idea. It causes confusion for users (who wonder why they can't see the port in docker ps) and makes it harder to work around port conflicts. Granted, the zigbee2mqtt configuration would let you change the port from 8080 to something else but it's still TWO more rules to remember (the first being that the configuration file is the place to change the port, the second being where zigbee2mqtt sticks its configuration file).

All things considered, it would be better if zigbee2mqtt was massaged into some semblance of consistency with other IOTstack containers.

The changes here are an attempt to make it consistent but, before we can consider propagating any of this into the template, we need to know if it works, or if there is another reason why the container needs to run in host mode.

Over to someone else...

@mpuff
Copy link
Author

mpuff commented Nov 23, 2020

Everything is working whe i set it up with your description 👍

@mpuff
Copy link
Author

mpuff commented Nov 23, 2020

But when we install openhab, port 8080 is used, maybe we can map this port to another one that is free if we install also other containers ;)

@Paraphraser
Copy link

Assuming that it is set up as above, just edit docker-compose.yml to change the external port. For example, if you wanted to use port 8181, it would look like this

ports:
      - "8181:8080/tcp"

To apply the change, you just docker-compose up -d.

If you make the same changes in ./services/zigbee2mqtt/service.yml (ie so it is identical to the zigbee2mqtt chunk in docker-compose.yml then your changes will persist across menu runs until you do a "pull full service from template".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants