esphome / feature-requests

ESPHome Feature Request Tracker
https://esphome.io/
408 stars 26 forks source link

Support multiple parallel PZEM004T sensort - older gen #1525

Closed sle118 closed 2 years ago

sle118 commented 2 years ago

Describe the problem you have/What new integration you would like

I am designing a circuit which will allow connecting up to 8 PZEM004T sensors in parallel and communicate individually to them using their unique address. Each device has a unique address that is set beforehand using a TTL adapter or some other method of sending the "set address" command.

Please describe your use case for this integration and alternatives you've tried:

I am looking to get detailed/whole house energy usage breakdown from a large electrical panel and feed these into Home Assistant so I can better understand the energy usage patterns and see where I could reduce it. There's a number of possible alternative to using esphome (for example ESPURNA), but the esphome platform seems really mature and diverse enough that I wish to use it going forward. Alternatively, I could probably setup a single ESP8266/ESP32 for each PZEM004T, but this would be quite a bit wasteful.

Additional context

I'm very familiar with embedded development and I am willing to implement the feature myself and eventually send a PR for upstream merging. However, I'd need some guidance on the best way to achieve my goal from a design perspective. For instance:

The parallel communication to older gen units was tested on espurna and known to be working. More specifically, the author of the code has provided some starting ideas for a communication bus using Schottky diodes.

// Needed when connecting multiple PZEM004T devices on the same UART
// *You must set the PZEM004T device address prior using this configuration*
//
// +---------+
// | ESPurna |                                             +VCC
// |   Node  |                                               ^
// | G  T  R |                                               |
// +-+--+--+-+                                               R (10K)
//   |  |  |                                                 |
//   |  |  +-----------------+---------------+---------------+
//   |  +-----------------+--|------------+--|------------+  |
//   +-----------------+--|--|---------+--|--|---------+  |  |
//                     |  |  |         |  |  |         |  |  |
//                     |  |  V         |  |  V         |  |  V
//                     |  |  -         |  |  -         |  |  -
//                   +-+--+--+-+     +-+--+--+-+     +-+--+--+-+
//                   | G  R  T |     | G  R  T |     | G  R  T |
//                   |PZEM-004T|     |PZEM-004T|     |PZEM-004T|
//                   |  Module |     |  Module |     |  Module |
//                   +---------+     +---------+     +---------+
//
// Where:
// ------
//     G = GND
//     R = ESPurna UART RX
//     T = ESPurna UART TX
//     V = Small Signal Schottky Diode, like BAT43,
//         Cathode to PZEM TX, Anode to Espurna RX
//     R = Resistor to VCC, 10K

https://github.com/xoseperez/espurna/blob/dev/code/espurna/sensors/PZEM004TSensor.h

I have attempted to connect more units in parallel, but quickly came to realize that the ESP8266's poor GPIO's would just be unable to drive the leds of 8 opto couplers. So I came with possible solution for the Tx side of the ESP32, which I'll be using for this project: image (edit: changed the Tx MOSFET to N Connector Type)

I will be able to confirm (or not) when I get my boards from JLCPCB in a few weeks (hopefully).

Thank you for helping me getting started with coding the enhancement!

Below is the circuit design that I have sent to production yesterday. My intention is to make the design publicly available when I have debugged all the hardware issues (this is the 1st batch of the design and I expect some magic smoke to come out of at least one of the units or, at best, to see that something is wrong and that I have to do some rework/changes).

image edit: Updated board rendering to new version

sle118 commented 2 years ago

So I've received my boards.

Any inputs here would be appreciated.

image
sle118 commented 2 years ago

I ended up purchasing pzem004t v3, which can be configured with multiple sensors each with its own address. I'll edit the final MOSFET connection which works great now