PRO: UBUNTU Server // Proxmox // SFML Daten pullen für z.B. externes Grafana :-)

SFML-Data-Extraction: HA-Sensordaten an externe InfluxDB pipelinen

Diese Anleitung beschreibt den Export von SFML-Daten (und prinzipiell jeglicher Entitäten) aus Home Assistant in eine externe InfluxDB-Instanz.

Disclaimer: Dies ist kein „Out-of-the-Box“-Add-on-Tutorial. Wir arbeiten hier auf Systemebene. Grundkenntnisse in Python, API-Handling und Datenbank-Strukturierung werden vorausgesetzt.

Die Infrastruktur (Referenz-Setup)

Um die Performance-Erwartungen einzuordnen: Das Setup läuft bei mir auf einer Synology DS1621+ (AMD Ryzen, 32GB RAM).

  • Storage-Layer: Dedizierter NVMe-Pool (2x M.2 im Stripe-Set) für maximale IOPS der VM-Disks.
  • Virtualisierung: Ubuntu Server (Headless). Hier laufen kritische Services wie MQTT, Paperless-ngx, eine Python-Dev-Umgebung sowie lokale LLMs.
  • Core: Home Assistant läuft dediziert auf separater Hardware.
  • Database Stack: InfluxDB (Docker-Container) & Grafana, vernetzt via Tailscale für sicheren Remote-Access.

Das Konzept ist agnostisch und lässt sich auf jede Linux-Umgebung (Proxmox, Bare-Metal, Docker-Stack) übertragen.

Schritt 1)

SFML muss installiert sein und korrekt konfiguriert… Du musst einen IinfluxDB Token haben + org + bucket (!!)

Schritt 2)
wir brauchen einen Konnektor :slight_smile:

pip3 install requests influxdb-client --break-system-packages

Schritt 3)
Nun erstellen wir einen langzeit Token in HA idealer Weise Name: influx kann aber auch bumbumboris heiße :slight_smile: den Token sicher speichern!

Schritt 4)
Mit Nano erstellen wir direkt auf dem Server den Code:

nano ~/ha_to_influxdb.py

Code:

(nicht vergessen die Senoren einzutragen, die gepullt werden sollen!

import requests
from influxdb_client import InfluxDBClient, Point
from influxdb_client.client.write_api import SYNCHRONOUS
from datetime import datetime

# Konfiguration
HA_URL = "http://DEINE_HA_IP:8123"
HA_TOKEN = "DEIN_HA_TOKEN"
INFLUX_URL = "http://DIE IP DEINES HA"
INFLUX_TOKEN = "DEIN_INFLUX_TOKEN"
INFLUX_ORG = "home"
INFLUX_BUCKET = "homeassistant"

# Sensoren die du erfassen willst
SENSORS = [
    "sensor.solar_forecast_ml_today",
    "sensor.solarbank_battery_level",
    # weitere Sensoren hier
]

headers = {
    "Authorization": f"Bearer {HA_TOKEN}",
    "Content-Type": "application/json"
}

client = InfluxDBClient(url=INFLUX_URL, token=INFLUX_TOKEN, org=INFLUX_ORG)
write_api = client.write_api(write_options=SYNCHRONOUS)

for sensor in SENSORS:
    try:
        r = requests.get(f"{HA_URL}/api/states/{sensor}", headers=headers)
        data = r.json()
        value = float(data["state"])
        point = Point(sensor).field("value", value).time(datetime.utcnow())
        write_api.write(bucket=INFLUX_BUCKET, record=point)
        print(f"✅ {sensor}: {value}")
    except Exception as e:
        print(f"❌ {sensor}: {e}")

client.close()

Beenden mit Ctrl+X → Y → Enter

Schritt 5:
testen ob der code läuft:

python3 ~/ha_to_influxdb.py

Ausgabe sollte sein:

zara@ubuntu-code-server:~$ python3 ~/ha_to_influxdb.py
2026-03-03 19:37:27 [INFO] 🚀 HA → InfluxDB Collector gestartet
2026-03-03 19:37:27 [INFO] 📡 Abfrage läuft...
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_prognose_heute: 6.39
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_prognose_heute_verbleibend: 0.0
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_prognose_morgen: 5.82
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_prognose_nachste_stunde: 0.0
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_prognose_ubermorgen: 5.71
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_max_peak_heute: 1380.0
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_max_peak_rekord: 1975.0
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_monatsertrag: 13.28
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_wochenertrag: 7.28
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_durchschnittlicher_monatsertrag: 6.64
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_o_ertrag_7_tage: 5.78714285714286
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_o_ertrag_30_tage: 2.31133333333333
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_yesterday_deviation: 0.39
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_performance_loss_today: 0.134
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_monatsverbrauch: 23.59
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_wochenverbrauch: 10.15
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_ai_rmse: 0.054
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_o_genauigkeit_30_tage: 64.2633333333333
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_physics_samples: 456
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_cloudiness_volatility: 95.1
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_shadow_today: 3.0
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml: warning
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_system_status: ok
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_coordinator_health: Healthy
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_active_prediction_model: AI-Hybrid
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_data_files_status: Connected
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_external_sensors_status: OK: 7/7 sensors
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_power_sensor_state: 0.0
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_yield_sensor_state: 7.35
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_last_update: 2026-03-03T19:20:04+00:00
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_last_ai_training: 2026-03-02T22:34:41+00:00
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_next_production_start: 2026-03-04T05:50:00+00:00
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_next_scheduled_update: 23:30 (End of Day)
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_beste_stunde: 12:00
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_cloudiness_trend_1h: stable
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_cloudiness_trend_3h: relatively_stable
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_shadow_current: no_data
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_produktionszeit_heute: 10:29:08
2026-03-03 19:37:27 [INFO] ✅ sensor.solar_forecast_ml_end_of_day_duration: 4:52 Min
2026-03-03 19:37:27 [INFO] 📊 Runde abgeschlossen: 39 ✅  0 ❌
2026-03-03 19:37:27 [INFO] 💤 Warte 15s...

Skript als Dienst einrichten:

sudo nano /etc/systemd/system/ha-collector.service
[Unit]
Description=HA to InfluxDB Collector
After=network.target

[Service]
User=zara
ExecStart=/usr/bin/python3 /home/zara/ha_to_influxdb.py
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

( Ctrl+X → Y → Enter) dann:

1:

sudo systemctl enable --now ha-collector

2:

sudo systemctl status ha-collector

sollte dann so aussehen:

zara@ubuntu-code-server:~$ sudo systemctl status ha-collector
● ha-collector.service - HA to InfluxDB Collector
     Loaded: loaded (/etc/systemd/system/ha-collector.service; enabled; preset: enabled)
     Active: active (running) since Tue 2026-03-03 19:42:28 UTC; 49s ago
   Main PID: 5805 (python3)
      Tasks: 1 (limit: 7007)
     Memory: 32.3M (peak: 33.3M)
        CPU: 1.748s
     CGroup: /system.slice/ha-collector.service
             └─5805 /usr/bin/python3 /home/zara/ha_to_influxdb.py

Mär 03 19:43:17 ubuntu-code-server python3[5805]: 2026-03-03 19:43:17 [INFO] ✅ sensor.solar_forecast_ml_next_productio>
Mär 03 19:43:17 ubuntu-code-server python3[5805]: 2026-03-03 19:43:17 [INFO] ✅ sensor.solar_forecast_ml_next_scheduled>
Mär 03 19:43:17 ubuntu-code-server python3[5805]: 2026-03-03 19:43:17 [INFO] ✅ sensor.solar_forecast_ml_beste_stunde: >
Mär 03 19:43:17 ubuntu-code-server python3[5805]: 2026-03-03 19:43:17 [INFO] ✅ sensor.solar_forecast_ml_cloudiness_tre>
Mär 03 19:43:17 ubuntu-code-server python3[5805]: 2026-03-03 19:43:17 [INFO] ✅ sensor.solar_forecast_ml_cloudiness_tre>
Mär 03 19:43:17 ubuntu-code-server python3[5805]: 2026-03-03 19:43:17 [INFO] ✅ sensor.solar_forecast_ml_shadow_current>
Mär 03 19:43:17 ubuntu-code-server python3[5805]: 2026-03-03 19:43:17 [INFO] ✅ sensor.solar_forecast_ml_produktionszei>
Mär 03 19:43:17 ubuntu-code-server python3[5805]: 2026-03-03 19:43:17 [INFO] ✅ sensor.solar_forecast_ml_end_of_day_dur>
Mär 03 19:43:17 ubuntu-code-server python3[5805]: 2026-03-03 19:43:17 [INFO] 📊 Runde abgeschlossen: 39 ✅  0 ❌
Mär 03 19:43:17 ubuntu-code-server python3[5805]: 2026-03-03 19:43:17 [INFO] 💤 Warte 15s...
lines 1-20/20 (END)

Nun pullt ihr direkt auf den Server → on the fly aus dem HA :slight_smile:

1 „Gefällt mir“