Files
ems/db/migration/V003__seed_site_home01.sql
Dusan Vojacek 9f4126946d second version
2026-04-03 14:23:16 +02:00

206 lines
8.7 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
--
-- Deye Modbus (holding, SUN-20K) viz docs/04-modules/telemetry.md:
-- 0x0215 PV W, 0x0103 SoC %, 0x0105 bat W, 0x0101 bat V×0.1,
-- 0x0169 grid W, 0x016F grid L1 V×0.1, 0x0213 load W,
-- 0x0220 inv temp ×0.1, 0x0168 mode, 0x0180 fault
-- Teltonika / Samsung registry: TODO doplnit z dokumentace / Loxone šablony
-- =============================================================
-- ============================================================
-- LOKALITA
-- ============================================================
INSERT INTO ems.site (code, name, timezone, latitude, longitude, active, notes)
VALUES (
'home-01',
'Hlavní objekt',
'Europe/Prague',
49.24466967511591,
17.40658656876068,
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', '172.16.1.10', 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';
-- 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';
-- 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';
-- ============================================================
-- 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,
18000, 18000, 18000,
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
184,
22, -- sklon odhad; upřesnit dle střechy
18,
1.0,
true,
'Hlavní FVE pole řízené Deye střídačem.'
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,
184,
35,
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', 'EHS Mono (placeholder)',
ep.id,
12000, -- jmenovitý topný výkon W upřesnit z datasheetu
3.20, -- COP @ 7 °C upřesnit
7.0, -- referenční teplota A7/W35
30, 15,
200, -- objem TUV zásobníku (l) upřesnit
45, 60, 55,
'TODO: Loxone / Modbus čidlo TUV',
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';