How to connect pzem 017 DC with nodemcu

I tried that too, but it didn’t help the D1 mini connects but I don’t get the data. Do you also have a D1 mini or other board?
pzem

esphome:
  name: pzem017
  platform: ESP8266
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "7a8fhfg5h5hfh54be730a7"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Pzem017 Fallback Hotspot"
    password: "2fh5fhfh5cX4s"

captive_portal:




uart:
   tx_pin: 1
   rx_pin: 3
   baud_rate: 9600
   stop_bits: 2
   
   
   

sensor:
  - platform: pzemdc
    current:
      name: "FV-Proud"
      filters:
        - calibrate_linear:
          - 0.0 -> 0.0
          - 2.1 -> 0.9
    voltage:
      name: "FV-Napětí"
      accuracy_decimals: 2
    power:
      name: "FV-Příkon"
      filters:
        - calibrate_linear:
          - 0.0 -> 0.0
          - 60.1 -> 25.6
      id: my_power
    update_interval: 2s
    
  - platform: total_daily_energy
    name: "FV-Energie"
    filters:
      - multiply: 0.001
    unit_of_measurement: kWh
    power_id: my_power
    
time:
  - platform: sntp
    id: my_time

I use a nodemcu 8266, a larger board.
I sent a private message.

Same question, the energy value could be read in pzemac platform, not in dc … Could be implemented with reset function of course, in next release? thanks

Here I measure the energy (direct current) that comes into the battery.
solar energi

Ok bit it is calculated by esphome… I mean the value inside pzemdc and not read by integration. There is also a problem with current, it is double than real so I need to use filter multiply x 0.5

Finally I used modbus controller integration too in order to read just energy value and create a small action to send direct on serial port the 4 byte to reset enegy if I need.
Anyway the current value reported by pzemdc original integration is not true (double), I have no knowledge to modify the source code, but I hope somebody could do . Thanks.

Hi I know its been a while since your post, but did you get it working ??..I had the same problem and found that the cheap RS485 TTL boards do not have the 120ohm resistor across pins A and B connected. You can see it fitted to the board but its not connected on one side. Therefore put a 120ohm resistor between the A and B outs and it should all work, i also had a problem that the silk screen on the board has got Rx and Tx mixed up, to get over this just connect Rx on 485 board to Rx or your receive GPIO pin) on wemos d1 … same for Tx. ie 485 Tx to transmit pin on wemos D1 hope it helps.

Hello pepe59,

I have some trouble with PZEM-017 DC connection to my Wemos D1 mini. Please can you help me with this?

budis (CZ/EN)

Hi, did you actually measure the calibration constants between the real and measured value for PZEM 017 or are they taken from somewhere? Thanks

Ahoj, kalibračné konštanty medzi reálnou a meranou hodnotou pre PZEM 017 si reálne meral či sú odniekiaľ prevzaté? Dík

I can’t get it work either. I have exactly same connection as posted here How to connect pzem 017 DC with nodemcu - #12 by cristi2005

with configuration posted here How to connect pzem 017 DC with nodemcu - #38 by pepe59 (swapped D1 D2 with RX TX of course)

But there is no response from PZEM-017. :’( Any advice how to make it work please?

What RS485 to UART converter are you using?

When I set mine up, after a lot of trial and error and trying 3 RS485 to UART converters, I found that the problem was that the output of the converter was 5v but the ESP needed 3.3v.
A logic level converter between the RS485 and the ESP did the trick for me.

I am using a D1 Mini for what it’s worth.

Yaml if it helps:

esphome:
  name: battery-monitor
  platform: ESP8266
  board: d1_mini

# Enable logging
logger:
  baud_rate: 0
# Enable Home Assistant API
api:
  encryption:
    key: !secret encryption_key

ota:
  password: 

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Battery-Monitor Fallback Hotspot"
    password: "WEPjVSJ9JhBj"
  power_save_mode: none

captive_portal:

uart:
  tx_pin: D5
  rx_pin: D6
  baud_rate: 9600
  stop_bits: 2
  debug:
text_sensor:
  - platform: template
    name: Inverter Uptime Human Readable
    id: uptime_human
    icon: mdi:clock-start
sensor:
  - platform: pzemdc
    current:
      name: "Inverter-Battery Current"
    voltage:
      name: "Inverter-BatteryVoltage"
    power:
      name: "Inverter-Battery Power"
      id: inverter_power
    update_interval: 10s
  - platform: total_daily_energy
    name: "Inverter Power"
    filters:
      - multiply: 0.001
    unit_of_measurement: kWh
    power_id: inverter_power

  - platform: wifi_signal
    name: "Inverter WiFi Signal"
    update_interval: 60s
  - platform: uptime
    name: Inverter Uptime
    id: uptime_sensor
    update_interval: 60s
    on_raw_value:
      then:
        - text_sensor.template.publish:
            id: uptime_human
            state: !lambda |-
              int seconds = round(id(uptime_sensor).raw_state);
              int days = seconds / (24 * 3600);
              seconds = seconds % (24 * 3600);
              int hours = seconds / 3600;
              seconds = seconds % 3600;
              int minutes = seconds /  60;
              seconds = seconds % 60;
              return (
                (days ? to_string(days) + "d " : "") +
                (hours ? to_string(hours) + "h " : "") +
                (minutes ? to_string(minutes) + "m " : "") +
                (to_string(seconds) + "s")
              ).c_str();

time:
  - platform: homeassistant
    id: hass_time

Exactly this one from link provided by @cristi2005 : https://www.aliexpress.com/item/32385757602.html?spm=a2g0s.9042311.0.0.632f4c4d5hzPqu

All my connections are exactly the same as at the picture. I tried 3 different RS485 to UART converters. I tried literally everything … switching RX/TX, A/B, but still no data at serial port…
I have debug level VERY_VERBOSE and this is only message I got:

[07:27:06][V][modbus:199]: Modbus write: 01.04.00.00.00.08.F1.CC (8)

Thanks! :slight_smile: I’ll try add logic converter then. Could you please send me which one are you using?

Something like this will work.
https://www.aliexpress.com/item/1005001621749928.html

1 Like

Hi . a have a working sistem with pzem017 and wemos d1 mini on home assistant. works perfect!

Hi, I have very similar problem. My wiring is the same as provided by @cristi2005, only I use nodemcu esp8266 board. At the beginning I’ve checked my wiring on simple 12v adapter connected to some load and everything was OK. After I connected pzem-monitor to my working solar system just at the beginning I’ve also got data from pzem-017. But after restart of my nodemcu board, my system stopped to send data. Then I started to search for the problem, checked my wiring, debug modbus signal, but was not able to find anything what can cause this problem.
Then I disconnected the V+ (red) wire from my solar system which goes to pzem module and connected it again. And voilà my monitor started sending reliable data immediately.
Unfortunately after the night period, when solar production is 0 or after I shutting down my inverter, I getting the same problem with NAN or Unknown signal. Then again I need to physically reconnect the V+ wire to get normal signal from pzem-017. Has everyone similar experience or any thoughts what can it be?

thanks you alot

I am setting up the same 8266 nodemcu and having troubles with the code
Iam using a pemz 017 board… Do the changes go in the configuration,yaml ?
Can send me the code for it.

thanks

Hi all, I’ve been messing with the PZEM-017s for a while and have learned a few things I wanted to share, hopefully to make it easier for others just getting started, and maybe find some better solutions. I am by no means an expert, but I wanted to share what’s worked for me.

I’ve gotten the PZEM working using just a RS485 to UART converter. Originally I was also using the logic level shifter recommended here and elsewhere, but I’ve found that I don’t actually need it

I’m using an ESP-WROOM-32 and breakout, a RS485 to TTL converter, and PZEM-017 with 50A shunt.

I’ve also been having the double or half current reading issue, and at first I thought that this was caused by the 3.3-5V logic level shifter, (my flawed logic being that 3.3 is almost half of 5V) but after doing some more research I now believe it has to do with the size of the shunt you are using.

I bought mostly 50A kits, and one 100A kit. I finally realized after a lot of troubleshooting that if I use the 100A shunt, I get the correct reading without any filtering. But if I use one of my 50A shunts, the reading I get is double what it should be, and I have to apply a filter.

According to this thread on the tasmota forum, this is because the PZEM-017 comes factory set to a certain shunt size. I assumed that the 50A kits I bought would be set to match the shunt they ship with, but this doesn’t seem to be the case. All of the units I’ve gotten appear to be factory set to 100A.

Apparently there IS a way to send a command to the PZEM-017 to set the shunt size you are using so that you don’t have to apply filters in ESPhome, but doing this is currently beyond my understanding, and since the reading seems to be EXACTLY double the correct reading, I don’t see any real drawback to using a filter besides the fact that it feels hacky.

After I figured that out, these sensors work great, and I’m using them to monitor my solar in real time. Cutting out the level shifter simplified the wiring a lot, but you may still need one for some boards. The ESP-WROOM-32 and breakout work great though, and the converter slides neatly between the ESP and breakout board, which keeps things tidy.

If anyone is interested, I post monthly updates about what I’ve learned on my Patreon, and everything I post there is free and open for everyone, nothing is paywalled or Patrons-only. If you want more details on how I’m using these sensors, you can find them at Patreon[dot]com/disruptivelyuseful (this is my first post so I can only post 2 links)

If anyone knows how to send a command to the PZEM-017 to change the shunt setting, I’d love to know how to do it.

Also, do I even need the RS845 converter? I don’t really know what I’m doing, I just know that how I’m currently doing it works for me.

Hope that’s helpful to anyone, happy hacking!

1 Like