Skip to content

Linux service providing garage door control on Onion Omega2+ device with data sent via MQTT to Home Assistant

License

Notifications You must be signed in to change notification settings

ironsheep/Omega2-GarageDoors-MQTT2HA-Daemon

Repository files navigation

Omega2 GarageDoors MQTT2HA Daemon

Project Maintenance

GitHub Activity

License: GPL v3

A simple Python script which is an MQTT sender/listener providing twin switches (left and right garage doors) via MQTT to your Home Assistant installation.

This script should be configured to be run in daemon mode continously in the background as a System-V init script. (using instructions/scripts provided)

--

This is a work in progress!

(this marker will be removed once the full system is working and code is committed to this repo)

--

Project Hardware

Omega2+ and as seen in HA

This is the onion Omega2+ mounted on an Expansion Dock with the (dual) relay exapnsion which they no longer sell but can still be found in their Maker Kit

Features

  • Registers two garage door controls with Home Assistant
  • Tested on Omega2+ v0.3.2 b244 running OpenWrt v4.14.81
  • Tested with Home Assistant v0.111.0
  • Tested with Mosquitto broker v5.1
  • Data is published via MQTT
  • MQTT discovery messages are sent so this controller is automatically registered with Home Assistant (if MQTT discovery is enabled in your HA installation)
  • MQTT authentication support

Omega2+ Device MQTT Discovery

The Omega2 Garage Door device is reported as:

Name Description
Manufacturer Onion Corporation
Model Omega2+
Name GarageDoor Controller
sofware ver Name, Version (e.g., v0.3.2 b233)

Omega2+ MQTT Topics

The Omega2 Garage Door device exposes a number of topics:

Name Device Class Units Description
~/left 'timestamp' n/a Is a timestamp which shows when the Omega last sent information, carries a template payload conveying all monitored values (attach the lovelace custom card to this sensor!)
~/right 'timestamp' n/a Is a timestamp which shows when the Omega last sent information, carries a template payload conveying all monitored values (attach the lovelace custom card to this sensor!)

Prerequisites

An MQTT broker is needed as the counterpart for this daemon.

MQTT is huge help in connecting different parts of your smart home and setting up of a broker is quick and easy. In many cases you've already set one up when you installed Home Assistant.

Installation

On OpenWrt just a few steps are needed to get the daemon working.

To begin installation we need to find the latest released version of this script. Visit our releases page to find the latest release. Copy the Link Address of the file you want to use for install (.zip or .tar.gz file)

The following example shows the installation below the /opt directory:

# make sure we have python3 installed
opkg install python3 python3-pip python3-relay-exp

# go to home directory
cd

# download the file
wget {the link address you copied}

# make our /opt directory if not already present
mkdir /opt

# move to new directory
cd /opt

# unpack the release file just downloaded
tar -xzvf /root/{filename}.tar.gz
(or) unzip /root/{filename}.zip

# this installed our files in /opt/Omega2-GarageDoors-MQTT2HA-Daemon, go there
cd /opt/Omega2-GarageDoors-MQTT2HA-Daemon

# and install our extra python support
pip3 install -r requirements.txt

Configuration

To match personal needs, all operational details can be configured by modifying entries within the file config.ini. The file needs to be created first:

cp /opt/Omega2-GarageDoors-MQTT2HA-Daemon/config.{ini.dist,ini}
vim /opt/Omega2-GarageDoors-MQTT2HA-Daemon/config.ini

You will likely want to locate and configure the following (at a minimum) in your config.ini:

# ...
hostname = {your-mqtt-broker}

# ...
base_topic = {your home-assistant base topic}

# ...
username = {your mqtt username if your setup requires one}
password = {your mqtt password if your setup requires one}

Now that your config.ini is setup let's test!

Execution

Initial Test

A first test run is as easy as:

python3 /opt/Omega2-GarageDoors-MQTT2HA-Daemon/ISP-GarageDoor-mqtt-daemon.py

NOTE: it is a good idea to execute this script by hand this way each time you modify the config.ini. By running after each modification the script can tell you through error messages if it had any problems with any values in the config.ini file, or any missing values. etc.``

Using the command line argument --config, a directory where to read the config.ini file from can be specified, e.g.

python3 /opt/Omega2-GarageDoors-MQTT2HA-Daemon/ISP-GarageDoor-mqtt-daemon.py --config /opt/Omega2-GarageDoors-MQTT2HA-Daemon

Configure to run script at startup

Now we need to configure our system service. OpenWrt uses the SysV init script convention so let's set this up.

NOTE: Daemon mode must be enabled in the configuration file (default).

Run as Sys V init script

In this form our wrapper script located in the /etc/init.d directory and is run according to symbolic links in the /etc/rc.x directories.

Set up the script to be run as a Sys V init script as follows:

ln -s /opt/Omega2-GarageDoors-MQTT2HA-Daemon/gardoors-daemon /etc/init.d/gardoors-daemon

 # configure system to start this script at boot time
/etc/init.d/gardoors-daemon enable

# let's start the script now, too so we don't have to reboot
/etc/init.d/gardoors-daemon start

# check to make sure all is ok with the start up
/etc/init.d/gardoors-daemon status  # look for "Running" vs. "NOT Running"

Update to latest

Like most active developers, we periodically upgrade our script.

To begin installation we need to find the latest released version of this script. Visit our releases page to find the latest release. Copy the Link Address of the file you want to use for install (.zip or .tar.gz file)

The following example shows the installation below the /opt directory:

# go to home directory
cd

# download the file
wget {the link address you copied}

Now You can update to the latest by following these steps:

# stop the service
/etc/init.d/gardoors-daemon stop

# disable it in-case we change the Start/Stop numbers
/etc/init.d/gardoors-daemon disable

# move to installed options directory
cd /opt

# move our existing directory out of the way
mv Omega2-GarageDoors-MQTT2HA-Daemon Omega2-GarageDoors-MQTT2HA-Daemon-old

# unpack the latest release file just downloaded
tar -xzvf /root/{filename}.tar.gz
(or) unzip /root/{filename}.zip

# this installed our updated files in /opt/Omega2-GarageDoors-MQTT2HA-Daemon, go there
cd /opt/Omega2-GarageDoors-MQTT2HA-Daemon
# (this makes sure our new files arrived in desired location)

# re-enable the service
/etc/init.d/gardoors-daemon enable

# restart the service with your new version
/etc/init.d/gardoors-daemon start

# check status of the running script
/etc/init.d/gardoors-daemon status  # look for "Running" vs. "NOT Running"

# if the status looks good then remove the older isntall directory
rm -rf /opt/Omega2-GarageDoors-MQTT2HA-Daemon-old

Integration

When this script is running data will be published to the (configured) MQTT broker topic "dvc-{hostname}/..." (e.g. dvc-picam01/...).

NOTE: Where there's an IP address that interface is connected.

This data can be subscribed to and processed by your home assistant installation.

Credits

Thank you to Thomas Dietrich for providing a wonderful pattern for this project. His project, which I use and heartily recommend, is miflora-mqtt-deamon


Disclaimer and Legal

Omega2+ is a product offered by Onion Corporation

This project is a community project not for commercial use. The authors will not be held responsible in the event of device failure or simply errant reporting/control of your garage doors, doggie doors or whatever doors you choose to control with this script.

This project is in no way affiliated with, authorized, maintained, sponsored or endorsed by Onion Corporation or any of its affiliates or subsidiaries.


About

Linux service providing garage door control on Onion Omega2+ device with data sent via MQTT to Home Assistant

Topics

Resources

License

Stars

Watchers

Forks