Debug VPN script

#!/bin/bash
 
export DEBUG=@option.debug@
export VPN_CONNECTION_ID=$(echo @option.vpn_connection_id@ | sed -e 's/^[[:space:]]*//')
 
[ "${DEBUG}" == "yes" ] && set -x
 
source /etc/kolla/admin-openrc.sh
source /usr/local/pyenv/versions/osc/bin/activate
 
# check parameter
if [[ ! ${VPN_CONNECTION_ID//-/} =~ ^[[:xdigit:]]{32}$ ]]; then
#if [ -z "${VPN_CONNECTION_ID}" ]; then
    echo -e "\e[34mPlease specify the VPN ipsec site connection ID"
    openstack vpn ipsec site connection list --long
 
    exit
fi 
 
 
VPN_CONNECTION_JSON=$(openstack vpn ipsec site connection show ${VPN_CONNECTION_ID} -f json)
 

Home Assistant MQTT

Install MQTT broker (server) on Anroid
https://apkpure.com/mqtt-broker-app/server.com.mqtt/download

Create MQTT sensor
https://www.home-assistant.io/integrations/sensor.mqtt/

# ~/.homeassistant/configuration.yam
# /mnt/data/supervisor/homeassistant/configuration.yaml (on Raspery PI)
...
mqtt: !include inverter.yaml
 
# inverter.yaml
  sensor:
    - name: "Inverter AC Power"
      unique_id: "inverter_ac"
      state_topic: "inverter/HM/ch0/P_AC"
      unit_of_measurement: "W"
      device_class: "energy"
      state_class: "measurement"
    - name: "Inverter DC Power"
      unique_id: "inverter_dc"
      state_topic: "inverter/HM/ch0/P_DC"
      unit_of_measurement: "W"
      device_class: "energy"
      state_class: "measurement"
    - name: "Inverter DC Power CH1"
      unique_id: "inverter_dc_ch1"
      state_topic: "inverter/HM/ch1/P_DC"
      unit_of_measurement: "W"
      device_class: "energy"
      state_class: "measurement"
    - name: "Inverter DC Power CH2"
      unique_id: "inverter_dc_ch2"
      state_topic: "inverter/HM/ch2/P_DC"
      unit_of_measurement: "W"
      device_class: "energy"
      state_class: "measurement"
    - name: "Inverter Yield Day"
      unique_id: "inverter_yield_day"
      state_topic: "inverter/HM/ch0/YieldDay"
      unit_of_measurement: "Wh"
    - name: "Inverter Yield Total"
      unique_id: "inverter_yield_total"
      state_topic: "inverter/HM/ch0/YieldTotal"
      unit_of_measurement: "kWh"
      device_class: "energy"
      state_class: "measurement"
    - name: "Inverter Temperature"
      unique_id: "inverter_temperature"
      state_topic: "inverter/HM/ch0/Temp"
      unit_of_measurement: "°C"
      icon: "mdi:thermometer"

Install mosquitto (MQTT broker) on Raspery PI OS as docker container

ahoy / Open DTU

Download ahoy firmware
https://github.com/lumapu/ahoy/releases
https://fw.ahoydtu.de/fw/release/

# dev
#URL=https://nightly.link/lumapu/ahoy/workflows/compile_development/development03/ahoydtu_dev.zip
 
# stable
URL=https://github.com/lumapu/ahoy/releases/download/ahoy_v0.8.140/ahoy_v0.8.140.zip
 
wget ${URL} -q -O /tmp/ahoydtu.zip
 
# extract
unzip /tmp/ahoydtu.zip -d /tmp

Download esptoo
https://github.com/espressif/esptool/releases

#pip install esptool
#git clone git@github.com:marcelstoer/nodemcu-pyflasher.git
#git clone https://github.com/espressif/esptool.git /tmp/esptool
 
wget https://github.com/espressif/esptool/releases/download/v4.7.0/esptool-v4.7.0-linux-amd64.zip -q -O /tmp/esptool.zip
unzip /tmp/esptool.zip -d /tmp
chmod +x /tmp/esptool-linux-amd64/esptool

Flash Ahoy DTU

Export server volume as image

SERVER_IDS="
dd799bc6-ded0-4f20-8f24-3e5af5250fd3
46562d71-ba00-47b7-872a-cd759abd014c
5e517453-c87f-4426-b705-96ffc9afe4ce
"
 
function save_image() {
    IMAGE_ID="${1}"
    IMAGE_NAME="${2}"
 
    echo "IMAGE_ID: ${IMAGE_ID}"
    openstack image set --private ${IMAGE_ID}    
 
    echo "Save image as ${IMAGE_NAME}.qcow2 ..."
    openstack image save ${IMAGE_ID} --file ${IMAGE_NAME}.qcow2
 
    openstack image show ${IMAGE_ID} -c size -f value
    ls -l ${IMAGE_NAME}.qcow2
    md5sum ${IMAGE_NAME}.qcow2 > ${IMAGE_NAME}.qcow2.md5sum
 
    openstack image show ${IMAGE_ID} -f json > ${IMAGE_NAME}.json
 
    echo "Delete image ${IMAGE_NAME}"
    openstack image delete ${IMAGE_ID}
}
 
 
for SERVER_ID in ${SERVER_IDS}; do
    echo "SERVER_ID: ${SERVER_ID}"
    SERVER_JSON=$(openstack server show ${SERVER_ID} -f json)
 
    SERVER_NAME=$(echo ${SERVER_JSON} | jq -r .name | tr " " "_")

Node-RED

https://nodered.org/

Termux (run Node-RED on Android)
https://nodered.org/docs/getting-started/android
https://github.com/termux/termux-app

# Install termux
https://github.com/termux/termux-app/releases/download/v0.118.0/termux-app_v0.118.0+github-debug_armeabi-v7a.apk

pkg upgrade
pkg install openssh
whoami
passwd
 
ssh u0_a114@192.168.178.222 -p 8022
~ $ echo  "ssh-rsa xxxxx" >> ~/.ssh/authorized_keys 
 
apt update
apt dist-upgrade
apt install -y vim
apt install -y coreutils
#apt install -y nodejs
#apt install -y termux-api
npm install -g node-red
 
node-red &
 
npm i node-red-node-ui-table node-red-dashboard

http://192.168.178.222:1880/

Links
https://nodered.org/docs/getting-started/android

Home Assistant

Install Home Assistant as Docker container
https://www.home-assistant.io/installation/linux#platform-installation

docker run -d \
  --name homeassistant \
  --privileged \
  --restart=unless-stopped \
  -e TZ=Europe/Berlin \
  -v homeassistant:/config \
  --network=host \
  ghcr.io/home-assistant/home-assistant:stable
 
# volume path
# /var/lib/docker/volumes/homeassistant

Configure
http://127.0.0.1:8123

Install HACS

sudo docker exec -it homeassistant bash
wget -O - https://get.hacs.xyz | bash -

Addons / Plugins
LocaTuya: https://github.com/rospogrigio/localtuya/

custom_zha_quirks
https://smarthomescene.com/reviews/tuya-zigbee-single-clamp-energy-meter-review/

Zigbee / SmartHome

homebridge

cat <<EOF> docker-compose.yml 
version: '2'
services:
  homebridge:
    image: oznu/homebridge:latest
    restart: always
    network_mode: host
    volumes:
      - ./volumes/homebridge:/homebridge
    logging:
      driver: json-file
      options:
        max-size: "10mb"
        max-file: "1"
EOF
 
sudo docker-compose up -d

Setup
http://localhost:8581

Tuya
https://github.com/0x5e/homebridge-tuya-platform

npm install @0x5e/homebridge-tuya-platform

Yamaha
https://github.com/cgierke/homebridge-musiccast

Links
https://github.com/homebridge/homebridge/wiki/Install-Homebridge-on-Docker

Migrate OpenStack VM with encrypted volume

SERVER_ID=xxxx-xxxx-xxxx-xxxx-xxxx
 
# VOLUME_ID=$(openstack server show ${SERVER_ID} -c volumes_attached -f value | cut -d "'" -f4)
# VOLUME_TYPE=$(openstack volume show ${VOLUME_ID} -c type -f value)
# openstack volume type show ${VOLUME_TYPE}
 
# add admin to project
PROJECT_ID=$(openstack server show ${SERVER_ID} -c project_id -f value)
openstack role add --user admin --project ${PROJECT_ID} admin
unset OS_PROJECT_DOMAIN_NAME
unset OS_PROJECT_NAME
export OS_PROJECT_ID=${PROJECT_ID}
 
# Live migrate VM
openstack server migrate --os-compute-api-version 2.56 --live-migration --wait --host com10-prod ${SERVER_ID}
openstack server show ${SERVER_ID} -c name -c OS-EXT-SRV-ATTR:host
 
# remove admin from project
unset OS_PROJECT_ID
source /etc/kolla/admin-openrc.sh
openstack role remove --user admin --project ${PROJECT_ID} admin