diff --git a/profiles/ini.env b/profiles/ini.env
index ffb4aa0..33c070a 100644
--- a/profiles/ini.env
+++ b/profiles/ini.env
@@ -9,3 +9,25 @@ taiga_user = taiga
[rabbitmq]
taiga_user = taiga
+
+# for a self-signed certificate
+[req]
+default_bits = 2048
+prompt = no
+default_md = sha256
+req_extensions = req_ext
+distinguished_name = some_dn
+
+[some_dn]
+C = RU
+L = Saint-Petersburg
+O = Calculate Linux
+emailAddress = support@calculate.ru
+CN = calculate-linux.org
+
+[req_ext]
+subjectAltName = @alt_names
+
+[alt_names]
+DNS.1 = otherdomain.com
+IP.1 = 1.2.3.4
diff --git a/profiles/templates/homeassistant/homeassistant/conf.homeassistant b/profiles/templates/homeassistant/homeassistant/conf.homeassistant
new file mode 100644
index 0000000..b01d88e
--- /dev/null
+++ b/profiles/templates/homeassistant/homeassistant/conf.homeassistant
@@ -0,0 +1,7 @@
+# Calculate path=/etc/conf.d name=#-cut(1,.)-# format=openrc
+# /etc/conf.d/homeassistant: configuration for /etc/init.d/homeassistant
+
+# Switches to pass to hass. See 'hass --help' for
+# a description of the possible switches.
+#
+HASS_OPTS=""
diff --git a/profiles/templates/homeassistant/homeassistant/ini.env b/profiles/templates/homeassistant/homeassistant/ini.env
index de612b0..896c1af 100644
--- a/profiles/templates/homeassistant/homeassistant/ini.env
+++ b/profiles/templates/homeassistant/homeassistant/ini.env
@@ -1,26 +1,4 @@
-# Calculate format=samba path=/var/calculate chmod=600 grep(/var/calculate/ini.env,homeassistant_sites_domain)== protected
+# Calculate format=samba path=/var/calculate grep(/var/calculate/ini.env,homeassistant_sites_domain)== protected
[homeassistant]
protocol = http
-domain = home.example.org
-
-# for a self-signed certificate
-[req]
-default_bits = 2048
-prompt = no
-default_md = sha256
-req_extensions = req_ext
-distinguished_name = some_dn
-
-[some_dn]
-C = RU
-L = Saint-Petersburg
-O = Calculate Linux
-emailAddress = support@calculate.ru
-CN = calculate-linux.org
-
-[req_ext]
-subjectAltName = @alt_names
-
-[alt_names]
-DNS.1 = otherdomain.com
-IP.1 = 1.2.3.4
+domain = #-ip()-#
diff --git a/profiles/templates/homeassistant/homeassistant/init.homeassistant b/profiles/templates/homeassistant/homeassistant/init.homeassistant
index 62fea08..2c0241e 100644
--- a/profiles/templates/homeassistant/homeassistant/init.homeassistant
+++ b/profiles/templates/homeassistant/homeassistant/init.homeassistant
@@ -12,7 +12,7 @@ serverlog="/var/log/homeassistant/server.log"
warningslog="/var/log/homeassistant/warnings.log"
retry="20"
-command=/var/calculate/www/homeassistant/.venv-live/bin/hass
+command=/var/calculate/www/homeassistant/homeassistant-live/bin/hass
directory=/var/calculate/www/homeassistant
start_stop_daemon_args="--user $user --stdout $stdoutlog --stderr $serverlog --wait 10"
diff --git a/profiles/templates/homeassistant/homeassistant/www/homeassistant/versions/.calculate_directory b/profiles/templates/homeassistant/homeassistant/www/homeassistant/versions/.calculate_directory
new file mode 100644
index 0000000..2be8757
--- /dev/null
+++ b/profiles/templates/homeassistant/homeassistant/www/homeassistant/versions/.calculate_directory
@@ -0,0 +1 @@
+# Calculate chown=homeassistant:homeassistant
diff --git a/profiles/templates/homeassistant/homeassistant/x-ini.env b/profiles/templates/homeassistant/homeassistant/x-ini.env
deleted file mode 100644
index 8824140..0000000
--- a/profiles/templates/homeassistant/homeassistant/x-ini.env
+++ /dev/null
@@ -1,10 +0,0 @@
-# Calculate run=/bin/bash grep(/var/calculate/ini.env,home\.example.org)!=
-
-# Подставим IP eth0, пока у шаблонов нет необходимой функции
-interface=$(ip route | grep -m 1 'default via' | awk '{print $5}')
-if [[ -z $interface ]]
-then
- interface=eth0
-fi
-IP=$(ifconfig $interface 2>/dev/null | grep 'inet ' | awk '{print $2}')
-sed -i -E "s/(domain =).*/\1 $IP/g" /var/calculate/ini.env
diff --git a/profiles/templates/homeassistant/zigbee2mqtt/0-adduser.zigbee2mqtt/groups b/profiles/templates/homeassistant/zigbee2mqtt/0-adduser.zigbee2mqtt/groups
new file mode 100644
index 0000000..d3c1f86
--- /dev/null
+++ b/profiles/templates/homeassistant/zigbee2mqtt/0-adduser.zigbee2mqtt/groups
@@ -0,0 +1,3 @@
+# Calculate path=/etc name=group format=patch protected
+dialout:x:20:homeassistant
+dialout:x:20:homeassistant,zigbee2mqtt
diff --git a/profiles/templates/homeassistant/zigbee2mqtt/ini.env b/profiles/templates/homeassistant/zigbee2mqtt/ini.env
index 4d002d1..1ad3ba6 100644
--- a/profiles/templates/homeassistant/zigbee2mqtt/ini.env
+++ b/profiles/templates/homeassistant/zigbee2mqtt/ini.env
@@ -1,4 +1,9 @@
# Calculate format=samba path=/var/calculate chmod=600 grep(/var/calculate/ini.env,zigbee2mqtt)== protected
[zigbee2mqtt]
+#?exists(/dev/ttyUSB0)-#
+dev = /dev/ttyUSB0
+#exists#
+#?exists(/dev/ttyACM0)-#
dev = /dev/ttyACM0
+#exists#
nodeenv = 16.15.0
diff --git a/profiles/templates/homeassistant/zigbee2mqtt/init.zigbee2mqtt b/profiles/templates/homeassistant/zigbee2mqtt/init.zigbee2mqtt
new file mode 100644
index 0000000..5249313
--- /dev/null
+++ b/profiles/templates/homeassistant/zigbee2mqtt/init.zigbee2mqtt
@@ -0,0 +1,33 @@
+# Calculate path=/etc/init.d name=#-cut(1,.)-# chmod=755 comment=# exists(/var/calculate/www/zigbee2mqtt/zigbee2mqtt-live)!=
+#!/sbin/openrc-run
+# Copyright 2023 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+description="Allows you to use your Zigbee devices without the vendor's bridge or gateway"
+
+user="zigbee2mqtt"
+group="zigbee2mqtt"
+
+command="/var/calculate/www/zigbee2mqtt/zigbee2mqtt-live/.venv/bin/npm"
+directory="/var/calculate/www/${RC_SVCNAME}/${RC_SVCNAME}-live"
+command_args="start"
+command_user="${user}:${group}"
+command_background="yes"
+pidfile="/run/${RC_SVCNAME}.pid"
+output_log="/var/log/${RC_SVCNAME}.log"
+error_log="${output_log}"
+export PATH="/var/calculate/www/zigbee2mqtt/zigbee2mqtt-live/.venv/bin:$PATH"
+
+depend() {
+ need mosquitto
+}
+
+stop(){
+ ebegin "Stopping ${SVCNAME}"
+ start-stop-daemon --stop --quiet --retry 20 --pidfile $pidfile
+ eend $?
+}
+
+start_pre() {
+ checkpath --file --owner $user --mode 0644 $output_log
+}
diff --git a/profiles/templates/homeassistant/zigbee2mqtt/runlevel.zigbee2mqtt b/profiles/templates/homeassistant/zigbee2mqtt/runlevel.zigbee2mqtt
new file mode 100644
index 0000000..80af438
--- /dev/null
+++ b/profiles/templates/homeassistant/zigbee2mqtt/runlevel.zigbee2mqtt
@@ -0,0 +1 @@
+# Calculate path=/etc/runlevels/default name=#-cut(1,.)-# link=/etc/init.d/#-cut(1,.)-# protected symbolic exists(/var/calculate/www/zigbee2mqtt/zigbee2mqtt-live)!=
diff --git a/scripts/functions/ip.sh b/scripts/functions/ip.sh
new file mode 100755
index 0000000..2218a1f
--- /dev/null
+++ b/scripts/functions/ip.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+# Define the IP address
+
+interface=$(ip route | grep -m 1 'default via' | awk '{print $5}')
+if [[ -z $interface ]]
+then
+ interface=eth0
+fi
+IP=$(ifconfig $interface 2>/dev/null | grep 'inet ' | awk '{print $2}')
+echo $IP
diff --git a/scripts/homeassistant/setup.sh b/scripts/homeassistant/setup.sh
index 7e826cb..83521dc 100755
--- a/scripts/homeassistant/setup.sh
+++ b/scripts/homeassistant/setup.sh
@@ -6,16 +6,16 @@ scriptpath=$(dirname $(readlink -f $0))
. /var/db/repos/calculate/scripts/ini.sh
-chmod o+rw /var/calculate/ini.env
+chmod o+r /var/calculate/ini.env
for script in $scriptpath/step/*.sh; do
"$script"
done
-chmod o-rw /var/calculate/ini.env
if [[ ! -e /etc/runlevels/default/homeassistant ]]; then
cl-setup-system
rc-update -u
fi
openrc
+chmod 600 /var/calculate/ini.env
echo -e "\nAll is done! Open the link ${ini[homeassistant.protocol]}://${ini[homeassistant.domain]} on your browser."
diff --git a/scripts/homeassistant/step/1-install.sh b/scripts/homeassistant/step/1-install.sh
index aa31921..c4abaf6 100755
--- a/scripts/homeassistant/step/1-install.sh
+++ b/scripts/homeassistant/step/1-install.sh
@@ -3,31 +3,31 @@
set -ueo pipefail
export PATH="/lib/rc/bin:$PATH"
+test -e ~/homeassistant-live && exit
+
SCRIPT=$(readlink -f $0)
[[ $UID == 0 ]] && exec su - homeassistant -c "$SCRIPT"
. /var/db/repos/container/scripts/functions.sh
. /var/db/repos/calculate/scripts/ini.sh
-if [[ ! -e ~/.venv-live ]]; then
- einfo 'Create a virtualenv'
+einfo 'Create a virtualenv'
+
+python -m venv ~/homeassistant-live
+. ~/homeassistant-live/bin/activate
- python -m venv ~/.venv-live
- echo '. ~/.venv-live/bin/activate' >> ~/.bashrc
- echo '. ~/.venv-live/bin/activate' >> ~/.bash_profile
-
- . ~/.venv-live/bin/activate
+einfo 'Install all Python dependencies'
+python -m pip install wheel
- einfo 'Install all Python dependencies'
- python -m pip install wheel
+einfo 'Install Home Assistant'
+pip install homeassistant
- einfo 'Install Home Assistant'
- pip install homeassistant
+einfo 'Install PostgreSQL dependencies'
+pip install psycopg2
- einfo 'Install PostgreSQL dependencies'
- pip install psycopg2
+ha_ver=$(pip list | grep ^homeassistant | awk '{print $2}')
+mv ~/homeassistant-live ~/versions/homeassistant-${ha_ver}
+ln -s ~/versions/homeassistant-${ha_ver} ~/homeassistant-live
- ha_ver=$(pip list | grep ^homeassistant | awk '{print $2}')
- mv ~/.venv-live ~/.venv-${ha_ver}
- ln -s ~/.venv-${ha_ver} ~/.venv-live
-fi
+echo '. ~/homeassistant-live/bin/activate' >> ~/.bashrc
+echo '. ~/homeassistant-live/bin/activate' >> ~/.bash_profile
diff --git a/scripts/homeassistant/step/3-zigbee2mqtt.sh b/scripts/homeassistant/step/3-zigbee2mqtt.sh
index a24d61d..c86bf9b 100755
--- a/scripts/homeassistant/step/3-zigbee2mqtt.sh
+++ b/scripts/homeassistant/step/3-zigbee2mqtt.sh
@@ -1,50 +1,51 @@
#!/bin/bash
+# Guide: https://www.zigbee2mqtt.io/guide/installation/07_python_virtual_environment.html
set -ueo pipefail
export PATH="/lib/rc/bin:$PATH"
+test -e ~/zigbee2mqtt-live && exit
+
SCRIPT=$(readlink -f $0)
[[ $UID == 0 ]] && exec su - zigbee2mqtt -c "$SCRIPT"
. /var/db/repos/container/scripts/functions.sh
. /var/db/repos/calculate/scripts/ini.sh
-if [[ ! -e ~/zigbee2mqtt-live ]]; then
- cd
- einfo 'Clone Zigbee2MQTT repository'
- ver=$(curl -s https://api.github.com/repos/Koenkk/zigbee2mqtt/releases/latest | grep tag_name | cut -d '"' -f 4) && echo "Latest Zigbee2MQTT version is ${ver}"
- wget -q https://github.com/Koenkk/zigbee2mqtt/archive/refs/tags/${ver}.zip -O zigbee2mqtt-${ver}.zip
- einfo 'Extract the archive'
- unzip -q -d versions zigbee2mqtt-${ver}.zip
- rm zigbee2mqtt-${ver}.zip
- ln -sf versions/zigbee2mqtt-${ver} zigbee2mqtt-live
+cd
+ver=$(curl -s https://api.github.com/repos/Koenkk/zigbee2mqtt/releases/latest | grep tag_name | cut -d '"' -f 4) && echo "Latest Zigbee2MQTT version is ${ver}"
+wget -q https://github.com/Koenkk/zigbee2mqtt/archive/refs/tags/${ver}.zip -O zigbee2mqtt-${ver}.zip
+einfo 'Extract the archive'
+unzip -q -d versions zigbee2mqtt-${ver}.zip
+rm zigbee2mqtt-${ver}.zip
+ln -sf versions/zigbee2mqtt-${ver} zigbee2mqtt-live
- einfo 'Install python env'
- python -m venv zigbee2mqtt-live/.venv
+einfo 'Install python env'
+python -m venv zigbee2mqtt-live/.venv
- einfo 'Activate environment'
- . zigbee2mqtt-live/.venv/bin/activate
+einfo 'Activate environment'
+. zigbee2mqtt-live/.venv/bin/activate
- einfo 'Upgrade pip, wheel and setuptools'
- pip install --upgrade pip wheel setuptools
+einfo 'Upgrade pip, wheel and setuptools'
+pip install --upgrade pip wheel setuptools
- einfo 'Install node environment'
- pip install nodeenv
+einfo 'Install node environment'
+pip install nodeenv
- einfo 'Init node environment'
- nodeenv -p -n ${ini[zigbee2mqtt.nodeenv]}
+einfo 'Init node environment'
+nodeenv -p -n ${ini[zigbee2mqtt.nodeenv]}
- einfo 'Install dependencies'
- cd zigbee2mqtt-live
- npm ci
- cd
+einfo 'Install dependencies'
+cd zigbee2mqtt-live
+npm ci
+cd
- echo '. ~/zigbee2mqtt-live/.venv/bin/activate' >> .bashrc
- echo '. ~/zigbee2mqtt-live/.venv/bin/activate' >> .bash_profile
+echo '. ~/zigbee2mqtt-live/.venv/bin/activate' >> .bashrc
+echo '. ~/zigbee2mqtt-live/.venv/bin/activate' >> .bash_profile
- einfo 'Setup zigbee2mqtt'
- mv zigbee2mqtt-live/data/configuration.yaml zigbee2mqtt-live/data/configuration.yaml.old
- cat > zigbee2mqtt-live/data/configuration.yaml << EOF
+ebegin 'Setup zigbee2mqtt'
+mv zigbee2mqtt-live/data/configuration.yaml zigbee2mqtt-live/data/configuration.yaml.old
+cat > zigbee2mqtt-live/data/configuration.yaml << EOF
# Home Assistant integration (MQTT discovery)
homeassistant: false
@@ -58,12 +59,13 @@ mqtt:
# MQTT server URL
server: 'mqtt://localhost'
# MQTT server authentication, uncomment if required:
- # # user: my_user
+ # user: my_user
# password: my_password
# Serial settings
serial:
# Location of USB sniffer
port: ${ini[zigbee2mqtt.dev]}
+frontend: true
EOF
-fi
+eend
diff --git a/scripts/homeassistant/step/4-config.sh b/scripts/homeassistant/step/4-config.sh
index a381a00..68367de 100755
--- a/scripts/homeassistant/step/4-config.sh
+++ b/scripts/homeassistant/step/4-config.sh
@@ -3,9 +3,11 @@
set -ueo pipefail
export PATH="/lib/rc/bin:$PATH"
+test -e /etc/homeassistant/configuration.yaml && exit
+
SCRIPT=$(readlink -f $0)
[[ $UID == 0 ]] && exec su - homeassistant -c "$SCRIPT"
-source .venv-live/bin/activate
+. homeassistant-live/bin/activate
. /var/db/repos/container/scripts/functions.sh
. /var/db/repos/calculate/scripts/ini.sh