Files
ems/db/migration/V095__ev_presence.sql
Dusan Vojacek 2122fa2035
All checks were successful
CI and deploy / migration-check (push) Successful in 47s
CI and deploy / deploy (push) Has been skipped
Tesla presence watcher: geofence, ev_presence_obs, 'píchni auto' pobídka
- V095 ems.ev_presence_obs (state/at_home/distance/charging/shift per ~5 min)
- tesla_client: get_vehicle_api_state (jen /vehicles — nebudí), haversine_m
- collector poll_tesla_presence: online → poloha → geofence 150 m vs GPS site;
  přechod pryč→doma + Disconnected → Discord pobídka s aktuálním přebytkem
  (cooldown 2 h); vše logováno pro budoucí dostupnostní statistiku
- 6 testů (haversine, přechody); docs: zákopy reauth procesu (6 bodů)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-12 14:14:48 +02:00

23 lines
1.1 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- Presence vozidla (Tesla location scope): kde auto je, kdy bývá doma.
-- Zdroj: levný poll /vehicles (state, NEbudí) + při online location_data.
-- Účel: (a) notifikace "auto doma a nepíchlé + svítí přebytek → píchni ho",
-- (b) dostupnostní statistika per DOW×hodina pro plánovač (maska ev_connected
-- a zreálnění oportunistické hodnoty) — follow-up nad těmito daty.
create table ems.ev_presence_obs (
id bigserial primary key,
vehicle_id int not null references ems.asset_vehicle (id),
observed_at timestamptz not null default now(),
api_state text, -- online / asleep / offline (z /vehicles, bez buzení)
at_home boolean, -- null = poloha neznámá (asleep)
distance_m int,
charging_state text, -- Disconnected / Stopped / Charging…
shift_state text
);
create index idx_ev_presence_obs_vehicle_time
on ems.ev_presence_obs (vehicle_id, observed_at desc);
comment on table ems.ev_presence_obs is
'Pozorování přítomnosti vozidla (geofence vs GPS site). Poll ~5 min, poloha jen když je auto vzhůru (nebudí). Vstup pro "píchni auto" notifikace a budoucí dostupnostní statistiku.';