esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 34 forks source link

2 pzem's on different pins (and therefore different UART Busses) #1896

Closed bjornstevens closed 3 years ago

bjornstevens commented 3 years ago

Operating environment/Installation (Hass.io/Docker/pip/etc.):

ESP (ESP32/ESP8266, Board/Sonoff):

ESP8266, nodemcu amica

ESPHome version (latest production, beta, dev branch)

Affected component:

pzemac

Description of problem:

I can't seem to figure out how to get my 2 pzem-004T's to get read by esphome. The issue seems to rely on that i can't define the 'uart_id' in the pzemac configuration. Is there any workaround for this?

As of now I can only select 1 of the 2 "ua's". Which makes it only possible for me to read out 1 sensor, while I would really love to read out both of them

Problem-relevant YAML-configuration entries:


modbus:
    - uart_id: ua1

uart:
  - id: ua1
    tx_pin: D1
    rx_pin: D2
    baud_rate: 9600
    #stop_bits: 1
  - id: ua2
    tx_pin: D5
    rx_pin: D6
    baud_rate: 9600
    #stop_bits: 1

sensor:
  - platform: pzemac
    current:
      name: "PZEM-004T V3 Current"
    voltage:
      name: "PZEM-004T V3 Voltage"
    energy:
      name: "PZEM-004T V3 Energy"
    power:
      name: "PZEM-004T V3 Power"
    frequency:
      name: "PZEM-004T V3 Frequency"
    power_factor:
      name: "PZEM-004T V3 Power Factor"
    update_interval: 1s
    address: 1
  - platform: pzemac
    current:
      name: "PZEM-004T_2 V3 Current"
    voltage:
      name: "PZEM-004T_2 V3 Voltage"
    energy:
      name: "PZEM-004T_2 V3 Energy"
    power:
      name: "PZEM-004T_2 V3 Power"
    frequency:
      name: "PZEM-004T_2 V3 Frequency"
    power_factor:
      name: "PZEM-004T_2 V3 Power Factor"
    update_interval: 1s
    address: 2

Logs (if applicable):

PASTE DEBUG LOG HERE

Additional information and things you've tried:

I tried playing with the addresses, changing out the modbus to something else (and also can't get it to use different connections) I also tried to change things in the uart, but also without succes. I can only get it to pick 1 of the 2 connections, while i want both.

glmnet commented 3 years ago

Che k if you can give an ID to modbus then add modbus_id for each sensor. I know it's not documented but it's how usually works

bjornstevens commented 3 years ago

Thanks, that was the exact piece I was missing!

Config now is as follows:


    - id: mod1
      uart_id: ua1
    - id: mod2
      uart_id: ua2

uart:
  - id: ua1
    tx_pin: D1
    rx_pin: D2
    baud_rate: 9600
    #stop_bits: 1
  - id: ua2
    tx_pin: D5
    rx_pin: D6
    baud_rate: 9600
    #stop_bits: 1

sensor:
  - platform: pzemac
    current:
      name: "PZEM-004T V3 Current"
    voltage:
      name: "PZEM-004T V3 Voltage"
    energy:
      name: "PZEM-004T V3 Energy"
    power:
      name: "PZEM-004T V3 Power"
    frequency:
      name: "PZEM-004T V3 Frequency"
    power_factor:
      name: "PZEM-004T V3 Power Factor"
    update_interval: 1s
    modbus_id: mod1
  - platform: pzemac
    current:
      name: "PZEM-004T_2 V3 Current"
    voltage:
      name: "PZEM-004T_2 V3 Voltage"
    energy:
      name: "PZEM-004T_2 V3 Energy"
    power:
      name: "PZEM-004T_2 V3 Power"
    frequency:
      name: "PZEM-004T_2 V3 Frequency"
    power_factor:
      name: "PZEM-004T_2 V3 Power Factor"
    update_interval: 1s
    modbus_id: mod2
bjornstevens commented 3 years ago

Maybe an extra: but is there a way to sync the requests? Like sync update_interval?

bjornstevens commented 3 years ago

Allright, so now comes the new issue: afbeelding

Somtimes when the 2 pzem's are synced up, I receive this message. Is there a way to correct this (like putting an request delay of around 100 miliseconds between the scans)?

glmnet commented 3 years ago

Start by setting uptade interval to never, to the second pzem

Then you'll need to trigger it manually. Use this action: https://esphome.io/guides/automations.html#component-update-action

You can add an on_value trigger to any sensor of first pzem

bjornstevens commented 3 years ago

Thanks for the reply, it was also exactly what I was looking for! Thanks!

I've now just given my pzemac's ID's and added this:

interval:
  - interval: 5s
    then:
       - lambda: 'id(pzemac1).update();'
       - delay: 50ms
       - lambda: 'id(pzemac2).update();'
bjornstevens commented 3 years ago

I will close this case for now due to my problem being fixed. Thanks for the help @glmnet !