Add webhook trigger condition for automations

Per-automation webhook URL with auto-generated 128-bit hex token.
External services (Home Assistant, IFTTT, curl) can POST to
/api/v1/webhooks/{token} with {"action": "activate"|"deactivate"}
to control automation state — no API key required (token is auth).

Backend: WebhookCondition model, engine state tracking with
immediate evaluation, webhook endpoint, schema/route updates.
Frontend: webhook option in condition editor, URL display with
copy button, card badge, i18n for en/ru/zh.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-01 18:28:31 +03:00
parent 01104acad1
commit aafcf83896
12 changed files with 221 additions and 9 deletions

View File

@@ -30,6 +30,8 @@ class Condition:
return DisplayStateCondition.from_dict(data)
if ct == "mqtt":
return MQTTCondition.from_dict(data)
if ct == "webhook":
return WebhookCondition.from_dict(data)
raise ValueError(f"Unknown condition type: {ct}")
@@ -158,6 +160,23 @@ class MQTTCondition(Condition):
)
@dataclass
class WebhookCondition(Condition):
"""Activate via an HTTP webhook call with a secret token."""
condition_type: str = "webhook"
token: str = "" # auto-generated 128-bit hex secret
def to_dict(self) -> dict:
d = super().to_dict()
d["token"] = self.token
return d
@classmethod
def from_dict(cls, data: dict) -> "WebhookCondition":
return cls(token=data.get("token", ""))
@dataclass
class Automation:
"""Automation that activates a scene preset based on conditions."""