Zigbee2mqtt with socat configuration

I have zigbee2mqtt home assistant add-on with working configuration. Now I want to move the zigbee usb stick in other location, but without moving my home assistant box.

I connected zigbee stick to another rp and installed ser2net - using instructions on https://www.zigbee2mqtt.io/how_tos/how_to_connect_to_a_remote_adapter.html.

CONFIGURATION FILE:

data_path: /share/zigbee2mqtt
devices: devices.yaml
groups: groups.yaml
homeassistant: true
permit_join: false
mqtt:
  base_topic: zigbee2mqtt
  server: 'mqtt://***********:1883'
  user: *******
  password: *********
serial:
  port: /dev/ttyZ2M
advanced:
  pan_id: 6754
  channel: 11
  network_key:
    - 1
    - 3
    - 5
    - 7
    - 9
    - 11
    - 13
    - 15
    - 0
    - 2
    - 4
    - 6
    - 8
    - 10
    - 12
    - 13
  availability_blacklist: []
ban: []
whitelist: []
queue: {}
socat:
  enabled: true
  master: 'pty,raw,echo=0,link=/dev/ttyZ2M,mode=777'
  slave: >-
    192.168.10.171:8485,keepalive,nodelay,reuseaddr,keepidle=1,keepintvl=1,keepcnt=5
  restartdelay: 1
  initialdelay: 1
  options: '-d -d'
  log: false

The log file gives the following error:

2020/06/06 22:23:08 socat[9706] N PTY is /dev/pts/0
2020/06/06 22:23:08 socat[9706] E unknown device/address "192.168.10.171"
2020/06/06 22:23:08 socat[9706] N exit(1)
[Info] Socat process terminated, restarting after 1 sec

Anyone who can tell what is wrong?

1 Like

You haven’t followed the howto.

Thanks for your reply Nick. Can you let me know where I can find the relevant howto - I have gone through many pages already but I can’t find it.

1 Like

Your configuration simply doesn’t match the howto you pointed to.

Why Socat?

The Howto you linked is using ser2net.

This looks very different from what the howto explains.

serial:
  port: /dev/ttyZ2M

Easiest way is to run zigbee2mqtt on the machine your USB is plugged in, and let it point to your HA mqtt. The native version of zigbee2mqtt runs fine even on a RbPI 1.

I spent a few hours getting the configuration to work, this ended up doing the job:

 serial:
  port: /dev/ttyZ2M
advanced:
  log_level: info
  pan_id: 6754
  channel: 11
  network_key:
    - 1
    - 3
    - 5
    - 7
    - 9
    - 11
    - 13
    - 15
    - 0
    - 2
    - 4
    - 6
    - 8
    - 10
    - 12
    - 13
  availability_blocklist: []
  availability_passlist: []
  rtscts: false
device_options: {}
blocklist: []
passlist: []
queue: {}
experimental: {}
socat:
  enabled: true
  master: 'pty,raw,echo=0,link=/dev/ttyZ2M,mode=777,end-close'
  slave: 'tcp4:172.16.0.1:8485,ignoreeof'
  restartdelay: 1
  initialdelay: 1
  options: '-d -d'
  log: true

I had ser2net running with

8485:raw:0:/dev/ttyUSB0:115200 8DATABITS NONE 1STOPBIT

in /etc/ser2net.conf on the machine connected to the dongle.

3 Likes

For Socat as of 2024, this config works with zigbee2mqtt:

run this command on the machine with a Sonoff Dongle-P:
socat TCP-LISTEN:port,reuseaddr /dev/ttyACM0,b115200,raw,echo=0;
(choose your port)

I typically put this on a router like my homehub 5As, which have a USB port build in, and ensure that socat reconnects at disconnect time with a run script:

#!/bin/sh
  while true;
  do
    /usr/bin/socat TCP-LISTEN:port,reuseaddr /dev/ttyACM0,b115200,raw,echo=0;
    logger -t ZIGBEE-SOCAT "SOCAT terminated, restarting";
    sleep 5;
  done

save as run_socat.sh
and make executable with chmod +x run_socat

I then run this at startup in the openwrt router with the prompt as follows (make use of the local startup feature) - the & at the end of the line runs in the background.

/root/run_socat.sh &

This ensures that socat restarts itself if the connection is lost, and this all runs at startup without having to worry about integration with linux ‘features’ for startup, which i almost always forget

and run this in zigbee2mqtt:

serial:
  port: tcp://address:port
  adaptor:ezsp

(enter right IP and port)

ps, i use something similar for z-wave config with socat - the aeotec z-wave stick needs a slightly different config:
/usr/bin/socat TCP-LISTEN:port /dev/ttyACM0,b115200,raw;
(choose your port again)