Skip to content

Instantly share code, notes, and snippets.

@hanzoh
hanzoh / battery_sim.sql
Last active March 3, 2025 20:46
Simulate home battery from Home Assistant data
drop table tmp_battery_sim;
create table tmp_battery_sim (start timestamp without time zone, energy_in_battery numeric, energy_not_consumed_from_grid numeric, savings_from_battery numeric);
do $$
declare
-- Variables
t record;
vn_battery numeric := 0.0;
vn_battery_prev numeric := 0.0;
vn_grid_savings numeric := 0.0;