root преди 1 месец
родител
ревизия
f093f64273
променени са 4 файла, в които са добавени 102 реда и са изтрити 93 реда
  1. 42 93
      automations.yaml
  2. 41 0
      scripts/sync_to_alexa.py
  3. 19 0
      scripts/sync_to_alexa.sh
  4. BIN
      zigbee.db

+ 42 - 93
automations.yaml

@@ -277,95 +277,6 @@
       milliseconds: 0
   mode: single
   max_exceeded: silent
-- id: '1684741441916'
-  alias: atmosphere effect 1
-  description: ''
-  triggers:
-  - device_id: 6c7dfb43f3f808a5498864911e8ab1ab
-    domain: zha
-    type: remote_button_double_press
-    subtype: button_4
-    trigger: device
-  conditions: []
-  actions:
-  - data:
-      effect: colorloop
-    action: light.turn_on
-    target:
-      entity_id: light.atmosphere
-  mode: single
-- id: '1684741637840'
-  alias: atmosphere hot pink
-  description: ''
-  triggers:
-  - device_id: 6c7dfb43f3f808a5498864911e8ab1ab
-    domain: zha
-    type: remote_button_short_press
-    subtype: button_4
-    trigger: device
-  conditions: []
-  actions:
-  - data:
-      rgb_color:
-      - 197
-      - 27
-      - 87
-      brightness_pct: 15
-    action: light.turn_on
-    target:
-      entity_id: light.atmosphere
-  mode: single
-- id: '1684741696773'
-  alias: atmosphere off
-  description: ''
-  triggers:
-  - device_id: 6c7dfb43f3f808a5498864911e8ab1ab
-    domain: zha
-    type: remote_button_short_press
-    subtype: button_1
-    trigger: device
-  conditions: []
-  actions:
-  - data:
-      transition: 3
-    action: light.turn_off
-    target:
-      entity_id: light.atmosphere
-  mode: single
-- id: '1684741914422'
-  alias: atmosphere brighter
-  description: ''
-  triggers:
-  - device_id: 6c7dfb43f3f808a5498864911e8ab1ab
-    domain: zha
-    type: remote_button_short_press
-    subtype: button_3
-    trigger: device
-  conditions: []
-  actions:
-  - data:
-      brightness_step: 50
-    action: light.turn_on
-    target:
-      entity_id: light.atmosphere
-  mode: single
-- id: '1684741987579'
-  alias: atmosphere dimmer
-  description: ''
-  triggers:
-  - device_id: 6c7dfb43f3f808a5498864911e8ab1ab
-    domain: zha
-    type: remote_button_short_press
-    subtype: button_2
-    trigger: device
-  conditions: []
-  actions:
-  - data:
-      brightness_step: -50
-    action: light.turn_on
-    target:
-      entity_id: light.atmosphere
-  mode: single
 - id: '1701926625524'
   alias: Office Heater - Turn Off
   description: ''
@@ -694,14 +605,52 @@
       encoding: ''
   conditions: []
   actions:
+  - variables:
+      timestamp: '{{ now().strftime("%Y%m%d_%H%M%S") }}'
+      image_file: '{{ trigger.payload_json.oid }}_{{ timestamp }}.jpg'
+  - action: shell_command.save_payload_image
+    data:
+      payload: '{{ trigger.payload_json.image }}'
+      filename: '{{ image_file }}'
+  - delay: 00:00:01
   - action: notify.adris_mobile_devices
-    metadata: {}
     data:
-      message: Person Detected in Bedrrom
+      message: Person Detected in Bedroom
       title: Bedroom Activity Detected
       data:
-        channel: Outdoor Activity
+        channel: Indoor Activity
         group: motion_detection
-        image: '{{ trigger.payload }}'
+        image: /local/snapshots/{{ image_file }}.jpg
+        actions:
+        - action: VIEW
+          title: View Recording
+          uri: http://athena.dgtlu.net:8090/streamFile.cgi?oid={{ trigger.payload_json.oid
+            }}&ot=2&fn={{ trigger.payload_json.file }}
   mode: single
   max_exceeded: silent
+- id: '1767242164550'
+  alias: Cleanup Old Snapshots
+  description: ''
+  triggers:
+  - trigger: time
+    at: 03:00:00
+  actions:
+  - action: shell_command.cleanup_snapshots
+    data: {}
+- id: '1767253364578'
+  alias: Sync Assist Entities to Alexa
+  description: ''
+  triggers:
+  - event_type: homeassistant_started
+    trigger: event
+  - event_type: sync_alexa_entities
+    trigger: event
+  - at: 03:00:00
+    trigger: time
+  actions:
+  - delay: 10
+  - action: shell_command.sync_to_alexa
+  - delay: 5
+  - action: persistent_notification.create
+    data:
+      message: Alexa sync complete. Say 'Alexa, discover devices'

+ 41 - 0
scripts/sync_to_alexa.py

@@ -0,0 +1,41 @@
+#!/usr/bin/env python3
+import json
+import urllib.request
+
+TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhNTk3MGM3YTQxNTE0YjZhYjg1OTNjZjJjMWY2NGQ0MyIsImlhdCI6MTc2NzI1OTE1MCwiZXhwIjoyMDgyNjE5MTUwfQ.hjng9QODqQsGLly3OXCKp7f5CPM6XcpgRLztVnPynTU"
+HA_URL = "http://localhost:8123"
+
+# Read entity registry
+with open('/config/.storage/core.entity_registry', 'r') as f:
+    registry = json.load(f)
+
+# Find entities exposed to conversation
+exposed = []
+for entity in registry['data']['entities']:
+    if entity.get('options', {}).get('conversation', {}).get('should_expose'):
+        exposed.append(entity['entity_id'])
+
+# Expose each to Alexa
+for entity_id in exposed:
+    data = json.dumps({
+        "entity_id": entity_id,
+        "assistants": ["alexa"]
+    }).encode('utf-8')
+    
+    req = urllib.request.Request(
+        f"{HA_URL}/api/services/homeassistant/expose_entity",
+        data=data,
+        headers={
+            'Authorization': f'Bearer {TOKEN}',
+            'Content-Type': 'application/json'
+        },
+        method='POST'
+    )
+    
+    try:
+        urllib.request.urlopen(req, timeout=5)
+        print(f"Exposed: {entity_id}")
+    except Exception as e:
+        print(f"Failed: {entity_id} - {e}")
+
+print(f"Synced {len(exposed)} entities")

+ 19 - 0
scripts/sync_to_alexa.sh

@@ -0,0 +1,19 @@
+#!/bin/sh
+
+# Read entity registry from storage
+TOKEN="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhNTk3MGM3YTQxNTE0YjZhYjg1OTNjZjJjMWY2NGQ0MyIsImlhdCI6MTc2NzI1OTE1MCwiZXhwIjoyMDgyNjE5MTUwfQ.hjng9QODqQsGLly3OXCKp7f5CPM6XcpgRLztVnPynTU"
+
+# Parse entity registry and expose each entity
+cat /homeassistant/.storage/core.entity_registry | \
+  grep -B2 '"should_expose":true' | \
+  grep '"entity_id"' | \
+  cut -d'"' -f4 | \
+while read entity; do
+  if [ ! -z "$entity" ]; then
+    wget -q -O- --post-data="{\"entity_id\":\"$entity\",\"assistants\":[\"alexa\"]}" \
+      --header="Authorization: Bearer $TOKEN" \
+      --header="Content-Type: application/json" \
+      http://localhost:8123/api/services/homeassistant/expose_entity
+    echo "Exposed: $entity"
+  fi
+done

BIN
zigbee.db