This is a Home automation project.
Pronounced "Ti d’Homme" in French.
This repository contains a hat project that integrates many devices and protocoles into an enabled Home Automation.

This project tries to offer a lot of flexibility in intergrating heterogeneous systems, while remaining simple: KISS (Keep It Simple Stupid).

Standard principles similar to IFTTT (If This Then That) can be applied, although architecture allows more flexible interoperability, yet simple-enough to understand and adapt to customized use-cases.

Overview

Example Usage

Sensors (DIY or proprietary) are sending room temperatures, motion or doors state.
A small and flexible Node-Red workflow allows to orchestrate heaters based on simple rules around sensors values and/or schedule and/or external weather.

Example Usage

Sensors (DIY or proprietary) are sending power and energy consumption.

Grafana allows to analyze and take next best improvements actions. This is possible to enable Solar routers, etc

1. Design

1.1. Principle

The source and explanation in this repository are following few principles:

  • Avoid monolithic home automation frameworks

  • Avoid using proprietary gateways named boxes such as any IKEA, Xiaomi, Amazon Echo, Leroy Merlin, Philips, Lidl, etc

  • Use (or re-use) available technology, avoid deprecation, but stay open to new technology

  • Client(s)/server(s) plugs together using any progamming language by leveraging message queues (MQTT) when necessary

  • DIY sensors or Web devices are using simple arduino sketches (Arduino, ESP8266, ESP32, etc)

  • Each element (e.g. Timeseries datastore) can be any, or multiple, and are interchangeable and migration-friendly

  • Deploy as much as possible with automation in mind, using Docker

1.2. Architecture

There are only few technical concepts:

  • Communication of each element from the system is done through messaging system MQTT bus (mosquitto)

  • Node-red enables loosely coupled custom workflow strategies

Architecture

In turns, this simplistic approach allows very flexible and powerful Home Automation.

1.3. Material

Hardware used for sensors/actors:

1.4. Dashboards

The project allows creation of simple Dashboards using Grafana and thanks to Victoria Metrics as timeseries database.

Power Overview

Dashboard Power - overview

  • Now:

    • Periode : Power cost period. "Heures Pleines" or "Heures Creuses" stands for high/low cost hours

    • Total (VA) : Power level from Téléinfo (EDF)

    • Total (W) : Power level from clamp

    • Consumers : Clamp meters on various elements (Zigbee clamps onto electric car, water heater, heaters)

    • Outlets : Wall plugs (CurrentCost or Zigbee plugs)

  • Energy Overview:

    • X days : Energy consumption (in kWh, percent, or € cost), for the selected period (1d,7d,30d,etc), and by categories

    • Total (tempo,hphc,base,kWh) : Energy consummed by hour, or day, or week slots and for each of the 6 Periode costs (EDF provider contract)

    • Clamps (kWh) : Energy consumed by devices, in kWh

Energy Timelines

Dashboard Power - hours

  • Total from grid : Energy consumed (in Wh, percent, or € cost)

  • Clamps (Wh): Energy consumed by devices, in Wh

The integration with Solar systems such as OpenDTU allows to view and diagnose daily production and compare grid consumption/production.
Solar Days Overview

Dashboard Solar - days

Solar Hours Overview

Dashboard Solar - hours

Dashboard Sensors Dashboard System

Dashboard System

2. How-To

This project can be entirely or partialy reproduced.
Hence this is not required to buy everything above mentioned to be working for Ti-Dhome.
If you need to control ZigBee devices, just implement relevant part of this project.

2.1. Setup modules

2.1.1. Orchestrator

Central to all the Orchestration of IoT is a docker container with Node RED.
Node-Red enables loosely coupled custom workflow strategies.
IoT devices can therefore be wired from monitoring to action.
Node-Red is like the advanced modern IFTTT (If This Then That) service, with much much more powerful integration capabilities, at the cost a requiring a little bit more effort to use :-)

Because Ti-Dhome requires few defaults and libs installed, a specific Docker version is cooked.
Check Ti-Dhome - Docker Node-Red (external git project)

2.1.2. Databases & Monitoring

Use any, as appropriate for your use-case.
Ti-Dhome uses Victoria Metrics to store Timeseries on sensors metrics.

Victoria Metrics is generally used in stack with monitoring of system, with Telegraf and Grafana.

2.2. Deployment

  • install Docker

  • clone this repository

    $ git clone https://github.com/kalemena/ti-dhome.git
    $ cd ti-dhome/src
  • edit the docker-compose.yml to map your USB gateway devices.

  • initialize few folders and config

    $ make init
  • start Node-RED

    $ make start

2.2.1. Strategies (aka Node-red flows)

Node-RED Flows

2.2.2. Security

$ openssl req -subj '/CN=localhost' -x509 -newkey rsa:4096 -nodes -keyout key.pem -out cert.pem -days 365

3. Modules

3.1. Module - Web Relay Board

This is an external Ti-Dhome module designed at https://github.com/kalemena/ti-dhome-web-relay-board

Integration in Node-Red is done through the REST API

3.1.1. Code

Parsing response from web relay
// name: Parse web relays
// outputs: 1
var outputMsgs = []
var displayMsg = ""
timestampH = new Date().toISOString()
timestamp = new Date().getTime()

for (var i in msg.payload.relays) {

    relayId = msg.payload.relays[i].id
    relayDesc = msg.payload.relays[i].description
    relayValue = msg.payload.relays[i].value
    type = 'toggle'
    entry = 0

    var msgS = {}
    msgS.topic = 'sensors/iotheaters/nodes/' + relayId + '/entries/' + entry + '/events/' + type;
    msgS.payload = {
        "gateway":"iotheaters",
        "id": relayId,
        "entry": entry,
        "type": type,
        "value": relayValue,
        "timestamp": timestamp,
        "timestamp-human": timestampH
    }
    displayMsg += relayDesc + "(" + relayId + ")=" + relayValue + "; "
    outputMsgs.push(msgS);
}

node.status({ fill:"blue", shape:"dot", text: displayMsg });

return [ outputMsgs ];

3.2. Teleinfo

In France, few components can be used to extract Main Home power consumption.

It is especially useful to have information such as consumption by time periods where periods can be high or low cost hours.

Linky

3.2.1. Hardware

Central board:

  • Arduino Nano 5v

  • Optocoupler: SFH6206

3.2.2. Arduino Schematic

Very basic, 2 pins to wire (e.g. pin 'D2' below).

Parts

3.2.3. Arduino Sketch

The Arduino sketch is ultra simple.
Simply ensure to set proper pin number for read (e.g. '2' below)

#include <SoftwareSerial.h>

SoftwareSerial cptSerial(2, 3);

void setup() {
  Serial.begin(1200);     // opens serial port, sets data rate to 1200 bps
  cptSerial.begin(1200);
}

void loop() {
  if (cptSerial.available())
    Serial.write(cptSerial.read() & 0x7F);
}

3.2.4. Installation

  • Once wired to computer, find correct USB tty number (dmesg | grep tty), then execute commands:

$ stty -F /dev/ttyUSB0 1200 sane evenp parenb cs7 -crtscts
$ cat /dev/ttyUSB0
  • Then other library can be used to parse and digest the teleinfo data that looks like below:

ADCO 02092xxxxxx @
OPTARIF HC.. <
ISOUSC 45 ?
HCHC 010956910 %
HCHP 016779643 >
PTEC HP..
IINST 021 Z
IMAX 047 J
PAPP 04860 3
HHPHC A ,
MOTDETAT 000000 B

3.3. RfxTrx433

RFXtrx433 is used to monitor and act on various proprietary systems such as:

  • Weather Station (Lacross Technology)

  • Home Central Alarm (Listen Door sensors)

  • Chacon devices

Ti-Dhome usage interconnects weather and alarm system.

Lacross products appears to be low quality.
Outdoor devices have rust after a year or so.
Indoor devices last 2 years for me as well.

After a bit of troublshooting, this module was not a good choice in Ti-Dhome project !

Because RFXtrx433 is a USB device with no particular driver needs, this module does not require any hacking.
The module is used with pushing events onto an MQTT queue, leveraged then from Node-Red flows.

3.3.1. Overview

Hardware overview

3.3.2. How-To

  • Connect rfxtrx433 to USB and find which usb resource connected

$ lsusb
$ dmesg
  • Setup automatic USB device mapping (optional)

# Grep information on device:
$ udevadm info -a -n /dev/ttyUSB1 | grep '{serial}'
ATTRS{serial}=="A600dVPj"
$ udevadm info -a -n /dev/ttyUSB1 | grep '{idProduct}'
ATTRS{idProduct}=="6001"
$ udevadm info -a -n /dev/ttyUSB1 | grep '{idVendor}'
ATTRS{idVendor}=="0403"

# Add rule for this device mapping:

$ sudo nano /etc/udev/rules.d/99-usb-serial.rules
SUBSYSTEM=="tty", ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", SYMLINK+="ttyRfxTrx"
  • Allow user access to resource and set speed

$ sudo stty -F /dev/ttyRfxTrx 38400 cs8
$ sudo chmod 777 /dev/ttyRfxTrx
  • Edit test script to point to USB devices or point Node-Red to correct USB device.

3.3.3. Test

Below is sample which listens on USB plugged RfxTrx433 and then publishes temperature/humidity/rain over MQTT.

#!/usr/bin/env node

var rfxcom = require("rfxcom"),
    eyes = require('eyes'),
    mqtt = require('mqtt');

var rfxtrx = new rfxcom.RfxCom("/dev/ttyRfxTrx", {debug: false} );
var client = mqtt.createClient('1883', 'localhost');

client.on('connect', function() {
  console.log('Connected for publications...');
});

// Start RFXCom activity
rfxtrx.on("th2", function (evt) {
    client.publish('sensors/' + parseInt(evt.id,16) + '/entries/1/events/temperature', '' + evt.temperature);
    client.publish('sensors/' + parseInt(evt.id,16) + '/entries/1/events/humidity', '' + evt.humidity);
});

rfxtrx.on("temp2", function (evt) {
    client.publish('sensors/' + parseInt(evt.id,16) + '/entries/1/events/temperature', '' + evt.temperature);
});

rfxtrx.on("rain2", function (evt) {
    var value = { rainrate: evt.rainrate, raintotal: evt.raintotal };
    client.publish('sensors/' + parseInt(evt.id,16) + '/entries/1/events/rain', JSON.stringify(value));
});

rfxtrx.initialise(function () {
    console.log("Device initialized");
});

3.4. Module - Current Cost

The CurrentCost EnviR allows to monitor live power usage and energy consumption. Up to 9 additional plugs can be used to monitor more devices.

Overview

Schema

See how to install and connect Hardware - Gateway USB CurrentCost for details.

Node-Red sample flow

Node-RED flow

Integration in Node-Red is done listening on USB tty device node. An XML to JSON translates information, and few lines of code are enough to read proper JSON fields.

Current Cost send several types of data:

  • Live power and live temperature (temperature of screen)

  • Historical energy consumption sent every 2h at mid-hour

The below Node-Red flow allows monitoring live power: