Help needed - ESPHome and uploading electrical use data to PVOutput dot org

Hi,

I’m looking for a bit of help with uploading power, voltage, current, frequency, etc from a PZEM004 v3 to PVOutput dot org. The best reference I can find is a similar post on this forum but there’s assumed knowledge I don’t yet have:

I’ve spent a couple of days on trial and error and am not having any luck unfortunately. There appear to be bits of code that go into the automations.yaml, and other bits that go into configuration.yaml, then there’s somewhere else that the shell commands are supposed to go. I think I’d prefer that the everything stayed in my own yaml file if that is practical and/or possible.

shell_command, to be run every 5 minutes:

   pvoutput_generation: 'curl -d "d={{now().strftime("%Y%m%d")}}" -d "t={{now().strftime("%H:%M")}}" -d "v2={{states.sensor.cs31011195_output_power.state|round(0)}}" -H "X-Pvoutput-Apikey: {{states.sensor.pvoutput_api_key.state}}" -H "X-Pvoutput-SystemId: {{states.sensor.pvoutput_system_id.state}}" https://pvoutput.org/service/r2/addstatus.jsp'

   pvoutput_consumption: 'curl -d "d={{now().strftime("%Y%m%d")}}" -d "t={{now().strftime("%H:%M")}}" -d "c1=1" -d "v3={{(states.sensor.energy_consumption_tariff_1.state|int)+(states.sensor.energy_consumption_tariff_2.state|int)}}" -H "X-Pvoutput-Apikey: {{states.sensor.pvoutput_api_key.state}}" -H "X-Pvoutput-SystemId: {{states.sensor.pvoutput_system_id.state}}" https://pvoutput.org/service/r2/addstatus.jsp'

Also looked here but not sure how to use it

My hardware:

Current state is that my NodeMCU hardware connects with 2 x PZEM004 V3. I’ve installed HomeAssistant on a Win10 Virtual box host, made an initial config and can upload over the air no problem. I have a web server on the NodeMCU which is working, and all data from PZEM004 is available directly from the webserver, and in the HomeAssistant Overview tab, along with time.

Another option for the PVOutput upload command, run every 5 minutes like this (thanks IanJohnston dot com)

http.begin("http://pvoutput.org/service/r2/addstatus.jsp?d="+dateString+"&t="+timeString+"&v7="+String(DataImportPwrPV,1)+"&v8="+String(DataExportPwrPV,1)+"&v2="+String(DataGenPwrPV,1)+"&v10="+String(DataGenPwrPV,1)+"&v9="+String(DataActualConsumptionPwrPV,1)+"&v6="+String(DataVoltagePV,1)+"&v5="+String(DataTemperaturePV,1)+"&v4="+String(DataConsumptionPwrPV,1)+"&key="+sid  +"&sid="+systemId); 

My yaml config is currently thus, all working except for PVOutput upload. I might want to add another two PZEMs in future totaling 4 channels, and also create a Grafana dashboard:


esphome:
  name: acpowermeter

esp8266:
  board: nodemcuv2

# Enable logging
logger:

# Enable Home Assistant API
api:

web_server:

ota:
  password: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

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

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

captive_portal:

time:
  - platform: sntp
    id: sntp_time

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

uart:
  - id: ua1
    rx_pin: D1
    tx_pin: D2
    baud_rate: 9600
    #stop_bits: 1
  - id: ua2
    rx_pin: D3
    tx_pin: D4
    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: 5s
    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: 5s
    modbus_id: mod2
    

text_sensor:
  - platform: template
    name: "Current time"
    lambda: |-
      char str[17];
      time_t currTime = id(sntp_time).now().timestamp;
      strftime(str, sizeof(str), "%Y-%m-%d %H:%M", localtime(&currTime));
      return  { str };
    update_interval: 5s

Apologies for the long post, it would be great if some knowledgeable person could find a few moments to give some guidance,

Thanks

Hi, I’ve been reading about this all day and feeling rather dumb that I’m not working it out.
I’m able to manually run ‘curl’ command from the terminal window of Home Assistant and the data appears in my PVOutput child system:
curl -d "data=20220105,15000" -H "X-Pvoutput-Apikey: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -H "X-Pvoutput-SystemId: xxxxx" https://pvoutput.org/service/r2/addoutput.jsp

I have the entities for the two pzem004 devices such as “sensor.pzem_004t_v3_power”.
Also time is there: “sensor.current_time”

The context is that I have 2 solar systems, an old one and a new one. The old one has been feeding data into PVOutput since 2014, the new one is much more capable but keeps it’s data within it’s ecosystem so I have built this PZEM004 NodeECU hardware system using CTs so that generation and consumption for the new system can be set free, sent into PVOutput, making use of their child/parent system and get an amalgamated view of both systems.

Trying MartijnBraam/pvoutput GitHub, it seems that there’s a ‘component’ entry that is required which is needed by ESPHome so I don’t think I can use that.

If I try to run the automation, I get an error “unable to find service shell_command.pvoutput.consumption”. I’ve put the scripts containing the curl commands all over the place and the automation can’t find them. Seems simple enough but I can’t make it work.

Ideally I think it makes sense to me if the PZEMs can be read every say 30 seconds and send that info to PVOutput. The curl would be a lambda or something in each of the modA and modB sections of my yaml

Can anyone suggest advice on how I can send the entity sensor.pzem.xxxx using curl to PVOutput API ? Please ?

I’ve installed Grafana and InfluxDB and have setup a few graphs, it looks good.

I’m still interested in doing the similar thing on PVOutPut, any guidance?

Why not use the http.begin() as you mentioned in the initial post?

Here is the answer: PVOuput Uploader - #26 by rieschard