📜 ⬆️ ⬇️

Bobaos - KNX TP / UART, Raspberry Pi and Apple HomeKit


In this publication, I will show how to set up and run homebridge (implementation of HomeKit Accessory Protocol on nodejs) based on Raspberry Pi, Weinzierl KNX BAOS 838 module kBerry and bobaos from scratch.


Preliminary requirements.


  1. Raspberry Pi with BAOS 838 kBerry module installed.
  2. Raspbian with installed: nodejs, npm (in my case raspbian stretch lite, nodejs version 8).

Go


Configure the serial port


For Raspberry Pi 3:


sudo sh -c "echo dtoverlay=pi3-miniuart-bt >>/boot/config.txt" 

From the file / boot / cmdline.txt we remove the entry console = ttyAMA0,115200 .


Add a user to the dialout group, reboot


 sudo usermod -a -G dialout pi sudo reboot 

Install bdsd.sock


 curl -L https://raw.githubusercontent.com/bobaos/bdsd.sock/master/bdsd_install.sh | bash 

Script content:


 #!/bin/bash sudo npm install -g bdsd.sock --unsafe-perm sudo npm install -g bdsd-cli --unsafe-perm SERVICE_NAME=bdsd.service mkdir $HOME/.config/systemd mkdir $HOME/.config/systemd/user touch $HOME/.config/systemd/user/$SERVICE_NAME SERVICE_PATH=$HOME/.config/systemd/user/$SERVICE_NAME echo "[Unit]" > $SERVICE_PATH echo "Description=Bobaos Datapoint Sdk Daemon" >> $SERVICE_PATH echo "[Service]" >> $SERVICE_PATH echo "ExecStart=/usr/bin/env bdsd.sock" >> $SERVICE_PATH echo "[Install]" >> $SERVICE_PATH echo "WantedBy=default.target" >> $SERVICE_PATH systemctl --user daemon-reload systemctl --user enable $SERVICE_NAME sudo loginctl enable-linger pi systemctl --user start $SERVICE_NAME 

The script will install the latest version of bdsd.sock from npm, create a bdsd.service file in $ HOME / .config / systemd / user / , configure autorun, start the service.


We check with bdsd-cli, translate the KNX module into programming mode:


 bdsd-cli connected bobaos> setProgrammingMode -v 1 Set programming mode: success bobaos> 

On the board, the red LED should turn on, indicating that the device is in programming mode. Go to the next step.


Configuration in ETS


Any KNX installation is configured in ETS (Engineering Tool Software), ours is no exception. We are interested in the KNX BAOS 830 appliqué from Weinzierl. Add, customize. In my case, 4 relays, with objects 101-108.
We write the physical address, further partial loading. After that go to the next step.



Install and configure homebridge


Install the homebridge from npm:


 sudo npm install -g homebridge --unsafe-perm 

Install homebridge-bobaos . At the moment, version 0.0.1, since The plugin is in the initial stages of development.


 sudo npm install -g homebridge-bobaos 

Next, we need to create a config.json configuration file located in $ HOME / .homebridge / config.json .


Minimum content:


 { "bridge": { "name": "Homebridge", "username": "CC:22:3D:E1:CE:36", "port": 51822, "pin": "031-45-154" }, "accessories": [], "platforms": [] } 

Next, we need to add the Bobaos platform to the configuration file, register the accessories, services, specifications. JSON editing manually is quite problematic - unreadable, high probability of error - you can forget quotes, extra commas, nesting. Therefore, I use YAML for configuration. A typical config might look like this:


 accessories: - name: Livroom lights services: - type: Lightbulb name: Livroom lights characteristics: - type: On control: 101 status: 105 - name: Livroom lights 2 services: - type: Switch name: Livroom lights 2 characteristics: - type: On control: 102 status: 106 - name: Kitchen lights services: - type: Lightbulb name: Kitchen lights characteristics: - type: On control: 6 status: 6 - type: Brightness control: 2 status: 2 - name: Kitchen Fan services: - type: Fan name: Kitchen Fan characteristics: - type: On control: 103 status: 107 

There are so few services supported: Switch (On), LightBulb (On, Brightness), Fan (On), in the process of adding the rest.


We save in a separate file, for example homebridge.yml . Now we need to translate the YAML document in JSON format. The homebridge-bobaos package includes the genBobaosAccessories utility. We use it:


 genBobaosAccessories homebridge.yml ~/.homebridge/config.json { "bridge": { "name": "Homebridge", "username": "CC:22:3D:E1:CE:36", "port": 51822, "pin": "031-45-154" }, "accessories": [], "platforms": [ { "platform": "Bobaos", "name": "bobaos", "accessories": [ { "name": "Livroom lights", "services": [ { "type": "Lightbulb", "name": "Livroom lights", "characteristics": [ { "type": "On", "control": 101, .... .... 

The first argument is the yml config file, the second is the existing config.json. Script parsit both files, add a new one to the list of platforms, if there are no Bobaos platforms, or update an element in the array if present. If the output of the utility is without errors, redirect to config.json:


 genBobaosAccessories homebridge.yml ~/.homebridge/config.json > ~/.homebridge/config.json 

Start the homebridge and proceed to the next step.


 homebridge 

Autostart


For autorun, configure the systemd service. To do this, create a service file on the path $ HOME / .config / systemd / user / homebridge.service with the following contents:


 [Unit] Description=Homebridge service [Service] ExecStart=/usr/bin/env homebridge [Install] WantedBy=default.target 

Next, run:


 systemctl --user daemon-reload systemctl --user start homebridge.service 

We are checking. If everything works well, assign autorun:


 systemctl --user enable homebridge.service 

This article comes to an end. It remains to express my gratitude, and say goodbye to this.


Previous publications


  1. Bobaos - access to the KNX TP / UART bus with the Raspberry Pi
  2. Bobaos - KNX TP / UART, Raspberry Pi and Unix Domain Socket

Thanks


  1. First of all, Weinzierl is for excellent KNX equipment, without it there would not be this project.
  2. Raspberry Pi for a great computer.
  3. The entire open-source community for Linux, nodejs, git, vim, and so on.

')

Source: https://habr.com/ru/post/354480/


All Articles