Files
ems/db/migration/V003__seed_site_home01.sql
Dusan Vojacek 8b4af663d8 Initial commit
Made-with: Cursor
2026-03-20 13:27:44 +01:00

204 lines
8.6 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.
-- =============================================================
-- V003__seed_site_home01.sql
-- EMS Platform seed data první lokality home-01
-- Doplnit: latitude, longitude, IP adresy, azimuty FVE polí
-- =============================================================
-- ============================================================
-- LOKALITA
-- ============================================================
INSERT INTO ems.site (code, name, timezone, latitude, longitude, active, notes)
VALUES (
'home-01',
'Hlavní objekt',
'Europe/Prague',
NULL, -- TODO: doplnit GPS
NULL, -- TODO: doplnit GPS
true,
'První instalace. Deye 20kW + 64kWh baterie + 2x Teltonika EV + Samsung TČ.'
);
-- ============================================================
-- ENDPOINTY
-- ============================================================
-- Deye střídač přes Waveshare RS485→TCP
INSERT INTO ems.site_endpoint (site_id, endpoint_type, host, port, protocol, unit_id, enabled, notes)
SELECT id, 'modbus_tcp', '192.168.1.100', 502, 'modbus_tcp', 1, true, 'Waveshare WS-ETH pro Deye SUN-20K. Unit ID dle DIP přepínače.'
FROM ems.site WHERE code = 'home-01';
-- TODO: doplnit skutečnou IP adresy Waveshare
-- Teltonika EV nabíječka 1 přes Waveshare
INSERT INTO ems.site_endpoint (site_id, endpoint_type, host, port, protocol, unit_id, enabled, notes)
SELECT id, 'modbus_tcp', '192.168.1.101', 502, 'modbus_tcp', 1, true, 'Waveshare pro Teltonika TeltoCharge #1.'
FROM ems.site WHERE code = 'home-01';
-- TODO: doplnit IP a unit_id
-- Teltonika EV nabíječka 2 přes Waveshare
INSERT INTO ems.site_endpoint (site_id, endpoint_type, host, port, protocol, unit_id, enabled, notes)
SELECT id, 'modbus_tcp', '192.168.1.102', 502, 'modbus_tcp', 1, true, 'Waveshare pro Teltonika TeltoCharge #2.'
FROM ems.site WHERE code = 'home-01';
-- Samsung tepelné čerpadlo přes Waveshare
INSERT INTO ems.site_endpoint (site_id, endpoint_type, host, port, protocol, unit_id, enabled, notes)
SELECT id, 'modbus_tcp', '192.168.1.103', 502, 'modbus_tcp', 1, true, 'Waveshare pro Samsung tepelné čerpadlo.'
FROM ems.site WHERE code = 'home-01';
-- Loxone Miniserver
INSERT INTO ems.site_endpoint (site_id, endpoint_type, host, port, protocol, unit_id, enabled, notes)
SELECT id, 'loxone_http', '192.168.1.10', 80, 'http', NULL, true, 'Loxone Miniserver příjem setpointů přes Virtual HTTP Inputs.'
FROM ems.site WHERE code = 'home-01';
-- TODO: doplnit IP Loxone
-- ============================================================
-- SÍŤOVÉ PŘIPOJENÍ
-- ============================================================
INSERT INTO ems.site_grid_connection (site_id, max_import_power_w, max_export_power_w, no_export, reserved_capacity_w, notes)
SELECT id, 22000, 20000, false, 0, 'Třífázová přípojka. Limity upřesnit dle smlouvy s distributorem.'
FROM ems.site WHERE code = 'home-01';
-- ============================================================
-- TRŽNÍ KONFIGURACE
-- ============================================================
INSERT INTO ems.site_market_config (
site_id, purchase_pricing_mode, sale_pricing_mode,
buy_margin_fixed_czk, buy_margin_percent,
sell_margin_fixed_czk, sell_margin_percent,
currency, valid_from, valid_to, notes
)
SELECT
id, 'spot', 'spot',
0.050, -- 5 haléřů/kWh nákupní marže (distribuce, poplatky)
0,
-0.020, -- 2 haléře/kWh srážka z prodejní ceny
0,
'CZK', now(), NULL, 'Výchozí konfigurace. Upřesnit dle skutečné smlouvy.'
FROM ems.site WHERE code = 'home-01';
-- ============================================================
-- AKTIVA STŘÍDAČ
-- ============================================================
INSERT INTO ems.asset_inverter (site_id, code, manufacturer, model, endpoint_id, max_charge_power_w, max_discharge_power_w, max_export_power_w, controllable, notes)
SELECT
s.id, 'deye-main', 'Deye', 'SUN-20K-SG01LP1-EU',
ep.id,
20000, 20000, 20000,
true,
'Hlavní hybridní střídač 20kW LV. RS485 Modbus RTU přes Waveshare.'
FROM ems.site s
JOIN ems.site_endpoint ep ON ep.site_id = s.id AND ep.notes LIKE '%Deye%'
WHERE s.code = 'home-01';
-- Ongridový střídač na GEN portu (autonomní, neřídíme)
INSERT INTO ems.asset_inverter (site_id, code, manufacturer, model, endpoint_id, max_export_power_w, controllable, notes)
SELECT
id, 'ongrid-gen', NULL, NULL, NULL, 10000, false,
'Ongridový střídač zapojený do GEN portu Deye. Autonomní provoz, EMS neřídí.'
FROM ems.site WHERE code = 'home-01';
-- ============================================================
-- AKTIVA BATERIE
-- ============================================================
INSERT INTO ems.asset_battery (site_id, inverter_id, code, usable_capacity_wh, min_soc_percent, reserve_soc_percent, max_soc_percent, charge_efficiency, discharge_efficiency, degradation_cost_czk_kwh)
SELECT
s.id, inv.id, 'bat-main',
64000, -- 64 kWh
10, -- min SoC 10 %
20, -- rezerva 20 % pro výpadek sítě
95, -- max SoC 95 %
0.95, 0.95,
0.50 -- Kč/kWh degradace, upřesnit dle záruky výrobce
FROM ems.site s
JOIN ems.asset_inverter inv ON inv.site_id = s.id AND inv.code = 'deye-main'
WHERE s.code = 'home-01';
-- ============================================================
-- AKTIVA FVE POLE
-- ============================================================
-- Pole A řízené Deye střídačem
INSERT INTO ems.asset_pv_array (site_id, inverter_id, code, name, nominal_power_wp, azimuth_deg, tilt_deg, module_count, shading_factor, controllable, notes)
SELECT
s.id, inv.id, 'pv-a', 'FVE pole A',
10000, -- 10 kWp
NULL, -- TODO: doplnit azimut (0=jih)
NULL, -- TODO: doplnit sklon (stupně)
NULL,
1.0,
true,
'Hlavní FVE pole řízené Deye střídačem. Doplnit azimut a sklon.'
FROM ems.site s
JOIN ems.asset_inverter inv ON inv.site_id = s.id AND inv.code = 'deye-main'
WHERE s.code = 'home-01';
-- Pole B ongridový, autonomní
INSERT INTO ems.asset_pv_array (site_id, inverter_id, code, name, nominal_power_wp, azimuth_deg, tilt_deg, module_count, shading_factor, controllable, notes)
SELECT
s.id, inv.id, 'pv-b', 'FVE pole B (ongrid)',
10000,
NULL, -- TODO: doplnit azimut
NULL, -- TODO: doplnit sklon
NULL,
1.0,
false,
'Ongridový střídač na GEN portu Deye. EMS neřídí, výkon se projeví v telemetrii Deye jako součást pv_power_w.'
FROM ems.site s
JOIN ems.asset_inverter inv ON inv.site_id = s.id AND inv.code = 'ongrid-gen'
WHERE s.code = 'home-01';
-- ============================================================
-- AKTIVA EV NABÍJEČKY
-- ============================================================
INSERT INTO ems.asset_ev_charger (site_id, code, manufacturer, model, endpoint_id, max_power_w, min_power_w, phases, connector_count, schedulable, notes)
SELECT
s.id, 'ev-charger-1', 'Teltonika', 'TeltoCharge 22kW',
ep.id,
22000, 1380, 3, 1, true,
'EV nabíječka č. 1. Modbus TCP přes Waveshare. Ověřit Modbus registry z dokumentace Teltonika.'
FROM ems.site s
JOIN ems.site_endpoint ep ON ep.site_id = s.id AND ep.notes LIKE '%TeltoCharge #1%'
WHERE s.code = 'home-01';
INSERT INTO ems.asset_ev_charger (site_id, code, manufacturer, model, endpoint_id, max_power_w, min_power_w, phases, connector_count, schedulable, notes)
SELECT
s.id, 'ev-charger-2', 'Teltonika', 'TeltoCharge 22kW',
ep.id,
22000, 1380, 3, 1, true,
'EV nabíječka č. 2. Modbus TCP přes Waveshare.'
FROM ems.site s
JOIN ems.site_endpoint ep ON ep.site_id = s.id AND ep.notes LIKE '%TeltoCharge #2%'
WHERE s.code = 'home-01';
-- ============================================================
-- AKTIVA TEPELNÉ ČERPADLO
-- ============================================================
INSERT INTO ems.asset_heat_pump (
site_id, code, manufacturer, model, endpoint_id,
rated_heating_power_w, cop_rated, cop_temp_reference_c,
min_run_duration_min, min_stop_duration_min,
tuv_tank_volume_l, tuv_min_temp_c, tuv_max_temp_c, tuv_target_temp_c,
tuv_temp_sensor_ref, schedulable, notes
)
SELECT
s.id, 'hp-samsung', 'Samsung', NULL, -- TODO: doplnit model
ep.id,
NULL, -- TODO: doplnit jmenovitý výkon W
NULL, -- TODO: doplnit COP rated
7.0, -- referenční teplota A7/W35
30, 15,
NULL, -- TODO: doplnit objem zásobníku
45, 60, 55,
NULL, -- TODO: doplnit odkaz na teplotní čidlo
true,
'Samsung tepelné čerpadlo s Modbus modulem. Řídit dle COP a venkovní teploty (výhodné kolem poledne v chladných měsících).'
FROM ems.site s
JOIN ems.site_endpoint ep ON ep.site_id = s.id AND ep.notes LIKE '%Samsung%'
WHERE s.code = 'home-01';