PVOutput.org Push


#1

Leveraging ScottBOnline’s senseapi python at https://github.com/scottbonline/sense

I use a weather module and then something i wrote to push the data collected to PVoutput.org

sense_api_pvoutput.py (1.1 KB)
weather.py (864 Bytes)


#2
import sys, subprocess
from datetime import datetime, date, time
from sense_api import Senseable
from weather import current_temp, min_temp, max_temp, forecast_text

DATE = datetime.now().strftime("%Y%m%d")
TIME = datetime.now().strftime("%H:%M")
username = 'email'
password = 'pass'
PVOutputURL = 'https://pvoutput.org/service/r2/addstatus.jsp'
PVOutputAPI = '83587u834jk'
PVOutputSID = '3543'

sense = Senseable(username,password)
active_power = str(sense.active_power).split('.')[0]
active_solar_power = str(sense.active_solar_power).split('.')[0]
active_voltage_split = str(sense.active_voltage).split(' ')[0]
active_voltage_strip = str(active_voltage_split).strip('[ ,')
active_voltage = active_voltage_strip[:5]
temp = round(float(current_temp),1)

PVOutputCURL = """curl -d "d={}" -d "t={}" -d "v4={}" -d "v2={}" -d "v5={}" -d "v6={}" -H "X-Pvoutput-APIkey:{}" -H "X-Pvoutput-SystemId:{}" {}""".format(DATE, TIME, active_power, active_solar_power, temp, active_voltage,PVOutputAPI, PVOutputSID, PVOutputURL)

subprocess.call(PVOutputCURL, shell=True)
print()

#3

I’m doing the same thing but with home-assistant.io (and the same python):
rest_command:
pvoutput_status:
url: ‘https://pvoutput.org/service/r2/addstatus.jsp
headers:
X-Pvoutput-Apikey:
X-Pvoutput-SystemId:
method: post
content_type: application/x-www-form-urlencoded
payload: “d={{now().strftime(’%Y%m%d&t=%H:%M’)}}&v2={{states.sensor.energy_production_stats_mean.state|int}}&v4={{states.sensor.energy_usage_stats_mean.state|int}}&v5={{(states.sensor.pws_temp_f_stats_mean.state|float - 32)/1.8}}&v6={{states.sensor.
dehumidifier_voltage.state|float * 2}}”

cron as an automation is left as an exercise to the reader. I created a bunch of mean stats sensors to capture the 5-minutely data pvoutput wants.


#4

Just a note - the API should not be used this way.

Rather than call the authentication every time:
sense = Senseable(username,password)

Instead, call it once, then have a loop that uses the existing instance to get the latest information.


#5

im only running the call once every 5 mins… how long does the key last? we can change the logic to use the key for x amount of time and then rekey after x time.


#6

From what I’ve seen, it never expires. I’ve been using it in a homeassistant component that initializes only once and then reports data until the server is restarted


#7

ok… ill do that and see how long it lasts… like your HA setup


#8

AFAIK the key never expires. I’ve been using the same one for over a month.


#9

What Home Assistant component is that?


#10

This one maybe?


#11

I have that one enabled but I was wondering if there was another component you can use to record the data better…


#12

Home Assistant will log the data automatically if you set up a sensor. You could also pass the data to another component in HA if you needed.