JTK – Notes and Ramblings Things we have found …

6/22/2020

Dust – adding the SDS011

Filed under: General,Home Automation — taing @ 11:23 am

A SDS011 dust sensor(datasheet and communications protocol) from Amazon has been added to openhab. There is lots of good info online describing the sensor performance and Arduino(1, 2), ESP32(1, 2) and Raspberry Pi(1, 2, 3, 4, 5) setup. There is even PC based software for testing.

Nettigo has a interesting article on using the sensor with a heater inline to improve performance in high humidity. They use a Sensirion SHT30 to automatically drive a MOSFET to trigger a PTC Heating element.

One of the nice things about the package as purchased is it comes with connectors and an USB/serial adapter to allow for connections using USB, TTL serial or i2c.

In the end, it was simplest to use the brand new Openhab plugin binding. The binding reports both 2.5 and 10 µg/m³. The binding allows for easy setup of reporting mode allowing the sensor to pretty much manage itself. For reporting mode, a reporting interval is set. The unit will wake up every interval and measure for 30 seconds then sleep for interval minus 30 seconds.

Since plugging the sensor directly into the openhab server in the basement wasn’t going to be very useful a modified version of the same method used to remote the Z-Wave dongle was used. This required installing ser2net on the Pi with the sensor and setting the correct comm parameters(9600 8N1) and making copies of /etc/default/socat.conf(updated with the proper device name and IP address of the Pi with the sensor) and /etc/init.d/socat (updated to point to unique .log and .pid files and the new .conf file).

6/21/2020

Update to LaCrosse weather

Filed under: General,Home Automation,RTL-SDR — taing @ 5:51 pm

While these updates were made a while ago they weren’t documented. In the original post on the LaCrosse Weather station, rtl_433 sends mqtt data to our openhab server. On github we found a simple means to get rtl_433 to run as a service.

The core is to update /etc/rtl_433/rtl_433.conf. There is a sample file at conf/rtl_433.example.conf. Most important is the output mqtt... line for example:

output mqtt://jtk-openhab,devices=rtl_433/garage[/model]

If the Pi has multiple dongles you will also need to confirm the device line. Then create /etc/systemd/system/rtl_433-mqtt.service:

[Unit]
Description=rtl_433 to MQTT publisher
After=network.target
[Service]
ExecStart=/usr/local/bin/rtl_433
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target

Enable the service with systemctl enable rtl_433-mqtt.service.

6/20/2020

Migration – a new server for openhab

Filed under: General,Home Automation — taing @ 3:39 pm

It was time to migrate the openhab installation from the Raspberry Pi 3B to the NUC.

Before leaving the Pi a full backup is required. openhab-cli backup name_of_zipped_backup. Details on the backup and restore process can be found in the openhab forums.

The installation starts with a fresh Debian Buster(10.4) console only install. Openhabian was added from git following the guide at https://www.openhab.org/docs/installation/openhabian.html.

sudo apt-get install git screen curl gnupg
sudo git clone https://github.com/openhab/openhabian.git /opt/openhabian
sudo ln -s /opt/openhabian/openhabian-setup.sh /usr/local/bin/openhabian-config

The optional Influx db for persistence and Grafana for graphs were added from the openhabian-config tool. Chronograf 1.8 was also added manually ( sudo apt-get install chronograf ) since Influx after v1.3 doesn’t support the web console anymore. Note this is from the Influx repo which is added by the openhabian-setup tool.

At this point:
Openhab web interface -> http://your_ip:8080
Openhab console (ssh) -> your_ip:8101
Influx web admin (chronograf) -> http://your_ip:8888
Grafana -> http://your_ip:3000

Hopefully, at this point it’s time to restore the backup made earlier on the Pi: openhab-cli restore name_of_zipped_backup

Possible Issues

To resolve the issue of the openhab repo not being properly signed refer to the discussion in the openhab forums. You will need to execute:

wget -qO - 'https://bintray.com/user/downloadSubjectPublicKey?username=openhab' | sudo apt-key <strong>add</strong> -

If you encounter errors in the log file regarding RestDocs, for example, “ERROR] [core.karaf.internal.FeatureInstaller] - Failed installing ‘openhab-misc-restdocs’“, refer to the discussion in the forums. The secret is the second set of config files at /var/lib/openhab2/config/org/openhab/addons.config.

If you encounter broken graphs in the Openhab UI with error messages similar to [WARN ] [org.eclipse.jetty.server.HttpChannel] - /chart
java.lang.Error: Probable fatal error:No fonts found
refer to the discussion in the forums. The trick here is to install fontconfig for 32 bit arch even on a 64 bit machine: sudo apt-get install fontconfig:i386. A restart of the openhab service will be required after installing fontconfig: sudo systemctl restart openhab.service.

Remote Z-Wave

One of the main reasons openhab had stayed on the Pi so long was the location of the Pi and the Aeon Labs DSA02203-ZWUS Z-Wave Z-Stick Series 2 USB Dongle. This dongle creates /dev/ttyUSB0 for the z-wave binding. Our solution was to leave the Pi in place with the dongle and handle the serial port connection over Ethernet to the NUC. ser2net gets installed on the machine with the dongle. socat gets installed and run as a service on the openhab server machine. There is a great discussion on the in the openhab forums.

On the Pi:
sudo apt-get install ser2net
pico /etc/ser2net.conf
3333:raw:0:/dev/ttyUSB0:115200 8DATABITS NONE 1STOPBIT
On the NUC:
sudo apt-get install socat
git clone https://github.com/asaif/socat-init.git
sudo cp socat-init/socat /etc/init.d/
sudo chmod +x /etc/init.d/socat
sudo update-rc.d socat defaults
sudo cp socat-init/defaults/socat.conf /etc/default/

sudo nano /etc/default/socat.conf
OPTIONS="pty,link=/dev/ttyUSB0,raw,user=openhab,group=dialout,mode=777 tcp:ip_of_the_pi:3333"
sudo service socat restart

This will create /dev/ttyUSB0 on the NUC which looks like a serial device to the z-wav binding.

Final Steps

The final steps were to make sure everything that was pointing the to Pi was now pointing to the NUC.

The RFM69HCW 915MHz radio on the original openhab Pi remained in place listening to the Moteinos and sending mqtt but needed to have the destination updated. This required recompiling Gateway.c. Somehow the appropriate libraries weren’t already on the Pi for this: sudo apt-get install libmosquitto-dev libmosquittopp-dev. The recompile then when fine: g++ Gateway.c rfm69.cpp -o Gateway -lwiringPi -lmosquitto -DRASPBERRY -DDEBUG.

The code on the Pi sending outside temperature and humidity via mqtt from the am2315 i2c sensor needed to be recompiled to send to the proper destination: gcc piGateway.c -o piGateway -lwiringPi -lmosquitto -lam2315 -DRASPBERRY -DDEBUG.

The Pi running the Weather Alert / SAME code needed to have the destination address updated. This is a simple change to the mqtt command line parameter in the script. The same Pi also runs the Seneye aquarium monitor code which needed an edit in suddriver.py to update the mqtt destination.

The Pi running rtl_433 for the LaCrosse weather station integration required an update to rtl_433.conf to point the mqtt data to the new destination. The same Pi also runs the as3935 Lightning detector. A quick modification to the python script to fix the mqtt destination got this back online.

Powered by WordPress