influxdb
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| influxdb [2022/11/08 21:52] – lars | influxdb [2025/11/15 23:12] (current) – [Zaehlerständeim Haus] lars | ||
|---|---|---|---|
| Line 28: | Line 28: | ||
| Der Verbrauch kann auf [[https:// | Der Verbrauch kann auf [[https:// | ||
| Das Format ist so beschrieben: | Das Format ist so beschrieben: | ||
| - | <WRAP center round box 60%> | + | <WRAP center round box 85%> |
| **Betankungen CSV-Export** \\ | **Betankungen CSV-Export** \\ | ||
| Auf dieser Seite können Sie die Betankungsdaten Ihres Fahrzeugs exportieren. | Auf dieser Seite können Sie die Betankungsdaten Ihres Fahrzeugs exportieren. | ||
| Line 45: | Line 45: | ||
| </ | </ | ||
| + | ==== Zaehlerständeim Haus ==== | ||
| + | === Import aus ECAS === | ||
| + | Bis 2025 hat Lars die Zählerstände in einer App Namens ECAS auf seinem Handy erfasst. | ||
| + | Die ist aber nicht länger im PlayStore zu bekommen. | ||
| + | Man kann in der App die Daten exportieren, | ||
| + | Der letzte Stand ist hier zu finden: {{ : | ||
| + | Die Daten aus der Datenbank habe ich per Script nach InfluxDB überführt. | ||
| + | Das Script hat ChatGPT für mich geschrieben. | ||
| + | <code bash> | ||
| + | sqlite3 ./ | ||
| + | " | ||
| + | | tail -n +2 \ | ||
| + | | awk -F',' | ||
| + | function map_meter(id, | ||
| + | if (id == 1) return " | ||
| + | if (id == 2) return " | ||
| + | if (id == 3) { | ||
| + | swap_time = " | ||
| + | if (datetime >= swap_time) return " | ||
| + | else return " | ||
| + | } | ||
| + | return " | ||
| + | } | ||
| + | function map_unit(id) { | ||
| + | if (id == 1) return " | ||
| + | if (id == 2) return " | ||
| + | if (id == 3) return " | ||
| + | return " | ||
| + | } | ||
| + | function to_ns(datetime) { | ||
| + | cmd = "date -d \"" | ||
| + | cmd | getline seconds | ||
| + | close(cmd) | ||
| + | return seconds " | ||
| + | } | ||
| + | { | ||
| + | meter = map_meter($1, | ||
| + | unit = map_unit($1); | ||
| + | ts_ns = to_ns($2); | ||
| + | value = $3; | ||
| + | comment = $4; | ||
| + | |||
| + | # SQLite liefert "" | ||
| + | if (comment == " | ||
| + | |||
| + | # Zeile mit oder ohne Bemerkung | ||
| + | if (comment != "" | ||
| + | printf(" | ||
| + | } else { | ||
| + | printf(" | ||
| + | } | ||
| + | |||
| + | # Gas (ursprünglich meterid=2) zusätzlich kWh | ||
| + | if ($1 == 2) { | ||
| + | kwh = value * 9.76608; | ||
| + | if (comment != "" | ||
| + | printf(" | ||
| + | } else { | ||
| + | printf(" | ||
| + | } | ||
| + | } | ||
| + | }' | ||
| + | </ | ||
| + | Diverse Besonderheiten werden darin bearbeitet wie etwa die Umrechnung der eingelesenen Gaszaehlerwerte in m³ in kWh (x9,76608) oder der Austausch des Wasserzaehlers am 27.05.2021. | ||
| + | |||
| + | Die Übertragung von ECAS nach InfluxDB hat am 15.11.2025 stattgefunden. | ||
| + | |||
| + | === Eingabe via Webseite === | ||
| + | |||
| + | Mit ChatGPT und einiger eigener Arbeit ist diese PHP-Seite herausgekommen, | ||
| + | Damit kann ich neue Werte aufnehmen. | ||
| + | <code php> | ||
| + | <?php | ||
| + | ?> | ||
| + | < | ||
| + | <html lang=" | ||
| + | < | ||
| + | <meta charset=" | ||
| + | < | ||
| + | < | ||
| + | body { font-family: | ||
| + | h1 { text-align: center; } | ||
| + | form { max-width: 420px; margin: auto; background: white; padding: 2rem; border-radius: | ||
| + | input, select, button { padding: 0.7rem; font-size: 1rem; border: 1px solid #ccc; border-radius: | ||
| + | button { background: #007bff; border: none; color: white; cursor: pointer; transition: background 0.2s; } | ||
| + | button: | ||
| + | .info { text-align: center; color: #555; margin-bottom: | ||
| + | .success { color: green; text-align: center; } | ||
| + | .error { color: red; text-align: center; } | ||
| + | </ | ||
| + | </ | ||
| + | < | ||
| + | < | ||
| + | <?php | ||
| + | // --- CONFIG --- | ||
| + | $influx_url = " | ||
| + | $org = " | ||
| + | $bucket = " | ||
| + | $token = " | ||
| + | |||
| + | function query_influx_selected() { | ||
| + | global $influx_url, | ||
| + | $zaehler_list = [' | ||
| + | $results = []; | ||
| + | |||
| + | foreach ($zaehler_list as $z) { | ||
| + | $flux = <<< | ||
| + | from(bucket: | ||
| + | |> range(start: | ||
| + | |> filter(fn: (r) => r._measurement == " | ||
| + | |> filter(fn: (r) => r[" | ||
| + | FLUX; | ||
| + | |||
| + | // Gas: nur Einträge ohne Einheit kWh | ||
| + | if ($z === ' | ||
| + | $flux .= " | ||
| + | } | ||
| + | |||
| + | $flux .= " | ||
| + | $flux .= " | ||
| + | $flux .= " | ||
| + | |||
| + | $curl = curl_init(); | ||
| + | curl_setopt_array($curl, | ||
| + | CURLOPT_URL => " | ||
| + | CURLOPT_RETURNTRANSFER => true, | ||
| + | CURLOPT_POST => true, | ||
| + | CURLOPT_HTTPHEADER => [ | ||
| + | " | ||
| + | " | ||
| + | ], | ||
| + | CURLOPT_POSTFIELDS => $flux | ||
| + | ]); | ||
| + | /* | ||
| + | print "< | ||
| + | | ||
| + | print " ?> -->"; | ||
| + | print PHP_EOL; | ||
| + | */ | ||
| + | |||
| + | $resp = curl_exec($curl); | ||
| + | curl_close($curl); | ||
| + | |||
| + | $results[$z] = null; | ||
| + | $lines = explode(" | ||
| + | foreach ($lines as $line) { | ||
| + | /* | ||
| + | print "< | ||
| + | print $line; | ||
| + | print " ?> -->"; | ||
| + | print PHP_EOL; | ||
| + | */ | ||
| + | if (strpos($line, | ||
| + | $parts = str_getcsv($line, | ||
| + | /* | ||
| + | print "< | ||
| + | print count($parts); | ||
| + | print implode(" | ||
| + | print " ?> -->"; | ||
| + | print PHP_EOL; | ||
| + | */ | ||
| + | if (count($parts) < 6) continue; | ||
| + | /* | ||
| + | print "< | ||
| + | print " | ||
| + | print "time: $parts[3] "; | ||
| + | print " ?> -->"; | ||
| + | print PHP_EOL; | ||
| + | */ | ||
| + | $value = $parts[4] ?? null; | ||
| + | $time = $parts[3] ?? null; | ||
| + | if ($value !== null) { | ||
| + | $results[$z] = [' | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | return $results; | ||
| + | } | ||
| + | |||
| + | $latest_selected = query_influx_selected(); | ||
| + | ?> | ||
| + | <!-- Letzte Werte aus InfluxDB --> | ||
| + | <?php foreach ($latest_selected as $k => $v): ?> | ||
| + | <!-- <?= $k ?>: <?= $v ? $v[' | ||
| + | <?php endforeach; ?> | ||
| + | <div class=" | ||
| + | <form method=" | ||
| + | < | ||
| + | <select name=" | ||
| + | <option value=" | ||
| + | <option value=" | ||
| + | <option value=" | ||
| + | </ | ||
| + | </ | ||
| + | < | ||
| + | <input type=" | ||
| + | </ | ||
| + | < | ||
| + | <input type=" | ||
| + | </ | ||
| + | < | ||
| + | <input type=" | ||
| + | </ | ||
| + | <button type=" | ||
| + | </ | ||
| + | < | ||
| + | const latestAll = <?= json_encode($latest_selected) ?>; | ||
| + | const latestInfo = document.getElementById(' | ||
| + | const zaehlerSelect = document.getElementById(' | ||
| + | function updateLatest() { | ||
| + | const selected = zaehlerSelect.value; | ||
| + | const data = latestAll[selected]; | ||
| + | if (data) { | ||
| + | latestInfo.textContent = `Letzter Wert: ${data.value} — Datum: ${data.time}`; | ||
| + | } else { | ||
| + | latestInfo.textContent = 'Keine Daten vorhanden.'; | ||
| + | } | ||
| + | } | ||
| + | zaehlerSelect.addEventListener(' | ||
| + | updateLatest(); | ||
| + | </ | ||
| + | <?php | ||
| + | if ($_SERVER[' | ||
| + | $z = $_POST[' | ||
| + | $zeit = $_POST[' | ||
| + | $wert = $_POST[' | ||
| + | $bem = trim($_POST[' | ||
| + | $ts = strtotime($zeit) * 1000000000; | ||
| + | |||
| + | $lines_to_write = []; | ||
| + | |||
| + | // Gas: m³ mit tag " | ||
| + | if ($z === ' | ||
| + | $lines_to_write[] = " | ||
| + | $kwh = $wert * 9.76608; | ||
| + | $lines_to_write[] = " | ||
| + | } elseif ($z===' | ||
| + | $lines_to_write[] = " | ||
| + | } elseif ($z===' | ||
| + | $lines_to_write[] = " | ||
| + | } else { | ||
| + | $lines_to_write[] = " | ||
| + | } | ||
| + | |||
| + | foreach ($lines_to_write as $line) { | ||
| + | $curl = curl_init(); | ||
| + | curl_setopt_array($curl, | ||
| + | $response = curl_exec($curl); | ||
| + | $status = curl_getinfo($curl, | ||
| + | curl_close($curl); | ||
| + | if ($status >=200 && $status< | ||
| + | else echo "< | ||
| + | } | ||
| + | } | ||
| + | ?> | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | Die Seite ist im webserver auf inuk gehostet. Die URL ist [[http:// | ||
influxdb.1667940751.txt.gz · Last modified: (external edit)
