Setting up Home Assistant to upload to PVOutput
I learnt about PVOutput via Mastodon. @solar@botsin.space was publishing their statistics and they had east, west panels like me. Turns out those statistics came via PVOutput.
If you like statistics you will love this site. PVOutput.org is a free service for sharing, comparing and monitoring live solar photovoltaic (PV) and energy consumption data. It can be very useful for comparing other solar setups in your area or orientations. This is my PVOutput - My site ID is 97627
Some vendors can automatically upload to PVOutput. Unfortunately LuxPowerTek does not have this functionality. Home Assistant has all the data I need to upload so this should be easy, or so I thought.
I found the YAML below via this link
rest_command:
update_pvoutput:
url: https://pvoutput.org/service/r2/addstatus.jsp
method: post
content_type: "application/x-www-form-urlencoded"
headers:
X-Pvoutput-Apikey:
X-Pvoutput-SystemId:
payload: >-
d={{now().strftime("%Y%m%d")}}
&t={{now().strftime("%H:%M")}}
&c1=2
&v1={{(states('sensor.lux_solar_output_daily')|float * 1000)|round(0) }}
&v7={{(states('sensor.lux_solar_output_array_1_live')|float * 1000)|round(0) }}
&v8={{(states('sensor.lux_solar_output_array_2_live')|float * 1000)|round(0) }}
Unfortunately it didn’t work completely. It only sent the last extended value in the YAML. I thought this would be an easy fix, but it took some working out. The LuxPowerTek GitHub group were a great help. I added the code below to the configuration.yaml to help with the issue.
logger:
default: info
logs:
homeassistant.components.rest_command: debug
In the Home Assistant log I had this entry
2023-03-20 21:05:01.151 DEBUG (MainThread) [homeassistant.components.rest_command] Success. Url: https://pvoutput.org/service/r2/addstatus.jsp. Status code: 200. Payload: b'd=20230320 &t=21:05 &v2=0 &v4=637 &v5=10 &v7=0 &v8=0'
I had a feeling the issue was due to the spaces between the & and the next v. In the end this is the working YAML. It goes in the configuration.yaml. The payload is one long line.
rest_command:
update_pvoutput:
url: https://pvoutput.org/service/r2/addstatus.jsp
method: post
content_type: "application/x-www-form-urlencoded"
headers:
X-Pvoutput-Apikey: !secret pvoutout-api
X-Pvoutput-SystemId: !secret pvoutput-site
payload: "d={{now().strftime('%Y%m%d')}}&t={{now().strftime('%H:%M')}}&v2={{(states('sensor.lux_solar_output_live'))|round(0)}}&v4={{(states('sensor.lux_home_consumption_live'))|round(0)}}&v5={{(states('sensor.met_office_buntingford_temperature_3_hourly'))|round(0)}}&v8={{(states('sensor.lux_solar_output_array_2_live'))|round(0)}}&v6={{(states('sensor.lux_grid_voltage_live'))|round(0)}}&v7={{(states('sensor.lux_solar_output_array_1_live'))|round(0)}}&v9={{(states('sensor.lux_battery'))|round(0)}}&v10={{(states('sensor.lux_battery_charge_live'))|round(0)}}&v11={{(states('sensor.lux_battery_discharge_live'))|round(0)}}&v12={{(states('sensor.lux_power_to_grid_live'))|round(0)}}"
You now need an Automation to call this code every 5 minutes.
alias: Upload to PVOuput
description: Upload to PVOuput
trigger:
- platform: time_pattern
minutes: /5
action:
- service: rest_command.update_pvoutput
data: {}
mode: single
The extended values have to be setup in PVOutput. This my configuration.
Here are some example pages from my site