sense_api_pvoutput.py (1.2 KB)
Updated script with changes that work with latest Sense API Python and small other changes.
import sys, subprocess
from datetime import datetime, date, time
from sense_energy 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 = ‘user’
password = ‘pass’
PVOutputURL = ‘https://pvoutput.org/service/r2/addstatus.jsp’
PVOutputAPI = ‘PVAPI’
PVOutputSID = ‘PVSID’
sense = Senseable(wss_timeout=30,api_timeout=30)
sense.authenticate(username, password)
sense.update_realtime()
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)
if active_solar_power < “0”:
active_solar_power = “0”
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()