From 2a8d569bb5e917fa40e6158bfc452647e73e4cfd Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Tue, 11 Nov 2025 11:01:52 +0100 Subject: [PATCH] shelly --- apps/abstraction/main.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/apps/abstraction/main.py b/apps/abstraction/main.py index b79aefc..8f483e2 100644 --- a/apps/abstraction/main.py +++ b/apps/abstraction/main.py @@ -181,9 +181,10 @@ async def handle_abstract_set( # Transform abstract payload to vendor-specific format vendor_payload = transform_abstract_to_vendor(device_type, device_technology, abstract_payload) - # For MAX! thermostats, vendor_payload is a plain string (integer temperature) + # For MAX! thermostats and Shelly relays, vendor_payload is a plain string # For other devices, it's a dict that needs JSON encoding - if device_technology == "max" and device_type == "thermostat": + if (device_technology == "max" and device_type == "thermostat") or \ + (device_technology == "shelly" and device_type == "relay"): vendor_message = vendor_payload # Already a string else: vendor_message = json.dumps(vendor_payload) @@ -339,9 +340,21 @@ async def mqtt_worker(config: dict[str, Any], redis_client: aioredis.Redis) -> N max_device_type = device["type"] break + # Check for Shelly relay (also sends plain text) + is_shelly_relay = False + shelly_device_id = None + shelly_device_type = None + for device_id, device in devices.items(): + if device.get("technology") == "shelly" and device.get("type") == "relay": + if topic == device["topics"]["state"]: + is_shelly_relay = True + shelly_device_id = device_id + shelly_device_type = device["type"] + break + # Parse payload based on device technology - if is_max_device: - # MAX! sends plain integer/string, not JSON + if is_max_device or is_shelly_relay: + # MAX! and Shelly send plain text, not JSON payload = payload_str.strip() else: # All other technologies use JSON @@ -377,6 +390,14 @@ async def mqtt_worker(config: dict[str, Any], redis_client: aioredis.Redis) -> N client, redis_client, max_device_id, max_device_type, device_technology, payload, redis_channel ) + # For Shelly relay devices, we already identified them above + elif is_shelly_relay: + device = devices[shelly_device_id] + device_technology = device.get("technology", "unknown") + await handle_vendor_state( + client, redis_client, shelly_device_id, shelly_device_type, + device_technology, payload, redis_channel + ) else: # Find device by vendor state topic for other technologies for device_id, device in devices.items():