Homebridge – Domoticz: control MySensors objects with Siri on iOS10

You have developed your own objects connected based Arduino (or ESP8266) and MySensors library, here’s how to drive through voice Siri or from the new application House (HomeKit) of iOS10 . In this first tutorial, we’ll install and configure Homebridge with Domoticz.

Required configuration

To achieve this tutorial you will need the following items.

A Raspberry Pi 3 (or 2) Pi Raspberry with Domoticz installed and configured. If you’re new to home automation on or Domoticz , here is a series of articles to help you (in French at the moment !) :

A MySensors Gateway. For this tutorial, I used a Gateway network based ESP8266. You can start with this How To post (in french) to build a Network Gateway. At the time of writing this tutorial, version 2 of the MySensors library is not yet officially supported by Domoticz but it works very well.

An iPhone running iOS 9 or iOS10. For this article I used an iPhone 6s under iOS10.

Install and configure Homebridge for Domoticz

Homebridge is an Open Source project developed by Nick Farina (Github , website). Homebridge is a modular project which can add plugins depending on the material you want to add to the iPhone (or iPad). There are already more than 260 (the list here). There are plugins for leading software automation (Domoticz, Home Assistant, OpenHAB, Jeedom, FHEM…) and for many materials (bulbs Philips Hue, Synology NAS).

To install and configure Homebridge, I you Council to follow this tutorial . I met configuration with Domoticz difficulties in following the official tutorial (even if the procedure is similar to the final). Before you begin, be sure that your system is up-to-date

sudo apt-get update 
sudo apt-get upgrade

If you have installed Domoticz from the official image, then already extend the partition to make it all of the space on the SD card.

 sudo raspi-config

and Option 1 – Expand Filesystem. Then Finish and finally Allow reboot .

Install nodejs

Before installing Homebridge, it is necessary to install Nodejs. Follow the following steps that correspond to your Raspberry model.

Raspberry Pi A/B/B+ (old versions)

sudo apt-get remove nodejs
sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*} /var/db/receipts/org.nodejs.*
hash -r
wget https://nodejs.org/dist/v6.3.1/node-v6.3.1-linux-armv6l.tar.gz
tar -xvf node-v6.3.1-linux-armv6l.tar.gz
cd node-v6.3.1-linux-armv6l
sudo cp -R * /usr/local/
cd ~/

Raspberry Pi 2 ou 3

sudo apt-get remove nodejs
sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*} /var/db/receipts/org.nodejs.*
hash -r
wget https://nodejs.org/dist/v6.3.1/node-v6.3.1-linux-armv7l.tar.gz
tar -xvf node-v6.3.1-linux-armv7l.tar.gz
cd node-v6.3.1-linux-armv7l
sudo cp -R * /usr/local/
cd ~/

Installation de Homebridge et eDomoticz

Now we can install Homebridge and Domoticz plugin.

sudo npm set prefix '/usr' -g
sudo npm update -g homebridge --unsafe-perm
sudo npm update -g homebridge-edomoticz --unsafe-perm
sudo apt-get install libavahi-compat-libdnssd-dev

small explanations for those who do not npm

  • -g allows to make the overall usable package. Without the -g, the package is usable for the installation directory. In this case everything is downloaded in the directory of npm and all other packages can use.
  • option – unsafe-perm allows you to override any error messages during the installation

Get the Mac address of your Raspberry PI. It is unrated but without this configuration (trick found here), you may not be able to detect the gateway Homebridge on iPhone (or iPad). Run ifconfig. The Mac address of the RPI is HWaddr right .

hombridge domoticz adresse mac rpi hwaddr

Now create a folder for Homebridge

mkdir ~/.homebridge

Then, open the configuration file in a text editor (pico or nano).

 sudo nano ~/.homebridge/config.json

Paste this default configuration as a basis for an existing Domoticz server. Change the value of the username key by entering the Mac address of the Raspberry Pi.

Warning. You must enter the Mac address in uppercase otherwise it will cause an error and stop Homebridge.

You can use this to assign your Pin code.

{
    "bridge": {
        "name": "Homebridge",
        "username": "ADRESSE_MAC_PI",
        "port": 51826,
        "pin": "031-45-154"
    },
    "description": "Configuration file for (e)xtended Domoticz platform.",
    "platforms": [
        {
            "platform": "eDomoticz",
            "name": "eDomoticz",
            "server": "127.0.0.1",
            "port": "8080",
            "ssl": 0,
            "roomid": 0,
            "mqttenable": 1,
            "mqttserver": "127.0.0.1",
            "mqttport": "1883",
            "mqttauth": 0,
            "mqttuser": "",
            "mqttpass": ""
        }
    ],
    "accessories": []
}

Save CTRL + X, then Y.

 

Now run Homebridge

sudo homebridge
You must execute the command with sudo if you encounter HTTP 401 (Unauthorized)
homebrige domoticz premier demarrage

First boot. No devices configured under Domoticz.

At startup, Homebridge search all devices (devices) configured on Domoticz and makes them visible by an iPhone or an iPad connected to the local network.

Adding MySensors object under Domoticz

For the purposes of this tutorial, I have prepared a small connected object that is composed of a contactor as well as a led to simulate the ignition and extinction of a lamp. We could very easily replace the Led by a relay to control a lamp or the opening of an electric gate for example.

To achieve this Assembly, you will need the following items :

Circuit

The radio nRF24L01 + module must be powered by 3, 3Volts. On the other hand, the power 3.3V on some maps is average. It is better to use a socket adapter plate which has a better voltage regulator.

 

mysensors gateway esp8266 wifi led contacteur nrf24l01+

Code

With version 2 of MySensors, it is possible to add one (or more) node to a gateway. Here is the code of an ESP8266 WiFi Gateway which allows you to back up the state of a contact (detect the opening of a door for example) and simulate a flashlight with a Led lighting/extinguishing.

Before upload code in your ESP8266, change the following parameters:

  • MY_ESP8666_SSID: the name of the WiFi network
  • MY_ESP8666_PASSWORD: and password
  • MY_IP_ADDRESS: it is best to set the ip address of the Gateway…
  • MY_IP_GATEWAY_ADDRESS and SUBNET that matches your router
/**
 * The MySensors Arduino library handles the wireless radio link and protocol
 * between your home built sensors/actuators and HA controller of choice.
 * The sensors forms a self healing radio network with optional repeaters. Each
 * repeater and gateway builds a routing tables in EEPROM which keeps track of the
 * network topology allowing messages to be routed to nodes.
 *
 * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
 * Copyright (C) 2013-2015 Sensnology AB
 * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
 *
 * Documentation: http://www.mysensors.org
 * Support Forum: http://forum.mysensors.org
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 *******************************
 *
 * REVISION HISTORY
 * Version 1.0 - Henrik EKblad
 * Contribution by a-lurker and Anticimex, 
 * Contribution by Norbert Truchsess <norbert.truchsess@t-online.de>
 * Contribution by Ivo Pullens (ESP8266 support)
 * 
 * DESCRIPTION
 * The EthernetGateway sends data received from sensors to the WiFi link. 
 * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
 *
 * VERA CONFIGURATION:
 * Enter "ip-number:port" in the ip-field of the Arduino GW device. This will temporarily override any serial configuration for the Vera plugin. 
 * E.g. If you want to use the defualt values in this sketch enter: 192.168.178.66:5003
 *
 * LED purposes:
 * - To use the feature, uncomment WITH_LEDS_BLINKING in MyConfig.h
 * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
 * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
 * - ERR (red) - fast blink on error during transmission error or recieve crc error  
 * 
 * See http://www.mysensors.org/build/esp8266_gateway for wiring instructions.
 * nRF24L01+  ESP8266
 * VCC        VCC
 * CE         GPIO4          
 * CSN/CS     GPIO15
 * SCK        GPIO14
 * MISO       GPIO12
 * MOSI       GPIO13
 * GND        GND
 *            
 * Not all ESP8266 modules have all pins available on their external interface.
 * This code has been tested on an ESP-12 module.
 * The ESP8266 requires a certain pin configuration to download code, and another one to run code:
 * - Connect REST (reset) via 10K pullup resistor to VCC, and via switch to GND ('reset switch')
 * - Connect GPIO15 via 10K pulldown resistor to GND
 * - Connect CH_PD via 10K resistor to VCC
 * - Connect GPIO2 via 10K resistor to VCC
 * - Connect GPIO0 via 10K resistor to VCC, and via switch to GND ('bootload switch')
 * 
  * Inclusion mode button:
 * - Connect GPIO5 via switch to GND ('inclusion switch')
 * 
 * Hardware SHA204 signing is currently not supported!
 *
 * Make sure to fill in your ssid and WiFi password below for ssid & pass.
 */

#include <EEPROM.h>
#include <SPI.h>

// Enable debug prints to serial monitor
#define MY_DEBUG 

// Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h
#define MY_BAUD_RATE 9600

// Enables and select radio type (if attached)
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69

#define MY_GATEWAY_ESP8266

#define MY_ESP8266_SSID "SSID"
#define MY_ESP8266_PASSWORD "PASSWORD"

// Enable UDP communication
//#define MY_USE_UDP

// Set the hostname for the WiFi Client. This is the hostname
// it will pass to the DHCP server if not static.
// #define MY_ESP8266_HOSTNAME "sensor-gateway"

// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
#define MY_IP_ADDRESS 192,168,1,20

// If using static ip you need to define Gateway and Subnet address as well
#define MY_IP_GATEWAY_ADDRESS 192,168,1,1
#define MY_IP_SUBNET_ADDRESS 255,255,255,0

// The port to keep open on node server mode 
#define MY_PORT 5003      

// How many clients should be able to connect to this gateway (default 1)
#define MY_GATEWAY_MAX_CLIENTS 3

// Controller ip address. Enables client mode (default is "server" mode). 
// Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere. 
//#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68

// Enable inclusion mode
#define MY_INCLUSION_MODE_FEATURE

// Enable Inclusion mode button on gateway
// #define MY_INCLUSION_BUTTON_FEATURE
// Set inclusion mode duration (in seconds)
#define MY_INCLUSION_MODE_DURATION 60 
// Digital pin used for inclusion mode button
#define MY_INCLUSION_MODE_BUTTON_PIN  3 

 
// Flash leds on rx/tx/err
// #define MY_LEDS_BLINKING_FEATURE
// Set blinking period
// #define MY_DEFAULT_LED_BLINK_PERIOD 300

// Led pins used if blinking feature is enabled above
#define MY_DEFAULT_ERR_LED_PIN 16  // Error led pin
#define MY_DEFAULT_RX_LED_PIN  16  // Receive led pin
#define MY_DEFAULT_TX_LED_PIN  16  // the PCB, on board LED

#if defined(MY_USE_UDP)
  #include <WiFiUDP.h>
#else
  #include <ESP8266WiFi.h>
#endif

#include <MySensors.h>

#define CHILD_ID_CONTACTEUR 0
#define CHILD_ID_LED 1
#define CHILD_ID_LEVELBAT 2
#define CONTACTEUR_PIN D3         // Broche sur laquelle est attaché le contacteur (2 ou 3 si on veut 
#define LED_PIN D1                // Broche sur laquelle est branchée l'actionneur (LED, Relay...)
#define FREQ_ENVOI 10000          // Force l'envoi d'état au bout de 2s
boolean etatPrecedent = false;
unsigned long dernierEnvoi = 0;
MyMessage msgContacteur(CHILD_ID_CONTACTEUR, V_TRIPPED);
MyMessage msgLed(CHILD_ID_LED,V_LIGHT);

void setup() {
  pinMode(CONTACTEUR_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(CONTACTEUR_PIN, HIGH);
  digitalWrite(LED_PIN, HIGH);
}

void presentation()  {
  // Send the sketch version information to the gateway and Controller
  sendSketchInfo("Gateway MySensors v2", "1.0");

  // Register all sensors to gateway (they will be created as child devices)
  present(CHILD_ID_CONTACTEUR, S_DOOR);
  present(CHILD_ID_LED, S_LIGHT);
}


void loop()      
{     
  uint8_t etat;
  unsigned long tempsActuel = millis();
  
  // Read contact state / Lit l'état du contacteur
  etat = digitalRead( CONTACTEUR_PIN ); // == LOW;
  if ( etat != etatPrecedent || ( tempsActuel - dernierEnvoi  > FREQ_ENVOI ) ) {
    etatPrecedent = etat;
    dernierEnvoi = tempsActuel;
    Serial.print("Etat du contacteur modifie ");
    Serial.println(etat ? "Ouvert " : "Ferme" );
    send( msgContacteur.set( etat ? "1" : "0" ) );  
  }

  delay(5); 
}

void receive(const MyMessage &message) {
  // We only expect one type of message from controller. But we better check anyway.
  if (message.isAck()) {
     Serial.println("This is an ack from gateway");
  }
  
  if (message.type == V_LIGHT) {
     // Change relay state
     bool state;
     state = message.getBool();
     digitalWrite(LED_PIN, state? LED_OFF:LED_ON);
     // Store state in eeprom
     saveState(CHILD_ID_LED, state);

     // Write some debug info
     Serial.print("Incoming change for sensor:");
     Serial.print(message.sensor);
     Serial.print(", New status: ");
     Serial.println(message.getBool());
   } 
}

Configuration of the devices under Domoticz

To learn about how to add an object MySensors under Domoticz, follow this tutorial (in french), if not here is the steps in (accelerated).

Add a MySensors Lan Gateway in settings -> material . Specify the ip address of the Gateway and the port. Name, and then Add .


homebridge domoticz gateway mysensors

Add the devices from settings -> devices-> press the arrow green in front of every device to add. Type a name for the device. After adding, the arrow turns blue.

homebridge-domoticz-dispositifs-mysensors-inclus

Go to the switches and change views if necessary.

homebridge-domoticz-interrupteurs-mysensors

Now rerun Homebridge to see devices that will be visible to iOS.

homebridge edomoticz capteur exposes ios homekit

Configure iPhone or iPad application House

On your iPhone or iPad (preferably under minimum iOS10), launch the home application.

icone application maison ios10

Uour iPhone (or iPad) must be connected to the local network in WiFi to be able to add a bridge and accessories. Tap Add aaccessory.

homekit home domicile ios10 ajout accessoire homebridge

Home screen of the app House

If everything is set up, you must have an accessory named Homebridge appearing. Select it.
homekit home domicile ios10 passerelle homebridge trouvee

Bridge Homebridge found!

Enter manually (or try your luck with the optical recognition) the Pin code displayed on the Terminal.
home kit home domicile ios10 saisie code pin

Entry of the pin.

Wait a few moments during the twinning of the bridge.
home kit home domicile ios10 jumelage homebridge

Current twinning

And here!

 

homekit home domicile ios10 pont homebridge ajoute

Bridge Homebridge successfully added

You can give a new name to the bridge and assign a place. As a bridge to an Automation server, interest is limited.

 

On peut attribuer un lieu (pas très utile pour Domoticz)

You can assign a place (not very useful for Domoticz).

Home then proposed that the first presentation device. In this case, the lamp (simulated by an Led). Assign him a place and change its icon (switch, bulb or fan). Long press on the icon from the home screen of Home then detail can change at any time.

Include in Favorites. Include all the accessories that you want to find in the center of the LockScreen notification.

Awarded a place. Assign a place to fly the accessories to the voice since Siri more easily. It suffice to say “light show” or “turn off the light in the living room…”

lumiere salon attribuer lieu homebridge domoticz mysensors

The same goes for the door switch

homekit-home domicile ios10 ajout accessoire contacteur porte

And the door switch

It’s over! You can also look at the active icons of accessories.

maison homekit ios10 homebridge domoticz mysensors

Lock your iPhone and open the notification Center. Drag the Panel to right twice to access the control panel of the Home Favorites.

ios10 centre notification favoris homebridge domoticz mysensors

Does it work outside my home?

Here is the main interest to use the application (HomeKit) Home of iSO10. You don’t need to expose your Automation server to the internet. It is iOS (HomeKit) and Apple servers via your iCloud account that takes care of everything and this in a secure way. But to make it work, you need a compatible hardware HomeKit home and must be turned on (.. .and loaded).

Here’s what you can do based on your hardware (go to this page Apple to learn)

  • to control accessories remote
    • 3rd generation Apple TV. It is not possible to access the HomeKit surveillance cameras.
    • 4th generation Apple TV equipped with tvOS 9.0 or higher
  • to set up the automation and the permissions of users

In summary, so you’ll need a fairly new iPad (iPad Air for example) or Apple TV of 4th generation (to be able to create simple scenarios). When you use home away from home, it will take a few seconds the that ‘ HomeKit retrieves the connection with the material playing the role of repeater (hub HomeKit). The 3rd generation Apple TV is still usable but the features are more limited (cannot use a camera home automation, creating automation, manage users).

centre-notification-accessoires favoris scene ios10 homebridge domoticz mysensors 3g 4g

You have problems outside the home you

Do not expect an immediate response to your actions when your iPhone is more connected to WiFi to Domoticz (or any certified device HomeKit). It takes some time for action in iCloud and then goes down on the iPad or Apple TV from your home. Even if iCloud has made big progress in terms of reliability and performance, there is a latency time which may also come from your 4 G (or 3 G) connection. Let’s say that a delay of a few seconds is not unusual.

Another finding, the status of accessories is not updated in real time in the notification Center. For example, if a switch goes back the opening of a door, the corresponding icon will not be enabled. The status of an accessory is updated to the Panel or display during manual action from the Panel.

Finally last point, Homebridge is a project “border line”. It is not included in a certified Apple product. We stay in the DIY, it works very well, but from time to time…

Fly to voice your Domoticz devices with Siri

Now that everything works in Home, it’s time to test the voice command with Siri.

Try to turn on the light in the living room-online “Hey Siri turns on the light in the living room”.

ios10 dis siri allume la lumiere du salon homebridge domoticz mysensors

Similarly to turn off say “turn off the light in the living room.

ios10 dis siri éteint lumiere salon homebridge domoticz mysensors

Finally, ask Siri if the door is closed: “Hey Siri the door is open.”

ios10 dis siri porte ouverte homebridge domoticz mysensors

List of commands that work with Siri and advice

So that Siri is able to make the link with the accessory Domoticz, name the exactly by its designation. Rather than putting an extension designation, best is to assign a place to each accessory. It allows Siri to make the connection easier. By example, rather than assign ‘light show’, ‘light’ name and create a “lounge”. Otherwise when asked ‘ light show ‘ it doesn’t work. If you have many accessories, you have to standardize your designations, or station to headache to remember the name given to the lamp in the attic ;-).

Under iOS10, here is a list of actions that you can perform at the votes with Siri ( from this list ):

order Siri (key word of action) usage examples accessory place set
turn on turn on the light in the room. light room
turn off turn off the light light
turn off the lights in the House of Chloé light House of Chloé
Thames Thames light light
rule sets the brightness to 50% 50%
set the thermostat on 21 ° on the ground floor Thermostat ground floor 21 ° C
put put the heating on (22) heating 22 ° C
turn on
down Dim the lights in the kitchen light kitchen
reduce reduce by half lighting of the dining room dining

You can also create and trigger scenes. To call him, simply saying his name, for example “Hey Hello Siri”.

maison bonjour scène ios10 homebridge domoticz mysensors

To create a scene, go to the parts ,

ajout scène ios10 homebridge domoticz mysensors
Press the more then Add a scene.  There are already existing scenes in the list.

scene ios10 homebridge domoticz mysensors

Finish the configuration. For example the scene Hello to turn on all the lights in the living room.

scene ios10 homebridge domoticz mysensors

It’s ready.

scene ios10 homebridge domoticz mysensors

Homebridge is a large community-supported Open Source project. Its very open architecture allowed the third development of many plugins. The eDomoticz plugin is very complete and responsive to the actuators. Turn on, turn off a lamp answers instantly. The update of the State of a contactor is longer, it is not uncommon to wait almost a minute.

Side iOS, the Domoticz is very simple and intuitive. You can even drive your installation from your iPhone out of the House without having to make your Raspberry Pi available on the internet. It is a true guarantee of security. Side scenarios, the home application is much less advanced than software automation, but the combination of the two solutions is really very soft and nice to use.

Subscribe to the weekly newsletter

No spam and no other use will be made of your email. You can unsubscribe anytime.

Tags:

We will be happy to hear your thoughts

Leave a Reply

DIY Projects
%d bloggers like this: