- Home
- Skills
- Workflow Automation
- Home Assistant Local LAN Protocol Bridge Builder
Works with the AI Agents you already use
Home Assistant Local LAN Protocol Bridge Builder
by Sam3gp8
Design and debug resilient local LAN custom integrations and socket bridges for Home Assistant — defensive frame validation, jittered backoff reconnects, clean teardown, and zero cloud lock-in.
$6.99
What it does
- Designs local TCP, UDP, or MQTT bridges to bypass vendor cloud servers
- Adds safety checks to prevent crashes from messy or incomplete device data
- Fixes infinite retry loops that clutter logs or heat up device hardware
- Ensures connections close cleanly when your home system shuts down
- Creates specific plans for handling unstable Wi-Fi connections
Who it's for
Homeowners with smart devices that need a cloud app to work
Take back control by moving your device control from the vendor's server to your local network.
Try asking: “Help me write a local bridge for my smart light that currently requires a cloud login.”
Home Assistant users with flaky custom integrations
Fix crashes caused by bad network connections or weird data packets from your devices.
Try asking: “My custom TCP integration for my pool heater keeps crashing when the Wi-Fi blips. Fix the reconnect logic.”
Privacy-focused tech enthusiasts
Remove the need for outside internet connections for your internal home gadgets.
Try asking: “Design a local MQTT bridge for my smart plugs so I can block them from the internet.”
Home Assistant Local LAN Protocol Bridge Builder
Example session with this skill installed
I have a smart heater that uses a local TCP port but it crashes Home Assistant whenever the Wi-Fi signal drops. Can you help me fix the reconnect logic?
- Read your context and instructions
- Compiled the home assistant local
Local TCP Bridge Failure-Mode Audit (heater_client.py)
| Severity | Failure Mode | Root Cause | Remediation |
|---|---|---|---|
| CRITICAL | Unhandled IncompleteReadError / struct.error crashes the listener loop on Wi-Fi drop | Parses raw reader.read(1024) chunks without checking frame header or byte length | Validate fixed header and bounded payload length before readexactly() |
| CRITICAL | Tight while True reconnect loop floods HA logs and wedges the heater's Wi-Fi stack | Immediate retry with zero backoff or jitter after ConnectionResetError | Enforce bounded exponential backoff (2s → 60s) with ±20% jitter and cooldown logging |
| HIGH | Reloading the integration or restarting HA leaves ghost sockets open | Background task not cancelled or awaited in async_unload_entry | Bind task to entry.async_create_background_task() and close StreamWriter in finally: |
| MEDIUM | Half-open Wi-Fi drop hangs the reader indefinitely with no unavailable state | Missing read timeout / heartbeat check | Wrap reads in asyncio.wait_for(..., timeout=30) and mark entities unavailable on disconnect |
Hardened Async TCP Transport (transport.py)
import asyncio
import logging
import random
from collections.abc import Callable
_LOGGER = logging.getLogger(__name__)
FRAME_MAGIC = b"\xAA\x55"
MAX_PAYLOAD_BYTES = 256
class HeaterLocalBridge:
def __init__(self, host: str, port: int, on_frame: Callable[[bytes], None], on_state: Callable[[bool], None]) -> None:
self._host = host
self._port = port
self._on_frame = on_frame
self._on_state = on_state
self._stop_event = asyncio.Event()
async def run_forever(self) -> None:
backoff = 2.0
while not self._stop_event.is_set():
writer: asyncio.StreamWriter | None = None
try:
reader, writer = await asyncio.wait_for(
asyncio.open_connection(self._host, self._port), timeout=10.0
)
backoff = 2.0 # Reset backoff on healthy connect
self._on_state(True)
await self._read_loop(reader)
except asyncio.CancelledError:
raise
except (OSError, asyncio.TimeoutError, asyncio.IncompleteReadError) as err:
self._on_state(False)
delay = min(backoff, 60.0) * random.uniform(0.8, 1.2)
_LOGGER.warning("Heater %s disconnected (%s); retrying in %.1fs", self._host, err, delay)
await asyncio.sleep(delay)
backoff = min(backoff * 2, 60.0)
finally:
if writer is not None:
writer.close()
try:
await asyncio.wait_for(writer.wait_closed(), timeout=3.0)
except (OSError, asyncio.TimeoutError):
pass
async def _read_loop(self, reader: asyncio.StreamReader) -> None:
while not self._stop_event.is_set():
header = await asyncio.wait_for(reader.readexactly(4), timeout=30.0)
if header[:2] != FRAME_MAGIC:
_LOGGER.debug("Dropping malformed frame header: %s", header.hex())
continue
length = int.from_bytes(header[2:4], "big")
if length == 0 or length > MAX_PAYLOAD_BYTES:
_LOGGER.debug("Dropping out-of-bounds payload length: %d", length)
continue
payload = await asyncio.wait_for(reader.readexactly(length), timeout=10.0)
self._on_frame(payload)
def stop(self) -> None:
self._stop_event.set()
Home Assistant Lifecycle Checklist
- Launch
bridge.run_forever()viaentry.async_create_background_task(hass, ..., "heater_tcp_bridge") - Register
bridge.stop()onEVENT_HOMEASSISTANT_STOPand cancel/await the task insideasync_unload_entry() - Keep entity updates decoupled inside
on_frame/on_statecallbacks so socket hiccups mark entitiesunavailableinstead of raising - Simulate a mid-frame Wi-Fi drop (
ncdisconnect) to verify clean recovery with zero orphaned sockets
Connects securely to your tools. The creator never sees your data.
About this skill
Turns your agent into a builder and debugger of local-network protocol bridges for Home Assistant devices that lack clean official APIs.
- Validate framing & lengths before parsing — defensive buffer/header/boundary checks so malformed or partial packets never raise unhandled exceptions.
- Bounded exponential backoff — jittered reconnects with circuit/cooldown visibility instead of tight loops that flood logs or drain device radios.
- Separate transport from entity state — isolate connection/framing logic; cancel sockets and tasks cleanly on unload/shutdown.
- No cloud lock-in — local TCP/UDP/HTTP/MQTT, no vendor servers.
Instruction-only design/debug guidance; adapt to your own protocols, ports, and entities.
This skill provides design and debugging guidance only. It cannot make network calls or run scripts directly on your hardware.
Built for Claude Code, Cursor, ChatGPT, and MCP-compatible coding agents targeting Home Assistant 2024.10+ custom integrations and local LAN bridges (TCP, UDP, HTTP, and MQTT). Engineering patterns enforced: • Defensive frame validation — Explicit header, payload-length, and buffer-boundary checks on asyncio.StreamReader before parsing so partial or malformed packets never raise unhandled exceptions. • Bounded jittered exponential backoff — Configurable retry caps, random jitter, and circuit/cooldown visibility instead of tight reconnect loops that flood logs or lock up device Wi-Fi radios. • Transport/entity separation — Decouples raw socket I/O and framing from Home Assistant entity state updates. • Clean lifecycle teardown — Registers background listeners via entry.async_create_background_task, cancels cleanly on async_unload_entry and EVENT_HOMEASSISTANT_STOP, and closes sockets without orphan tasks.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 2 days ago
- Software
- Home Assistant 2024.10+
Permissions
No special permissions declared or detected
What's inside
Frequently Asked Questions
New in Workflow Automation
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Workflow Automation.