nygma2004 / beca_mqtt

Beca thermostat Modbus to MQTT Gateway
MIT License
16 stars 9 forks source link

Beca thermostat Modbus to MQTT Gateway

This sketch is designed to provide an MQTT gateway to Beca Modbus thermostats. It uses a ESP8266 (in my case Wemos D1 mini) and an RS485 to TTL converter to read the Holding Registers of the thermostat and publish those values to MQTT. Also subscirbes to MQTT and relevant updates are written into the Modbus device (like power status, fan speed, mode, target temperature and screen lock).

Project explained in detail in this video: https://youtu.be/d8nhMimx9-0

Libraries used

Wiring

Wemod D1 mini (or other ESP)            TTL to RS485
D1                                      DE
D2                                      RE
D5                                      RO
D6                                      DI
5V                                      VCC
G(GND)                                  GND

Red Modbus wire goes to the RS486 "A" screw terminals and black to "B".

MQTT topic

Root topic is defined in the beginning of the sketch and the full topic gets appended to this. I specified "/beca/" as my root, so my topic are e.g. "/beca/read/power". Values read from the device have "read" in the topic, and values sent to the thermostat have "write". Sending messages to the "read" topics get ignored. There is no error handling on the payload of the "write" messages, data received gets sent to the device.

Read topics (Published topics)

Test board shown in the video

This is the general layout of the board showing how the Wemos D1 mini and the RS485 board is oriented: General board layout

This is the side where the Wemos plugs in. You see the red +5V wires connected to the 5V pin of the Wemos and Vcc of the RS486 board. Black goes to GND on both: Wemos side

And the other side of the board where the RS485 plugs. Yellow wires are the data wires, blue are the enable wires: Wemos side

Node-Red

There is an example Node-Red flow (also shown in the video), which shows how to communicate with the device from Node-Red. The flow is in Gitbuh, and also here: https://flows.nodered.org/flow/286a8cea2fbb2a60544f0dd2faefda2a

PCB

I have also designed a PCB for this board. You can see my PCB project at PCBWay where you can order the PCB but you can also download the gerber files if you want to manufacture elsewhere: https://www.pcbway.com/project/shareproject/ESP8266_Modbus_board.html You can find the BOM on the PCBWay project page. I purchased most of the components on eBay, but some of the links do not work any more. But only the RS486 to TTL converter is "special" everything else can be found in many different places, like Aliexpress.

Custom Case

I have design a 3D printable case for the board, you find all the information in the case folder.