superjunky / Domoticz-Brel-Plugin

A Python plugin for Domoticz to controll Brel Home Hub
MIT License
3 stars 3 forks source link

A Domoticz plugin for Brel Home Hub

Brel Home Hub

Brel offers some great motors for blinds and screens, for inside and outside use. Now there is a gateway in the form of the Brel Home Hub, which can be controlled from your smartphone. Ofcourse we want Domoticz to be able to communicate with the Home Hub aswel, and now we can! If you want to know more what the Brel Home Hub is all about, check their website: (https://www.brel-motors.nl/brel-app.html). But for now, let's read ahead and check out this plugin!

Key features

Supported Brel devices

The plugin supports and is able to controll the following devices:

The plugin doesn't work with:

Compatible hardware

Most systems capable of running domoticz and has a version of python3 available should be able to run the plugin.

Software requirements:

  1. Python version 3.5.3 or higher, 3.7.x recommended
  2. Domoticz compiled with support for Python-Plugins
  3. Upgraded pip
  4. You need the pycrypto Python-module

Installation:

1. Clone Brel plugin into domoticz plugins-directory:

  $ cd domoticz/plugins/
  $ git clone https://github.com/superjunky/Domoticz-Brel-Plugin.git Domoticz-Brel-Plugin

2. Update pip:

  $ pip3 install -U pip

3. Install pycrypto

The plugin uses the pycrypto python module (https://pypi.org/project/pycrypto/)

  $ pip3 install pycryptodome

3.1 Let Domoticz know about the pycrypto module

Domoticz may not have the path to the pycrypto library in its python environment. In this case you will observe something starting like that in the log:

To find where pycrypto is installed, in a shell:

  $ pip3 show pycrypto

The Crypto directory should be present in the directory indicated with Location.

When you have it installed, just add a symbolic link to it in Domoticz-Brel-Plugin directory with ln -s. Example:

  $ cd ~/domoticz/plugins/Domoticz-Brel-Plugin
  $ ln -s /home/pi/.local/lib/python3.5/site-packages/Crypto Crypto

4. Restart domoticz and enable Brel Home Hub from the hardware page

Don't forget to enable "Allow new Hardware" in the Domoticz settings page.

Configuration

The "Defaults array" explained

Let's start with an example:

  -1:{"o":{"P":15,"A":25},"c":{"P":80,"A":80}}

In conclusion, a full array could look like this:

  -1:{"o":{"P":15,"A":25},"c":{"P":100,"A":90}}, 0:{"o":{"A":25}}, 3:{"c":{"P":80,"A":80}}

Updating plugin

To update the plugin to the newest version, stop domoticz, enter the plugin directory, pull the latest changes from git and restart domoticz:

  $ cd domoticz/plugins/Domoticz-Brel-Plugin
  $ git pull

Known issues

None so far.

Usage

Devices have to be added to the gateway as per Brel's instructions, using the official Brel app.

Blinds and curtains Position

Domoticz sets the position of a blind as a percentage between 0 (fully open) to 100 (fully closed). You need to set the minimum/maximum posistions of the blind before using Domoticz. Please refer to the instructions from Brel on how to set the maximum positions of a blind.

Venetian blinds Tilt

Besides the position, Domoticz can set the angle of a venetian blind in degrees. An additional device is created, where the name will end with "Tilt". For this device you can set a percentage between 0 and 100, and is converted by the plugin into degrees between 0 and 180. To open your blinds, set the angle to 50% (which translates to 90 degrees).

By default this Tilt-device in Domoticz will send a 90-degrees-command when switched on, and a 0-degrees-command when switched of. Use the slider to choose a custom position.

Bonus: Homebridge

So, you have Domoticz running at home, AND you have an iPhone? Chances are you have a copy of Homebridge running aswel. Then go ahead:

And there you go, your Brel-blinds can be controlled from within your Apple's Homekit :)

{
    "accessory": "mqttthing",
    "type": "windowCovering",
    "name": "{Blinds name}",
    "topics": {
        "getCurrentPosition": {
            "topic": "domoticz/out/mqtt/MQTTthing",
            "apply": "return JSON.parse(message).idx == {idx_position} ? Math.round( 100 - JSON.parse(message).svalue1 ) : undefined"
        },
        "setTargetPosition": {
            "topic": "domoticz/in",
            "apply": "return JSON.stringify({command: 'switchlight', idx: {idx_position}, switchcmd: 'Set Level', level: Math.round( 100 - message ) })"
        },
        "getTargetPosition": {
            "topic": "domoticz/out/mqtt/MQTTthing",
            "apply": "return JSON.parse(message).idx == {idx_position} ? Math.round( 100 - JSON.parse(message).svalue1 ) : undefined"
        },
        "getPositionState": {
            "topic": "domoticz/out/mqtt/MQTTthing",
            "apply": "return JSON.parse(message).idx == {idx_position} || JSON.parse(message).idx == {idx_tilt} ? 'STOPPED' : undefined"
        },
        "setTargetHorizontalTiltAngle": {
            "topic": "domoticz/in",
            "apply": "return JSON.stringify({command: 'switchlight', idx: {idx_tilt}, switchcmd: 'Set Level', level: Math.round( (message + 90) / 1.8) })"
        },
        "getTargetHorizontalTiltAngle": {
            "topic": "domoticz/out/mqtt/MQTTthing",
            "apply": "return JSON.parse(message).idx == {idx_tilt} ? Math.round( (JSON.parse(message).svalue1 * 1.8) - 90 ) : undefined"
        },
        "getCurrentHorizontalTiltAngle": {
            "topic": "domoticz/out/mqtt/MQTTthing",
            "apply": "return JSON.parse(message).idx == {idx_tilt} ? Math.round( (JSON.parse(message).svalue1 * 1.8) - 90 ) : undefined"
        }
    },
    "startPub": [
        {
            "topic": "domoticz/in",
            "message": "{\"command\": \"getdeviceinfo\", \"idx\": {idx_position} }"
        },
        {
            "topic": "domoticz/in",
            "message": "{\"command\": \"getdeviceinfo\", \"idx\": {idx_tilt} }"
        }
    ],
    "manufacturer": "Brel",
    "model": "Venetian Blinds",
    "serialNumber": "Idx {idx_position}"
}