SolarCost bridge para capturar Totales de Solar Assistant y publicarlos por HTTP.
Project description
SolarCost Bridge
Bridge en Python para:
- autenticarse contra SolarAssistant,
- conectarse al websocket de Phoenix LiveView de la solapa
Totales, - mantener un estado actualizado y persistido,
- publicar ese estado por HTTP para que otra aplicacion lo consulte.
Estructura
src/sa_totals_bridge: codigo fuenterequirements.txt: dependenciasdata/: base SQLite local generada en ejecucion
Instalacion
sudo apt update
sudo apt install -y python3-full python3-venv
mkdir -p /opt/solarcost/bridge
cd /opt/solarcost/bridge
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install solarcost-bridge
sudo "$(command -v sa_bridge)" init
El comando recomendado es sa_bridge. Los comandos anteriores sa-bridge y sa-totals-bridge siguen funcionando por compatibilidad.
Si prefieres mantener el comando anterior, tambien funciona:
sudo "$(command -v sa-totals-bridge)" init
Si Solar Assistant corre en la misma maquina que el bridge, el asistente propone por defecto http://127.0.0.1.
Desinstalacion
pip uninstall solo elimina el paquete instalado dentro del entorno virtual. No borra automaticamente:
- el archivo
solarcost-bridge.env, - la base SQLite,
- el directorio de trabajo,
- los unit files de
systemd, - ni los servicios habilitados.
Eso es intencional para no perder configuracion o datos sin querer.
Si quieres una desinstalacion conservando configuracion:
source .venv/bin/activate
pip uninstall solarcost-bridge
O con el asistente interactivo:
sa_bridge uninstall
Si quieres tocar un servicio system, usa:
sudo "$(command -v sa_bridge)" uninstall
Si instalaste desde el repo, tambien puedes usar:
./uninstall.sh
Si quieres una desinstalacion limpia completa:
sudo systemctl stop solarcost-bridge.service
sudo systemctl disable solarcost-bridge.service
sudo rm -f /etc/systemd/system/solarcost-bridge.service
sudo systemctl daemon-reload
rm -f /ruta/a/solarcost-bridge.env
rm -f /ruta/a/data/solar_assistant_totals.sqlite3
rm -rf /ruta/al/directorio/de/trabajo
Despliegue rapido en Raspberry Pi
- Clona el repo en la Pi.
- Entra a la carpeta del proyecto.
- Ejecuta
./init.sh. - Responde el asistente interactivo.
- Si elegiste
systemouser, el script deja generado el service y puede habilitarlo automaticamente.
Ejemplo:
git clone https://github.com/gteijeiro/solarcost-bridge.git
cd solarcost-bridge
./init.sh
Para ver logs del servicio:
sudo journalctl -u solarcost-bridge.service -f
Ejecucion
export SA_BASE_URL="http://SOLAR_ASSISTANT_HOST_O_IP"
export SA_PASSWORD="TU_PASSWORD_DE_SOLAR_ASSISTANT"
sa_bridge
Tambien puedes usar el subcomando explicito:
sa_bridge run
La API queda por defecto en:
http://127.0.0.1:8765http://<tu-ip-local>:8765
Como funciona la actualizacion
- El bridge abre una sesion autenticada contra Solar Assistant.
- Luego abre un websocket de Phoenix LiveView hacia la solapa
Totales. - La API HTTP del bridge no abre un websocket por cada request.
- Cada request a la API solo devuelve el ultimo snapshot guardado en memoria y SQLite.
SA_HEARTBEAT_INTERVALmantiene viva la conexion websocket.SA_REFRESH_INTERVALfuerza una resincronizacion periodica del periodo actual porque la vistaTotalesno siempre emite cambios nuevos por si sola.
En otras palabras:
heartbeatno trae datos nuevos, solo evita que la conexion muera.refreshvuelve a abrir la sesion del collector y refresca los valores actuales.
Por defecto el bridge:
- manda heartbeat cada
30segundos, - fuerza resincronizacion cada
10segundos, - hace backfill historico una vez al arrancar el collector,
- despues mantiene el historial ya guardado y solo refresca el periodo actual.
Si quieres menos carga en la Pi o en Solar Assistant:
export SA_DAILY_HISTORY_PERIODS="6"
export SA_MONTHLY_HISTORY_PERIODS="3"
export SA_REFRESH_INTERVAL="20"
Si quieres desactivar la resincronizacion forzada y dejar solo el websocket:
export SA_REFRESH_INTERVAL="0"
Endpoints
GET /healthGET /stateGET /totals/dailyGET /totals/daily/pointsGET /totals/monthlyGET /totals/monthly/pointsGET /openapi.jsonGET /docs
Los endpoints de points devuelven una sola lista concatenada de todos los periodos cargados. Si necesitas un periodo puntual, puedes usar ?period_key=....
Variables disponibles
SA_BASE_URLSA_PASSWORDSA_BIND_HOSTSA_BIND_PORTSA_DB_PATHSA_LOG_LEVELSA_RECONNECT_DELAYSA_HEARTBEAT_INTERVALSA_REFRESH_INTERVALSA_CONNECT_TIMEOUTSA_DAILY_HISTORY_PERIODSSA_MONTHLY_HISTORY_PERIODS
Diagnostico rapido
Para saber si el bridge esta trayendo datos recientes, revisa:
GET /healthGET /state
Campos utiles:
service.connectedservice.last_login_atservice.last_join_atservice.last_message_atservice.last_errordaily.updated_atmonthly.updated_at
Si connected=true pero last_message_at o daily.updated_at quedan viejos durante mucho tiempo, normalmente significa que Solar Assistant no esta empujando diffs nuevos y dependes del SA_REFRESH_INTERVAL.
Recomendacion de seguridad
- No guardes
SA_PASSWORDen archivos versionados. - No subas la base
data/solar_assistant_totals.sqlite3a GitHub. - Si usas
.env, mantenlo fuera del repositorio.
Notas
- El collector hace una busqueda hacia atras con
prev-dailyyprev-monthly, y luego vuelve al periodo actual connext-dailyynext-monthly. - Por defecto intenta traer
12periodos diarios anteriores y5periodos mensuales anteriores. - Swagger UI esta en
/docsy carga assets desde CDN.
Build y publicacion
Build local:
python -m pip install --upgrade build
python -m build
El repo incluye workflows de GitHub Actions para:
- CI en
pushypull_request, - publicacion manual a TestPyPI con
workflow_dispatch, - publicacion a PyPI al crear un tag
v*.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file solarcost_bridge-0.1.1.tar.gz.
File metadata
- Download URL: solarcost_bridge-0.1.1.tar.gz
- Upload date:
- Size: 26.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3d92bf97f8420c112b9f30c479416018468a74c9b60e615971ba6e1f7a9439f
|
|
| MD5 |
19a72664a814f1f7809c481de8dd40bc
|
|
| BLAKE2b-256 |
aece0723a9382ab862cb942c1ee3168e1012e3a32e9cdd0623ca8e94077b1453
|
Provenance
The following attestation bundles were made for solarcost_bridge-0.1.1.tar.gz:
Publisher:
publish.yml on gteijeiro/solarcost-bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
solarcost_bridge-0.1.1.tar.gz -
Subject digest:
c3d92bf97f8420c112b9f30c479416018468a74c9b60e615971ba6e1f7a9439f - Sigstore transparency entry: 1319264983
- Sigstore integration time:
-
Permalink:
gteijeiro/solarcost-bridge@a39b1ffde548df7ea85896f7009f81c4b48433e4 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/gteijeiro
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a39b1ffde548df7ea85896f7009f81c4b48433e4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file solarcost_bridge-0.1.1-py3-none-any.whl.
File metadata
- Download URL: solarcost_bridge-0.1.1-py3-none-any.whl
- Upload date:
- Size: 27.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d527868ac37f1b0d7a1f40b6e0990fe34c80e5b9d86212d398edfea39405402a
|
|
| MD5 |
89623c451fe49bc7ac717f5eb4bc751b
|
|
| BLAKE2b-256 |
9a6dd7ccc2ac0fb0477ed917289196c319bc80c24fa507e631012f79b3fce49c
|
Provenance
The following attestation bundles were made for solarcost_bridge-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on gteijeiro/solarcost-bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
solarcost_bridge-0.1.1-py3-none-any.whl -
Subject digest:
d527868ac37f1b0d7a1f40b6e0990fe34c80e5b9d86212d398edfea39405402a - Sigstore transparency entry: 1319265075
- Sigstore integration time:
-
Permalink:
gteijeiro/solarcost-bridge@a39b1ffde548df7ea85896f7009f81c4b48433e4 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/gteijeiro
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a39b1ffde548df7ea85896f7009f81c4b48433e4 -
Trigger Event:
push
-
Statement type: