second version

This commit is contained in:
Dusan Vojacek
2026-04-03 14:23:16 +02:00
parent 897b95f728
commit 9f4126946d
105 changed files with 9738 additions and 1470 deletions

View File

@@ -38,10 +38,18 @@ STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$BASE/api/v1/sites/${SITE_ID}/p
echo -n "OTE price import... "
RESULT=$(curl -sf -X POST "$BASE/api/v1/sites/${SITE_ID}/prices/import" \
-H "Content-Type: application/json" 2>/dev/null) || RESULT=""
PRICES_EXPECTED=$(python3 -c "
from zoneinfo import ZoneInfo
from datetime import datetime
n = datetime.now(ZoneInfo('Europe/Prague'))
print(1 if (n.hour, n.minute) >= (14, 30) else 0)
")
if echo "$RESULT" | python3 -c "import sys,json; d=json.load(sys.stdin); assert d.get('slots_imported',0)>0" 2>/dev/null; then
echo "OK ($(echo "$RESULT" | python3 -c "import sys,json; print(json.load(sys.stdin)['slots_imported'])") slotů)"
elif [ "$PRICES_EXPECTED" = "1" ]; then
echo "WARN OTE API možná nemá data pro zítřek nebo je nedostupné (po 14:30 Europe/Prague)"
else
echo "WARN OTE API možná nemá data pro zítřek nebo je nedostupné"
echo "OK (před 14:30 Europe/Prague D+1 ceny typicky ještě nejsou; import přeskočen bez WARN)"
fi
# 6. PV forecast

View File

@@ -0,0 +1,69 @@
"""Rychlý test Modbus TCP na Deye přes Waveshare (registry dle aktuální mapy)."""
from __future__ import annotations
import asyncio
import sys
from pymodbus.client import AsyncModbusTcpClient
HOST = "172.16.1.10"
PORT = 502
UNIT_ID = 1 # dle DIP přepínače
# (adresa, typ, počet registrů, jednotka, popis)
REGISTERS: dict[str, tuple[int, str, int, str, str]] = {
"run_state": (500, "uint", 1, "", "enum provozní stav střídače (raw)"),
"battery_soc_%": (588, "uint", 1, "%", "SoC baterie"),
"battery_power_w": (590, "sint", 1, "W", "+ vybíjení / nabíjení"),
"batt_charge_today_wh": (514, "uint", 1, "Wh", "dnešní nabití baterie"),
"batt_discharge_today_wh": (515, "uint", 1, "Wh", "dnešní vybití baterie"),
"gen_port_power_w": (667, "uint", 1, "W", "GEN port FVE pole B"),
"grid_total_power_w": (625, "sint", 1, "W", "+ import ze sítě / export"),
"load_total_power_w": (653, "uint", 1, "W", "celková spotřeba"),
"pv1_power_w": (672, "uint", 1, "W", "výkon PV1"),
"pv2_power_w": (673, "uint", 1, "W", "výkon PV2"),
}
async def read_reg(client: AsyncModbusTcpClient, address: int, reg_type: str) -> int | None:
result = await client.read_holding_registers(
address, count=1, device_id=UNIT_ID
)
if result.isError():
return None
raw = int(result.registers[0])
if reg_type == "sint" and raw > 32767:
raw -= 65536
return raw
async def test_deye() -> None:
print(f"Připojuji se na {HOST}:{PORT} device_id={UNIT_ID}...")
client = AsyncModbusTcpClient(HOST, port=PORT)
try:
ok = await client.connect()
if not ok or not client.connected:
print("CHYBA: Nelze se připojit na Waveshare")
return
print("Připojeno OK\n")
print(f"{'Signál':<28} {'Hodnota':>10} {'Jedn.':<6} Reg(dec) Popis")
print("-" * 85)
for name, (addr, rtype, _count, unit, desc) in REGISTERS.items():
val = await read_reg(client, addr, rtype)
reg_h = f"{addr} (0x{addr:04X})"
if val is None:
print(f" {name:<26} {'CHYBA':>10} {'':6} {reg_h:<12} {desc}")
else:
u = unit or ""
print(f" {name:<26} {val:>10} {u:<6} {reg_h:<12} {desc}")
finally:
client.close()
if __name__ == "__main__":
try:
asyncio.run(test_deye())
except KeyboardInterrupt:
sys.exit(130)

View File

@@ -0,0 +1,18 @@
-- Aktualizace Waveshare endpointu pro Deye (home-01) bez resetu migrací.
-- OR musí být v závorkách, jinak by se aktualizovaly i řádky jiných site.
UPDATE ems.site_endpoint
SET host = '172.16.1.10', port = 502, unit_id = 1
WHERE endpoint_type = 'modbus_tcp'
AND site_id = (SELECT id FROM ems.site WHERE code = 'home-01')
AND (
notes LIKE '%Deye%'
OR notes ILIKE '%inverter%'
OR notes ILIKE '%střídač%'
);
-- Ověření
SELECT id, endpoint_type, host, port, unit_id, notes
FROM ems.site_endpoint
WHERE site_id = (SELECT id FROM ems.site WHERE code = 'home-01')
ORDER BY id;