1. Description
This project is an Open Source / Open Hardware minimal approach to build a Web Relay Board.
This Web Relay Board:
-
allows to connect 16 devices allowing to switch on/off Main Power
-
has temperature / humidity sensor
-
captures Téléinfo (France Electricity provider serial consumption data)
-
has REST API
-
has Web Socket API
Caution with 230v. Do not use high current. |
The Web Relay board uses HTTP/REST API as interface.
Additionaly, simple Web UI is implemented on top of the REST API.
In practice, the Web Relay is used to manage electric heaters with data wire named fil pilote which is 230v at very low current. The heaters are ochestrated through Node-Red.
This project is part of a wider TiDhome Home Automation project. |
Above is an example of a dashboard created as part of Ti-Dhome project and using mostly Teleinfo data produces by the module in this repo, published to Node-Red through Web Sockets and inserted in Prometheus for Grafana use. |
2. Specifications
-
16 relays for 230v main current
-
Wifi
-
WebSockets
-
Reads EDF Téléinfo (France power consumption of the home as serial stream of data)
-
Reads room temperature and humidity
-
Simple web UI
4. Integration in Electric panel
Here is an integration of freshly solder PCB into electric panel:
5. BOM
Here is list of items to purchase:
Component | Price | Comment |
---|---|---|
SainSmart 16 relays |
~ 12€ |
16 relays 12v with 5v data triggers |
Wemos ESP8266 or ESP32 with (Wemos-clone pin layout)] |
~ 4€ |
|
2x 74HC595 |
~ 0.2€ |
Shift Register IC DIP-16 Texas (sold by 20) |
2x ULN2803 |
~ 0.12€ |
(sold by 20) |
Optional (for Teleinfo and Temperature sensor |
||
SFH6206 |
< 1€ |
Optocoupler for Teleinfo |
4.7k resistor |
For Teleinfo |
|
HTU21D |
< 4€ |
Temperature sensor |
Total |
~ 20€ |
6. API
REST API and websocket API are returning same JSON structure data. Additionaly, websocket will periodically push changing info such as other user relay switch, Téléinfo and temperature. |
Below is API description with examples:
6.1. GET /
Main HTML page display simple button and status:
6.2. GET /status
$ curl http://ioteleinfo.local/status | jq .
{
"system": {
"chip-model": "ESP32-D0WDQ6",
"chip-revision": 1,
"chip-cores": 2,
"chip-bluetooth": "/BT/BLE",
"chip-id": "ABCDEFGH",
"heap": 256412,
"flash-size": 4,
"flash-type": "external",
"time-iso": "2021-02-06T11:44:37Z"
},
"sensors": {
"temperature": 13.12,
"humidity": 62.5
},
"relays": [
{
"description": "Ch. Jeux",
"id": 0,
"value": 0
},
{
"description": "Bureau",
"id": 1,
"value": 0
},
...
{
"description": "Hall",
"id": 15,
"value": 0
}
],
"teleinfo": {
"ADCO": 123456789,
"OPTARIF": "HC..",
"ISOUSC": 45,
"HCHC": 32548297,
"HCHP": 40260054,
"PTEC": "HP..",
"IINST": 5,
"IMAX": 90,
"PAPP": 1100,
"HHPHC": "A",
"MOTDETAT": 0
},
"message": "status"
}
6.3. GET /relays/set?id=X&value=Y
Specify id between 0 and 15:
$ curl -v http://ioteleinfo.local/relays/set?id=1&value=-1
{
"id": 1, "value":0
}
value is 0, 1 or -1 to switch blindly |
6.4. GET /test
Triggers a cycle on/off on each of the relays, with 500ms in between on/off.
Useful to test the websocket reaction of Web UI.
$ curl -v http://ioteleinfo.local/test
6.5. WebSocket
Example at index.html
{
"system":{
"time":"1615034255"
}
}
{
"teleinfo":{
"PAPP":"01140"
}
}
{
"sensors":{
"temperature":13.2,
"humidity":62.75
}
}
{
"relays":[
{"id":2,"value":1}
]
}
7. TODO
-
create 3D-printed plastic box
8. Iterations
8.1. 0 - Manual Setup ESP8266 board in Arduino IDE
Since this tutorial was written, I made available a Docker Arduino IDE |
The development uses simple Arduino IDE with ESP8266 libs.
Follow this guide to setup ESP8266 board in Arduino IDE: https://github.com/esp8266/Arduino
Documentation is here: http://esp8266.github.io/Arduino/versions/2.3.0/
8.1.1. Procedure
-
Import ESP Board into Arduino IDE
-
Load the Libraries for ESP8266
-
Load sample hello app into NodeMCU
In Arduino IDE, select proper board, example:
- Tools/Cards/NodeMCU 1.0 board
- CPU 160 MHz
- <correct USB device>
Create sketch such as the ESP8266 LED
void setup() {
// initialize digital pin 2 as an output.
pinMode(2, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
LED should blink as shown below:
-
Control a Wifi LED
-
Upload sketch found at ESP8266 LED WIFI with changing Wifi network settings
-
Open Serial Consoleon Arduino IDE
-
Ensure from logs that NodeMCU connected to local Wifi
-
Browse to IP address logged out
-
Click on button to switch led On and Off
-
8.1.2. Resources
8.2. 1 - Docker Setup ESP8266 board in Arduino IDE
-
check your tty device. e.g. /dev/ttyUSB2 and match it in Makefile
-
open the Arduino IDE with:
$ make arduino
8.3. 2 - Breadboard relay board
Using Node MCU for Wifi, there are few remaining constraints:
-
GPIOs are 3.3v and we need 5v: ULN2803 to the rescue
> ULN2803 is a Darlington array which can be used to translate from 3.3v digital outputs to 5v
-
Not enough GPIOs: 74HC595 to the rescue
> This components enables use of 3 GPIOs to be used in serial protocol to handle in our case the 16 outputs requires for relay board
Photo (showing wired relay 8 to 15):
Fritzing picture: