sqlite3 ./2025-11-15-ecas-export.db -readonly -csv \
"SELECT meterid, date, value, comment FROM reading" \
| tail -n +2 \
| awk -F',' '
function map_meter(id, datetime) {
if (id == 1) return "strom1";
if (id == 2) return "gas1";
if (id == 3) {
swap_time = "2021-05-27T08:30:00";
if (datetime >= swap_time) return "wasser2";
else return "wasser1";
}
return "unbekannt";
}
function map_unit(id) {
if (id == 1) return "kwh";
if (id == 2) return "m3";
if (id == 3) return "m3";
return "unknown";
}
function to_ns(datetime) {
cmd = "date -d \"" datetime "\" +%s"
cmd | getline seconds
close(cmd)
return seconds "000000000"
}
{
meter = map_meter($1, $2);
unit = map_unit($1);
ts_ns = to_ns($2);
value = $3;
comment = $4;
# SQLite liefert "" für leere Kommentare → ignorieren
if (comment == "\"\"") comment = "";
# Zeile mit oder ohne Bemerkung
if (comment != "") {
printf("zaehlerstand,zaehler=%s,einheit=%s wert=%s,Bemerkung=%s %s\n", meter, unit, value, comment, ts_ns);
} else {
printf("zaehlerstand,zaehler=%s,einheit=%s wert=%s %s\n", meter, unit, value, ts_ns);
}
# Gas (ursprünglich meterid=2) zusätzlich kWh
if ($1 == 2) {
kwh = value * 9.76608;
if (comment != "") {
printf("zaehlerstand,zaehler=%s,einheit=kwh wert=%.5f,Bemerkung=%s %s\n", meter, kwh, comment, ts_ns);
} else {
printf("zaehlerstand,zaehler=%s,einheit=kwh wert=%.5f %s\n", meter, kwh, ts_ns);
}
}
}'
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, die in die InfluxDB schreibt.
Damit kann ich neue Werte aufnehmen.
Zählerstand erfassen
Zählerstand erfassen
range(start: -5y)
|> filter(fn: (r) => r._measurement == "zaehlerstand")
|> filter(fn: (r) => r["_field"] != "Bemerkung")
FLUX;
// Gas: nur Einträge ohne Einheit kWh
if ($z === 'gas1') {
$flux .= "\n |> filter(fn: (r) => r[\"einheit\"] != \"kwh\")";
}
$flux .= "\n |> filter(fn: (r) => r[\"zaehler\"] == \"$z\")";
$flux .= "\n |> last()";
$flux .= "\n |> keep(columns: [\"_time\", \"_value\", \"zaehler\", \"_field\"])";
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "$influx_url/api/v2/query?org=$org",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
"Authorization: Token $token",
"Content-Type: application/vnd.flux"
],
CURLOPT_POSTFIELDS => $flux
]);
/*
print "";
print PHP_EOL;
*/
$resp = curl_exec($curl);
curl_close($curl);
$results[$z] = null;
$lines = explode("\n", $resp);
foreach ($lines as $line) {
/*
print "";
print PHP_EOL;
*/
if (strpos($line, '_value') !== false) continue;
$parts = str_getcsv($line, ',', '"', '\\');
/*
print "";
print PHP_EOL;
*/
if (count($parts) < 6) continue;
/*
print "";
print PHP_EOL;
*/
$value = $parts[4] ?? null;
$time = $parts[3] ?? null;
if ($value !== null) {
$results[$z] = ['value'=>$value, 'time'=>$time, 'raw_lines'=>$lines];
}
}
}
return $results;
}
$latest_selected = query_influx_selected();
?>
$v): ?>
"$influx_url/api/v2/write?org=$org&bucket=$bucket&precision=ns", CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_HTTPHEADER => ["Authorization: Token $token","Content-Type: text/plain; charset=utf-8"], CURLOPT_POSTFIELDS => $line]);
$response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($status >=200 && $status<300) echo "Erfolgreich gespeichert: $line
";
else echo "Fehler: $response
";
}
}
?>
Die Seite ist im webserver auf inuk gehostet. Die URL ist [[http://inuk:10025/zaehlerstandeingabe.php]].