You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
>&2echo"There are multiple devices connected, that could be Zigbee USB adaptors. Please check data/zigbee/configuration.yml, if the device is wrong. /dev/ttyACM0 is used as the default."
8
-
9
-
echo"/dev/ttyACM0"
4
+
usb_dev_count=0
5
+
usb_dev_found="FALSE"
6
+
fordevicein /dev/ttyUSB* /dev/ttyACM*
7
+
do
8
+
if [ !-c$device ];then
9
+
continue
10
10
fi
11
-
12
-
if [ -c /dev/ttyACM0 ];then
13
-
echo"/dev/ttyACM0"
14
-
else
15
-
>&2echo"I could not find /dev/ttyACM0. Please check your hardware."
if [ "$(echo ${VENDOR_PRODUCT}| egrep '^0451:|^10c4:')"!="" ]
16
+
then
17
+
((usb_dev_count=usb_dev_count+1))
18
+
usb_dev_found="$device"
19
+
>&2echo"📄 Found Device #$usb_dev_count$device (vendor:product=${VENDOR_PRODUCT}) that could be Zigbee USB adaptor"
16
20
fi
17
-
else
18
-
>&2echo No Texas Instruments USB device found.
21
+
done
19
22
20
-
echo"False"
23
+
if [ "$usb_dev_count"-gt 1 ];then
24
+
>&2echo"⚠️ There are multiple devices connected, that could be Zigbee USB adaptors. Please check data/zigbee/configuration.yml, if the device is wrong. $usb_dev_found is used as the default."
21
25
fi
26
+
27
+
if [ "$usb_dev_count"-eq 0 ];then
28
+
>&2echo"⚠️ No Texas Instruments USB device nor slaesh’s CC2652RB stick found for zigbee2mqtt"
29
+
fi
30
+
echo"$usb_dev_found"
22
31
}
23
32
24
33
functioncreate_mosquitto_config {
@@ -41,13 +50,19 @@ touch data/mqtt/config/passwd
41
50
}
42
51
43
52
functioncreate_zigbee2mqtt_config {
53
+
# zigbee2mqtt device
54
+
device="$1"
55
+
44
56
cat > data/zigbee/configuration.yaml <<EOF
45
57
# Home Assistant integration (MQTT discovery)
46
58
homeassistant: true
47
59
48
60
# allow new devices to join
49
61
permit_join: true
50
62
63
+
serial:
64
+
port: $device
65
+
51
66
# enable frontend
52
67
frontend:
53
68
port: 1881
@@ -74,6 +89,48 @@ echo '⚠️ Disable permit_join in data/zigbee/configuration.yaml or the Zigbe
74
89
75
90
}
76
91
92
+
functioncreate_compose_env {
93
+
# zigbee2mqtt device
94
+
device="$1"
95
+
96
+
cat > .env <<EOF
97
+
# Container-Tag listed in README.md (e.g.: latest-14, devel, devel-14, ...)
98
+
# Default = latest
99
+
CONTAINER_TAG=latest
100
+
101
+
#
102
+
# MQTT Ports for mosquitto
103
+
# Default:
104
+
# - 1883 insecure
105
+
# - 9001 websocket
106
+
# - 8883 secure (must be configured)
107
+
MQTT_PORT=1883
108
+
MQTT_WEBSOCKET_PORT=9001
109
+
MQTT_SECURE_PORT=8883
110
+
111
+
# Port for access to zigbee2mqtt Frontend
112
+
ZIGBEE_FRONTEND_PORT=1881
113
+
114
+
EOF
115
+
if [ "$device"!="FALSE" ] ;then
116
+
cat >> .env <<EOF
117
+
# Device mounted into zigbee2mqtt container
118
+
ZIGBEE_DEVICE=$device
119
+
EOF
120
+
else
121
+
cat >> .env <<EOF
122
+
# Device mounted into zigbee2mqtt container
123
+
# ZIGBEE_DEVICE=$device
124
+
# Uncomment line ZIGBEE_DEVICE and replace $device with device path like /dev/ttyXXX
125
+
# also edit data/zigbee/configuration.yaml to set the same device!
126
+
EOF
127
+
128
+
fi
129
+
echo'⚠️ Check .env for correct versions, ports and zigbee2mqtt-device'
130
+
}
131
+
132
+
133
+
77
134
functionfix_permissions {
78
135
echo'📄 Setting the permissions of the configurations in the data folder.'
79
136
sudo chown 1883:1883 data/mqtt
@@ -84,17 +141,26 @@ function fix_permissions {
84
141
85
142
86
143
functionbuild_data_structure {
87
-
echo'📄 Configuration folder ./data is missing. Creating it from scratch.'
88
144
mkdir -p data/mqtt/config
89
145
mkdir -p data/zigbee/
90
146
mkdir -p data/nodered/
91
147
148
+
# zigbee2mqtt device
149
+
device="$1"
150
+
92
151
if [ !-f data/mqtt/config/mosquitto.conf ];then
152
+
echo'📄 Configuration file data/mqtt/config/mosquitto.conf is missing. Creating it from scratch.'
93
153
create_mosquitto_config
94
154
fi
95
155
96
-
if [ !-f data/zigbee/configuration.yaml ];then
97
-
create_zigbee2mqtt_config
156
+
if [[ !-f data/zigbee/configuration.yaml &&"$device"!="FALSE" ]];then
157
+
echo'📄 Configuration file data/zigbee/configuration.yaml is missing. Creating it from scratch.'
158
+
create_zigbee2mqtt_config "$device"
159
+
fi
160
+
161
+
if [ !-f .env ];then
162
+
echo'📄 Configuration file .env is missing. Creating it from scratch.'
163
+
create_compose_env "$device"
98
164
fi
99
165
100
166
fix_permissions
@@ -110,6 +176,13 @@ function check_dependencies {
110
176
echo'⚠️ Error: git is not installed.'>&2
111
177
exit 1
112
178
fi
179
+
180
+
if! [ -x"$(command -v udevadm)" ];then
181
+
echo'⚠️ Error: udevadm is not installed.'>&2
182
+
exit 1
183
+
fi
184
+
185
+
113
186
}
114
187
115
188
functionstart {
@@ -120,10 +193,9 @@ function start {
120
193
container="nodered mqtt"
121
194
fi
122
195
123
-
if [ !-d data ];then
124
-
build_data_structure
125
-
fi
126
-
196
+
# Build data structure with default file if not existing
197
+
build_data_structure "$device"
198
+
127
199
echo'🏃 Starting the containers'
128
200
docker-compose up -d $container
129
201
echo'⚠️ After you made yourself familiar with the setup, it'"'"'s strongly suggested to secure the services. Read the "Security" section in the README!'
@@ -188,7 +260,8 @@ case "$1" in
188
260
fix_permissions
189
261
;;
190
262
"data")
191
-
build_data_structure
263
+
device=$(detect_zigbee_device)
264
+
build_data_structure "$device"
192
265
;;
193
266
* )
194
267
cat <<EOF
@@ -204,4 +277,4 @@ start.sh data – set up the data folder needed for the containers, but run none
204
277
Check https://github.com/ct-Open-Source/ct-Smart-Home/ for updates.
0 commit comments