Add go-e wallbox charger integration
- charger.go: polls go-e /api/status?filter=nrg,eto every 10 s - db.go: WriteCharger() inserts into charger hypertable - config.go: ChargerConf with host field - main.go: polls charger in parallel with inverter and meters - schema.sql: charger table + charger_10m/1h/daily aggregates + policies Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
50
schema.sql
50
schema.sql
@@ -98,10 +98,40 @@ SELECT time_bucket('1 day', time) AS bucket,
|
||||
FROM power_meter
|
||||
GROUP BY bucket, device;
|
||||
|
||||
-- Written by energy-collector every 10 s
|
||||
CREATE TABLE charger (
|
||||
time TIMESTAMPTZ NOT NULL,
|
||||
power REAL, -- W total charging power
|
||||
eto_wh BIGINT -- Wh cumulative total energy (from go-e eto field)
|
||||
);
|
||||
SELECT create_hypertable('charger', 'time', chunk_time_interval => INTERVAL '7 days');
|
||||
|
||||
CREATE MATERIALIZED VIEW charger_10m
|
||||
WITH (timescaledb.continuous, timescaledb.materialized_only = false) AS
|
||||
SELECT time_bucket('10 minutes', time) AS bucket,
|
||||
AVG(power) AS power
|
||||
FROM charger
|
||||
GROUP BY bucket;
|
||||
|
||||
CREATE MATERIALIZED VIEW charger_1h
|
||||
WITH (timescaledb.continuous, timescaledb.materialized_only = false) AS
|
||||
SELECT time_bucket('1 hour', bucket) AS bucket,
|
||||
AVG(power) AS power
|
||||
FROM charger_10m
|
||||
GROUP BY 1;
|
||||
|
||||
CREATE MATERIALIZED VIEW charger_daily
|
||||
WITH (timescaledb.continuous, timescaledb.materialized_only = false) AS
|
||||
SELECT time_bucket('1 day', time) AS bucket,
|
||||
last(eto_wh, time) AS eto_wh
|
||||
FROM charger
|
||||
GROUP BY bucket;
|
||||
|
||||
-- ── Retention — keep 30 days of raw data; aggregates stay forever ─────────────
|
||||
|
||||
SELECT add_retention_policy('inverter', INTERVAL '30 days');
|
||||
SELECT add_retention_policy('power_meter', INTERVAL '30 days');
|
||||
SELECT add_retention_policy('charger', INTERVAL '30 days');
|
||||
|
||||
-- ── Refresh policies ──────────────────────────────────────────────────────────
|
||||
|
||||
@@ -135,6 +165,22 @@ SELECT add_continuous_aggregate_policy('power_meter_daily',
|
||||
end_offset => INTERVAL '1 day',
|
||||
schedule_interval => INTERVAL '1 day');
|
||||
|
||||
-- Grant SELECT on all tables and views (including continuous aggregates) to energy.
|
||||
-- Run after all views are created so the grant covers them.
|
||||
SELECT add_continuous_aggregate_policy('charger_10m',
|
||||
start_offset => INTERVAL '1 hour',
|
||||
end_offset => INTERVAL '10 minutes',
|
||||
schedule_interval => INTERVAL '10 minutes');
|
||||
|
||||
SELECT add_continuous_aggregate_policy('charger_1h',
|
||||
start_offset => INTERVAL '3 hours',
|
||||
end_offset => INTERVAL '1 hour',
|
||||
schedule_interval => INTERVAL '1 hour');
|
||||
|
||||
SELECT add_continuous_aggregate_policy('charger_daily',
|
||||
start_offset => INTERVAL '3 days',
|
||||
end_offset => INTERVAL '1 day',
|
||||
schedule_interval => INTERVAL '1 day');
|
||||
|
||||
-- Grant privileges after all objects are created.
|
||||
-- INSERT on raw hypertables (collector writes), SELECT on everything else (frontend reads).
|
||||
GRANT INSERT ON inverter, power_meter, charger TO energy;
|
||||
GRANT SELECT ON ALL TABLES IN SCHEMA public TO energy;
|
||||
|
||||
Reference in New Issue
Block a user