PVOuput Uploader

This topic is a couple of years old, but still a great inspiration of how to upload data to PVOutput.

I’d like to share the way I implemented this so others can benefit from it.

To start off, I have this rest_command definition in my configuration.yaml file.

rest_command:
  upload_to_pvoutput:
    url: "{{ url }}"
    method: POST
    headers:
      X-Pvoutput-Apikey: !secret pvoutput_api_key
      X-Pvoutput-SystemId: !secret pvoutput_system_id
      Content-Type: application/x-www-form-urlencoded
    payload: "{{ payload }}"

Using the url and payload as variables allows me to fiddle around with the automation that will eventually send the data to PVOutput without reloading Home Assistant after every change.

📝Info Something that helped me tremendously with troubleshooting was using a mock API service such as Beeceptor. This allows you to set up an endpoint to intercept and analyze your REST API calls very easily.
Make sure to create a new rest_command definition that does not include your actual API key and system ID for better security. :grin:
Another tip is to always define a response_variable. Even if you don’t plan to implement any error handling this variable is shown in the automation trace which can be a great resource when troubleshooting.

Next up I use this automation to send the data to PVOutput.

alias: Upload PV data to PVoutput
description: ""
triggers:
  - minutes: /5
    trigger: time_pattern
conditions:
  - condition: template
    value_template: "{{ states('sensor.pv_power') != 'unavailable' }}"
    alias: If status sensor.pv_power is not unavailable
actions:
  - data:
      url: https://pvoutput.org/service/r2/addstatus.jsp
      payload: |-
        {{ ''.join([
          'd=' ~ now().strftime('%Y%m%d'),
          '&t=' ~ now().strftime('%H:%M'),
          '&v1=' ~ ((states('sensor.today_s_pv_generation') | float) * 1000),
          '&v2=' ~ states('sensor.pv_power'),
          '&v5=' ~ (state_attr('weather.forecast_thuis', 'temperature') | float)
        ]) }}
    action: rest_command.upload_to_pvoutput
    response_variable: pvoutput_response
    alias: >-
      Data is sent to PVOutput. The `join` function ensures no extra whitespace
      is added
mode: single

This automation sends data to PVOutput every 5 minutes. But only when my sensor for pv_power is available. My inverter shuts down in the evening, so it makes no sense sending data to PVOutput in that situation.

The way the payload is formatted is pretty important. I’ve seen people trying to keep their yaml readable by using a folded block scalar (>-) and putting each parameter on a new line. But this introduced unintended whitespace which causes issues with the PVOutput API. By using join you can mitigate this issue and keep your payload readable.

I hope this contribution will prevent people from having the issues I encountered and start using PVOutput straight away.

3 Likes