arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
21.71k stars 4.72k forks source link

Adding support for PZEM004T energy monitor for 3 phase - request #2315

Closed roblad closed 4 years ago

roblad commented 6 years ago

Hi,

Is it possible add USE_PZEM004T and add support for PZEM004T Energy monitor for 3 phase by using USE_SERIAL_BRIDGE and report each phase through that functionality ? May be there is possibility to use 3 phase config for USE_PZEM004T as it is in that project:

https://github.com/apreb/eNode

roblad commented 6 years ago

Hi,

Is it possible to add 3 PZEM004T in one node?

Rgds, RL

0x3333 commented 6 years ago

I'm looking for the same thing.

As long as I can tell, each PZEM004T can be directly addressed, so you can hookup as many PZEM004T as you can in the same UART, when you read, you send the "ip address" of each module.

But the code in xdrv_03_energy.ino is not able to read from multiple sources. When I get my units I'll work on this. Don't know if this can be accomplished, but would be great.

roblad commented 6 years ago

Hi, It means that when I change IP for each PZM and plug 3 of themas a 3 soft serials or plug 3 of them to 1 serial ? Could you sent me a private mesage if you could with more detailed manual or some code that you hook haw it looks. I am not such expert as you it will be very usfull :-)

Thanks,

0x3333 commented 6 years ago

I mean plugging all the 3 PZEM in the same hardware/soft serial, like this:

smms_ttl

The diode can be a BAT45, the pullup resistor can be a 10K to 5V.

But you need to program the PZEM address before using this method, the address can be sequential, like 0.0.0.1,0.0.0.2,0.0.0.3, it is not really a IP address.

But the tasmota must be changed to accommodate multiple meters, you can test using an arduino.

roblad commented 6 years ago

Hi,

Many thanks, but I have a question, may be stupid, Master UART means tasmota serial ? Yes ?

And all of the slaves there are PZEMs Am I right ?

Have you got it on your Arduino/ESP connected ?

I will try it ofcource but first of all I am working for MQTT bridge through serial bridge of Tasmota - I have Nodes based on it:

https://github.com/artekw/sensnodetx https://github.com/artekw/sensnodetx

and receiver basenode which prints output to serial as JSON, I am working on www displaing all recaived data as normal sensors pluged to tasmota, next one task will be the hook of PZM004 ino.

and

also see that:

https://github.com/apreb/eNode/issues/1#issuecomment-354369777

0x3333 commented 6 years ago

Yes, Tasmota master, PZEM slaves. Yes, connected to ESP.

roblad commented 6 years ago

Hi,

Could you share Your ino code for PEZM for further testing, I have 3 already :-) after 2 months shipment :-) ?

0x3333 commented 6 years ago

Well, I don't have it actually, but here is some to start with:

#include <PZEM004T.h>

PZEM004T pzem(10, 11);

IPAddress ip[3];

void setup() {
  Serial.begin(9600);

  ip[0] = IPAddress(0, 0, 0, 1);
  ip[1] = IPAddress(0, 0, 0, 2);
  ip[2] = IPAddress(0, 0, 0, 3);
}

void loop() {
  for (uint8_t j ; j < 3 ; j++) {
    Serial.print("ID: ");
    Serial.print(j);
    Serial.print(": ");
    float v = pzem.voltage(ip[j]);
    if (v < 0.0)
      v = 0.0;
    Serial.print(v);
    Serial.print("V; ");

    float i = pzem.current(ip[j]);
    if (i >= 0.0) {
      Serial.print(i);
      Serial.print("A; ");
    }

    float p = pzem.power(ip[j]);
    if (p >= 0.0) {
      Serial.print(p);
      Serial.print("W; ");
    }

    float e = pzem.energy(ip[j]);
    if (e >= 0.0) {
      Serial.print(e);
      Serial.print("Wh; ");
    }
    Serial.println();
  }

  delay(1000);
}

Remember to call pzem.setAddress(ip[X]); with only one connected to set it's internal address.

roblad commented 6 years ago

Hi,

Many thanks, but what do you mean 👍 Remember to call pzem.setAddress(ip[X]); with only one connected to set it's internal address.

I did not catch you, it means that I have to set the pzem.setAddress(ip[X]) step by step with plug only one PZEM for initial setup of IP ? And next plug all of them for finale mastering am I right ? What about Save set values in PZEM, will they disappear after power lost ? What do you mean "with only one connected to set it's internal address"

0x3333 commented 6 years ago

Buddy, dont get me wrong, but you should do your homework...

Each PZEM have an Address. You must set a unique address to each one, individually. That's what I meant with setAddress. Create another sketch to set the addresses. Then run the one I provided.

roblad commented 6 years ago

Hi,

" but you should do your homework" yes I will :-), thanks for explanation, I let you know about my results :-)

0x3333 commented 6 years ago

Great, as soon as I get my sonoffs, I'll let you know my findings.

asking23 commented 6 years ago

Any updates ? but in this way we would never be able to poll 3 Phases Simultaneously to Make Graph/Trend 3 Phases. Each Consecutive reading will have 1 Second Interval so wont be able to correlate voltage on each phase to each other.

0x3333 commented 6 years ago

I'm looking to do the readings in the same time slice. But I'll need to change the code. I'm on vacations now, next week I'll work on it.

0x3333 commented 6 years ago

Here I'm again. I read the code and believe that create another xdrv for this is the best option to me. Change a code that is shared with other devices to add 2 more phases will require a lot of effort and will not benefit the others. I'm looking to create a xdrv_13_energy_3phases.ino driver, especifically to PZEM004T, this way it will not add more line of codes to other energy meters and increased complexity.

I've only an hour at night to work on side projects, but will give it some attention.

@arendst , do you believe that this is the right thing to do? What is your direction on this matter?

Thanks!

roblad commented 6 years ago

Hi,

Where is xdrv_13_energy_3phases.ino ?

0x3333 commented 6 years ago

There is no xdrv_13_energy_3phases.ino, I'm about to write it.

roblad commented 6 years ago

aaaaaaa :-)

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

0x3333 commented 5 years ago

Well, I changed to ESPurna, and in that firmware, it's simply not possible, it is too slow to read all magnitudes from all sensors. I'm working in a custom board with an Arduino Pro Mini that will read all PZEM(Max 6 devices) and will communicate using I2C, all measurements will be read in a single call. I'll let you know the progress.

rt400 commented 5 years ago

any new with this ?

0x3333 commented 5 years ago

I'm finishing the custom board, the board will read up to 6 PZEM004T and will communicate using I2C/SPI. It constantly read the PZEM and buffer the responses, when asked the response is instantaneous. In my board I also added a ESP-01 module, so I don't need a Sonoff Basic or alike. But it is not finished yet...

screen shot 2018-08-21 at 11 07 35

screen shot 2018-08-21 at 11 07 50

0x3333 commented 5 years ago

Probably I will use this repo: https://github.com/0x3333/powermeter

But the code probably will change...

rt400 commented 5 years ago

https://github.com/apreb/eNode did you see this ? its looks that he success to do that.. can you share the diagram of connection ? and i understant that you connect directly to wemos or arduino board ..so why use also in spi or i2c ?

0x3333 commented 5 years ago

Yes, I saw that.

In my case, the arduino pro mini(Not running arduino) is connected to a ESP-01(Running Espurna, but can work with any other firmware) using a spi connection. The arduino is only doing the hard work.

roblad commented 5 years ago

Hi,

Great, but will you add that to tasmota as a 3 phase module ?

0x3333 commented 5 years ago

Sure, @arendst will need to approve a custom driver, but sure.

roblad commented 5 years ago

ok Iam waiting :-), but all soft will be inside ?

ascillato2 commented 5 years ago

Hi,

Any news on this?

0x3333 commented 5 years ago

Not yet, but I'm working on creating a new library non-blocking instead of a custom board. Probably I'm the only one working on this, so, asap I'll finish the library, that will be exclusive to ESP, I'll let you guys know.

roguestreak commented 5 years ago

Thanks 0x3333, I've just picked one of these up and would like to be able to read multiple of them from one Tasmota'd Sonoff (or wemos), in my case it's single phase so the timing isn't an issue, I just want to be able to get the data from multiple of them without needing multiple ESP8266 devices; would be a good cheap way of adding power monitoring to each circuit in the house, without having to put something like a POW inline.

On a side note, would be interested to see if anyone has tried monitoring Pin 51 when connected to the street-side of an importing/exporting meter (eg. solar PV), to see if it does in fact indicate when you are "feeding back" into the grid? Even the metering guys at work are unsure of what happens phase-wise when exporting to the grid.

rt400 commented 5 years ago

hi.. i hope that someone have news to use 3 phaze monitor in one WEMOS with TASMOTA.. i try but he recognize only ONE.. 2 3 here i config 2 monitor on different GPIO and still only one work....

rt400 commented 5 years ago

any news ??

0x3333 commented 5 years ago

Time is limited here. I'm testing several options, let you guys know when I progress.

rt400 commented 5 years ago

@0x3333 you are the best man... thank you.. hope it will allow us to use it

Jason2866 commented 5 years ago

@rt400 Tasmota can only handle one device of the same type. You cant configure it multiple on different GPIOs

andrethomas commented 5 years ago

I think the only logical way to do this is to offload the 3 sensors to a pro mini and read sensor values over I2C - Having 3 x PZEM004T connected at the same time in Tasmota is not possible.

I'm guessing since this thread has been hanging for 6 months the above is not likely to happen any time soon. This problem could have been solved with 3 wemos d1 mini's or 3 bare esp8266 boards and just report each phase independently - unless its actually being used to monitor a 3 phase device, having it all on seperate esp8266 modules would not make any difference - besisides, if you want to consolidate one one of the esp8266 modules you can always use knx to push data to that main one.

The latter will take less than 6 months ;)

ascillato commented 5 years ago

Hi

@0x3333

Do you have any progress in modifying the Tasmota PZEM driver? or you are fine with the workaround explained by @andrethomas ?

0x3333 commented 5 years ago

Well, using 3 tasmota devices is for sure the fastest option.

But I'm working on another solution, a custom board with Atmega 2560 reading up to 6 devices, 2 per UART(it has 4 uart, one is used to debug). But Im working in some side projects that are using my spare time. I can't give you a time frame.

Also a option is re-write the pzem library to be async, continuously reading the pzem devices and returning the lastest reading when asked. This would make the tasmota reading much faster, allowing multiple devices. But we should change the way it is today, to allow multiple devices per gpio or multiples gpios.

andrethomas commented 5 years ago

Yeah, it is not impossible to modify the driver to have 3 inputs but they would need to be 3 different names for the 3 separate RX pins - You do not need TX to be connected as you are only reading what the PZEM is spitting out.

I do not own any of these devices otherwise I would give it a go.

So basically you would ideally end up with something like this:

image

andrethomas commented 5 years ago

Possibly even make it possible to have more than 3 since there are still free GPIO's then people who want to monitor multiple single-phase measurements, from say inside the AC Tripswitch Box of the house...one for lights, one for plugs, one for geysers, one for outbuildings etc... So perhaps also keep this use case in the back of your mind when writing the code - to allow the individual use or 1or 2 x 3 phase use depending on configuration settings, of course.

0x3333 commented 5 years ago

@andrethomas nope. You must have TX. Pzem doesn't spit things, you must request.

andrethomas commented 5 years ago

Right, common TX then but the RX lines need to be separately handled - cannot be duplicates of the same handler.

roguestreak commented 5 years ago

Wasn't the idea (if not looking at simultaneous readings) that one RX/TX can be used for multiple PZEMs, you "just" need to configure them first (using a script?) to have an "address", and then the ESP can cycle through these addresses? I couldn't figure out the configuration bit, or find a script to do it. I think it could work if we dictate that you must use sequential addresses, then have a console setting to specify start address (eg. 10.0.0.1) and how many PZEMs (eg. 4, so addresses queried are 10.0.0.1, 10.0.0.2, 10.0.0.3, 10.0.0.4) Good for monitoring all circuits on a single-phase install.

asking23 commented 5 years ago

I have already implemented...3 Phase PZEM-004T using multiple Soft Serial TX RX in NodeMCU Amica. I am not sure that readings are synchronised...but they do work....

screenshot_2018-10-05-10-35-41-425_org openhab habdroid

0x3333 commented 5 years ago

@roguestreak yes, but using current drivers is not possible, it is sync and takes too much time waiting. I'm working in another solution, using async reading and synchronized reading.

rt400 commented 5 years ago

@Jason2866 i understant that.. i wonder if anyone can change the pzem004T driver that can handle 3 devices.. with simple arduino its work but i dont know how ...

rt400 commented 5 years ago

@0x3333 there is away to clone the driver 3 times? for 3 phaze ?

0x3333 commented 5 years ago

@rt400 yes, but I don't believe it will work, as it is sync and takes to much cpu...

0x3333 commented 5 years ago

Updated the repo. powermeter

Some feedback is great. This week will send to manufacture the boards.