PVOuput Uploader

Hi Didier,
I am testing Home assistant for the first time and i am struggling trying to use the description you posted.
I input the portion sensor and shell_command into configuration.yaml . The API and system id into the file secret.yalm
Checking the file configuration.yaml system says it is OK …no errors… but how to run every 5 minutes the command to upload data to PVOUTPUT?
Would be very appreaciated a support from you.

many thanks in advance
Cheers

Finally I did it !! :grinning:
automation file was wrongly formatted.

Hi @ciottomate glad you figured it out already :slight_smile: I was on holiday and could not respond any sooner.

For those who come looking for the answer, create an automation rule that runs every 5 mins and runs the two shell scripts:

  alias: PVOutput Uploader
  description: Uploads values to PVOutput.
  trigger:
  - platform: time_pattern
    minutes: /5
  condition: []
  action:
  - service: shell_command.pvoutput_consumption
    data: {}
  - service: shell_command.pvoutput_generation
    data: {}
  mode: single
1 Like

Hi,

So I got the API working fine thanks to your posts above, however I’m a bit confused how I create a 5min average sensor to send to PVoutput.
I have a template sensor that calculates my instantaneous house consumption (removing solar generation):

      # Template sensor for values of power consumption (active_power < 0)
      energy_consumption:
        friendly_name: "Power Consumption"
        unit_of_measurement: 'W'
        value_template: >-
          {% if (states('sensor.house_consumption')|float - 685 - states('sensor.pv_power')|float - states('sensor.pv_power_2')|float) < 0 %}
            {{ (states('sensor.house_consumption')|float - 685 - states('sensor.pv_power')|float - states('sensor.pv_power_2')|float) * -1 }}
          {% else %}
            {{ (states('sensor.house_consumption')|float - 685 + states('sensor.pv_power')|float + states('sensor.pv_power_2')|float) }}
          {% endif %}

How do I turn that into a 5 min average to send up to Pvoutput.
You mentioned you had something with a timestamp or similar?

There doesn’t seem to be a average, only min-max median, confused.

Thanks for any bone you can throw me.

For anyone looking in the future, I think I figured it out using statistics:

sensor:
  # Sensor for 5 min average consumption for Pvoutput
  - platform: statistics
    name: "Energy Consumption 5min"
    entity_id: sensor.energy_consumption
    state_characteristic: mean
    max_age:
      minutes: 5
    sampling_size: 300
1 Like

That is a very smart solution!

In my case I simply upload the cumulative power amount, whereas you have the actual power (the difference is Wh vs W)

The following solution works in my setup, and does away with the secret problem. It uploads power and energy generation.

In configuration.yaml:


rest_command:
  pvoutput_generation:
    method: POST
    url: https://pvoutput.org/service/r2/addstatus.jsp
    headers:
      X-Pvoutput-Apikey: !secret pvoutput_api_key
      X-Pvoutput-SystemId: !secret pvoutput_system_id
    payload: 'd={{now().strftime("%Y%m%d")}}&t={{now().strftime("%H:%M")}}&v1={{states.sensor.growatt_energytoday.state|round(1)*1000}}&v2={{states.sensor.growatt_acpower.state|round(0)}}'
    content_type: "application/x-www-form-urlencoded"

In automations:


alias: PVOutput Uploader (rest_command)
description: Uploads values to PVOutput
trigger:
  - platform: time_pattern
    minutes: /5
    seconds: '0'
condition:
  - condition: state
    entity_id: sensor.growatt_status
    state: Normal
action:
  - service: rest_command.pvoutput_generation
    data: {}
mode: single

I am using the sensors described here : ESPHome modbus Growatt ShineWiFi-S

4 Likes

With recent modernization of the PVOutputPro integration, this should be fairly easy to add to the core integration as a service.

Will put it on my list to do, could use it myself as well (not as high priority though)

14 Likes

Awesome, thanks for that example. Based on that I’ve got a functioning configuration for a Fronius inverter. The config below uploads all the standard fields, including consumption, voltage, temperature etc. So if anyone else adapts this for there fronius choose which fields you want to upload, v1 and v3 are the essential ones I believe.

Note to deal with the ‘unknown’ state from a sensor in some circumstances the powerflow is set to default to 0, if it’s unable to be rounded.

rest_command:
  pvoutput_generation:
    method: POST
    url: https://pvoutput.org/service/r2/addstatus.jsp
    headers:
      X-Pvoutput-Apikey: !secret pvoutput_api_key
      X-Pvoutput-SystemId: !secret pvoutput_system_id
    payload: 'd={{now().strftime("%Y%m%d")}}&t={{now().strftime("%H:%M")}}&v1={{states.sensor.energy_total_fronius_inverter_1_http_192_168_xx_xx.state|round(0)}}&v2={{states.sensor.power_photovoltaics_fronius_power_flow_0_http_192_168_xx_xx.state|round(0,default=0)}}&v3={{states.sensor.energy_real_consumed_fronius_meter_0_http_192_168_xx_xx.state|round(0)}}&v4={{states.sensor.power_load_fronius_power_flow_0_http_192_168_xx_xx.state|round(0)*-1}}&v5={{states.sensor.outdoor_temperature|float}}&v6={{states.sensor.fronius_smartmeter_voltage_ac_phase_1.state|round(0)}}&c1=1'
    content_type: "application/x-www-form-urlencoded"

I think there’s a ‘}’ too many there?

Your correct, and yet strangely enough it was working perfectly fine and HA was happy with the configuration file…

^corrected.

Is this still working for people in 2022.6?

Ah turns out you need default values for all operations now, so float(0), round(0) etc…

Still works

This thread was very useful, but when I trigger this via an automation I get this error in the trace:
Stopped because an error was encountered at September 5, 2022 at 9:30:37 PM (runtime: 0.02 seconds)
’entity_id’

Any ideas on how to resolve this?
Using the rest_command

Can you post a snippet of your code? Seems you have an issue with entity_id

Edit, both rest and automation.

Thanks, I made some progress but did not get a result.

rest_command:
  pvoutputpro:
    url: https://pvoutput.org/service/r2/addoutput.jsp
    method: POST
    headers:
      X-Pvoutput-Ap:ikey: xxxxxxxxxxxxxxxxxxxxxxx"
      X-Pvoutput-SystemId: "yyyyy"
      accept: "application/json"
      user-agent: 'Mozilla/5.0 {{ useragent }}'
      payload: 'd={{now().strftime("%Y%m%d")}}&t={{now().strftime("%H:%M")}}&v1={{states.sensor.yield_energy_daily_wh.state|float(0)|round(0)}}&v2={{states.sensor.solar_power_c.state|float(0)|round(0)}}v3={{states.sensor.grid_consumption_energy_wh.state|float(0)|round(0)}}&v4={{states.sensor.load_power.state|float(0)|round(0)}}&v6={{states.sensor.solar_voltage_a|float(0)}}&c1=1'

      content_type: "application/x-www-form-urlencoded"

and the automation (which works)

- id: '1662376140100'
  alias: Pvoutput_trigger
  description: Posts data to pvoutput.org
  trigger:
  - platform: time_pattern
    minutes: /5
  condition: []
  action:
  - service: rest_command.pvoutputpro
    data: {}
  mode: single

Any help appreciated.

rest_command:
  pvoutputpro:
    url: https://pvoutput.org/service/r2/addoutput.jsp
    method: POST
    headers:
      X-Pvoutput-Ap:ikey: xxxxxxxxxxxxxxxxxxxxxxx" <<<< does this have a typo? should be  X-Pvoutput-Apikey:
      X-Pvoutput-SystemId: "yyyyy"
      accept: "application/json"
      user-agent: 'Mozilla/5.0 {{ useragent }}'     <<< I don't use this 
    payload: 'd={{now().strftime("%Y%m%d")}}&t={{now().strftime("%H:%M")}}&v1={{states.sensor.yield_energy_daily_wh.state|float(0)|round(0)}}&v2={{states.sensor.solar_power_c.state|float(0)|round(0)}}v3={{states.sensor.grid_consumption_energy_wh.state|float(0)|round(0)}}&v4={{states.sensor.load_power.state|float(0)|round(0)}}&v6={{states.sensor.solar_voltage_a|float(0)}}&c1=1'
    content_type: "application/x-www-form-urlencoded"

Your indents are out compared to mine, I edited yours above. I don’t use the accept line either(although I doubt that matters.)
You also have an extra : in the api key line.

"d={{now().strftime('%Y%m%d&t=%H:%M')}}&
I use that for the datetime

thats my whole payload line, although mine converts from kWh back to Wh

payload: "d={{now().strftime('%Y%m%d&t=%H:%M')}}&c1=3&v3={{states('sensor.powerpal_total_consumption')| float * 1000 }}&v4={{states('sensor.powerpal_live_consumption')| float * 1000 }}"
    

Might be worth checking your c1 flag too…

The following values are valid for the c1 flag.

  • 1 - Both v1 and v3 values are lifetime energy values. Consumption and generation energy is reset to 0 at the start of the day.
  • 2 - Only v1 generation is a lifetime energy value.
  • 3 - Only v3 consumption is a lifetime energy value.

pvo api spec

Thanks for the help and pointing out silly typos that must have crept in. Really appreciated.
I reworked my payload and checked the formatting on the developer tools/template page which was super helpful as I found one value with a trailing .state missing!

I had converted values to Wh in a template before the payload

This is the payload now.

    payload: 'd={{now().strftime("%Y%m%d&t=%H:%M")}}&v1={{states.sensor.yield_energy_wh.state|float(0)|round(0)}}&v2={{states.sensor.solar_power_c.state|float(0)|round(0)}}v3={{states.sensor.grid_consumption_energy_wh.state|float(0)|round(0)}}&v4={{states.sensor.load_power.state|float(0)|round(0)}}&v6={{states.sensor.solar_voltage_a.state|float(0)}}&c1=1'

I’m a bit worried pvoutput.org won’t like changing from 14 year old inverter totals to totals from a new energy meter.

Is there any way to see the returned status?
I’ll see what happens tomorrow during sunlight hours…

I can’t say I’ve figured out where to find the returned status for a rest post…

I get a returned status from SBFspot, that doesn’t really help you though.

It does take about 5 mins for PVo to update I find…

1 Like

Found it!

If you add this to configuration.yaml

logger:
  default: info
  logs:
    homeassistant.components.rest_command: debug     

It reports the reult in home-assistant.log (search for debug)

2022-09-15 22:20:01.359 DEBUG (MainThread) [homeassistant.components.rest_command] Success. Url: https://pvoutput.org/service/r2/addoutput.jsp. Status code: 200. Payload: b'd=20220915&t=22:20&v1=2021047&v2=0v3=1278895&v4=1181&v6=238.7&c1=1'

So the 200 Sucess status confirms the data is gettig to pvoutput.org :rofl:

1 Like