DYI Zigbee

I want to water the lawn during the night, sure there are plenty of existing systems that cost like $20 that will do it for me but what is the fun in that ? No instead let's see if I can spent $100 to be able control a solenoid valve using my home server.

Hardware requirements

Installation

First let's get a modern version of Python.

~$ git clone https://github.com/pyenv/pyenv.git

~# apt install build-essential zlib1g-dev libffi-dev libssl-dev libbz2-dev libreadline-dev libsqlite3-dev liblzma-dev

~/pyenv$ src/configure && make -C src

~$ echo 'export PATH="/home/${USER}/.local/bin:/home/${USER}/.pyenv/shims:${PATH}"' > ~/.bashrc

~$ mkdir -p ~/.local/bin

~$ ln -s /home/${USER}/pyenv/bin/pyenv /home/${USER}/.local/bin/pyenv

~$ source ~/.bashrc

~$ pyenv install 3.9.6

~$ pyenv global 3.9.6

~$ pip install pipenv        

Okay done with the snake, we need an mqtt broker and zigbee2mqtt

~# apt install mosquitto

        
~# echo "listener 1883 127.0.0.1" >> /etc/mosquitto/mosquitto.conf

~# service mosquitto restart

~$ git clone https://github.com/Koenkk/zigbee2mqtt.git

~/zigbee2mqtt$ pipenv install nodeenv

~/zigbee2mqtt$ pipenv run nodeenv -p -n 16.4.2

        
~/zigbee2mqtt$ pipenv run npm ci        

We got everything, let's check which device the control is mapped to and configure zigbee2mqtt accordingly

~$ ls /dev/tty[AU]*
/dev/ttyUSB0

~/zigbee2mqtt$ sed -i 's/ttyACM0/ttyUSB0/g' data/configuration.yaml

~# chmod 666 /dev/ttyUSB0        

Let's start to test it out and give a friendly name to our device

~/zigbee2mqtt$ pipenv run npm start
 ...
        
Zigbee2MQTT:info  2021-07-11 02:53:10: Successfully configured '0x00124b0022ee4a71'

~/zigbee2mqtt$ sed -i 's/friendly_name: \'0x00124b0022ee4a71\'/friendly_name: \'lawn_valve\'/g' data/configuration.yaml        

Tell systemd to make sure zigbee2mqtt always runs by adding a service in /etc/systemd/system/zigbee2mqtt.service (make sure to replace your username)

[Unit]
Description=zigbee2mqtt
After=network.target


[Service]
ExecStart=/bin/bash -c 'pipenv run npm start'
WorkingDirectory=/home/dorian/zigbee2mqtt
StandardOutput=inherit
StandardError=inherit
Restart=always
User=dorian


[Install]
WantedBy=multi-user.target        

and enabling it

~# systemctl enable zigbee2mqtt.service

~# systemctl start zigbee2mqtt.service        

And voila ! Now we can send an mqtt message to start watering the lawn.

To view or add a comment, sign in

More articles by Dorian Jaminais-Grellier

  • Avoiding Double negatives isn't bad

    It’s been a while since the last #nanassitoLearned, but if I don’t want to repeat my mistakes, I have to document them.…

    2 Comments
  • Break name conventions

    Name conventions are everywhere. They creep up in every system over time.

    1 Comment
  • On re-writing from scratch

    A friend and mentor of mine wrote about this a long time ago but I don’t have access to their version and now I feel…

  • Code smell: Break early

    No I didn’t give up yet, I still have more #nanassitoLearned to share. Today I want to talk about a code smell:…

    4 Comments
  • Software pyramid of needs

    This #nanassitoLearned if a bit different, it’s not so much about a recurring problem we are facing but rather an…

  • Message passing vs. Transactions

    tl;dr; Distinguish messages from transactions and don’t implement one using the other. Definitions and context A…

  • Databases aren’t interfaces

    Tl;dr; Put an API on top of your database instead of doing multi-tenancy. Definitions and context In this post…

  • Separate system databases from analytics databases

    tl;dr; Block adhoc usage of your system's database (even read-only) There are two major use cases for a database in…

Others also viewed

Explore content categories