Pārlūkot izejas kodu

Add more IKEA. Play with scene trig

pi 1 gadu atpakaļ
vecāks
revīzija
09600dacd1
4 mainītis faili ar 128 papildinājumiem un 10 dzēšanām
  1. 13 0
      SERVICE_ACCOUNT.JSON
  2. 16 1
      configuration.yaml
  3. 41 9
      pyscript/state_goto.py
  4. 58 0
      scenes.yaml

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 13 - 0
SERVICE_ACCOUNT.JSON


+ 16 - 1
configuration.yaml

@@ -96,4 +96,19 @@ sql:
     query: "SELECT IF(onOff>0,'on','off') AS status FROM RemoteRxLog.nexaLog where rxTx='R' and remote_id = '20071094' and button='2' order by ts desc LIMIT 1;"
     column: 'status'
   
-  
+#google_assistant:
+#  project_id: home-assistant-7390
+#  service_account: !include SERVICE_ACCOUNT.JSON
+#  report_state: true
+#  exposed_domains:
+#    - switch
+#    - light
+#  entity_config:
+#    light.hall_door:
+#      name: main door
+#
+#home-assistant-7390
+#Alittlesecret
+#https://chef.hassio.sundby.com
+#Service acc name: thisisthomasserviceaccountname
+   

+ 41 - 9
pyscript/state_goto.py

@@ -1,6 +1,32 @@
-from homeassistant.const import EVENT_STATE_CHANGED
+from homeassistant.const import EVENT_STATE_CHANGED, EVENT_CALL_SERVICE
 from datetime import datetime, time
 
+"""
+When receiving a scene activation event (Service call)
+got EVENT_STATE_CHANGED with kwargs=
+{'trigger_type': 'event',
+ 'event_type': 'call_service', 
+ 'context': <homeassistant.core.Context object at 0x7ff02cde4800>,
+   'domain': 'scene', 
+   'service': 'turn_on',
+     'service_data': {'entity_id': 'scene.test_scene_a'}
+     }
+"""
+
+
+"""
+Also, please don't set a state variable inside a function that is trigged by EVENT_STATE_CHANGED,
+ or make a service call that is triggered by EVENT_CALL_SERVICE, unless the trigger condition is False
+ in those cases. Otherwise bad things will happen...
+"""
+@event_trigger(EVENT_CALL_SERVICE, "domain == 'scene' and service == 'turn_on'")
+def monitor_scene_service_events(domain=None, service=None, service_data=None):
+    log.info(f"Scene activated: >{service_data['entity_id']}<")
+    if( service_data['entity_id'] == 'scene.test_scene_a'):
+        log.info("Yes. It's A")
+    elif( service_data['entity_id'] == 'scene.test_scene_b'):
+        log.info("Yes. It's B")
+
 @state_trigger("input_select.light_mode")
 def monitor_service_calls(value=None):
     if not value is None:
@@ -49,12 +75,14 @@ def state_goto_all_on():
     task.unique('state_goto_py')
     log.info(f"********* ALL ON *********** State: " + input_select.light_mode )
     light.turn_on(entity_id='light.tradfri_bulb')   # Stora flyglampan
-    light.turn_on(entity_id='light.hall_inner')
-    light.turn_on(entity_id='light.hall_door')
+    light.turn_on(entity_id='light.hall_inner', brightness=38, color_temp_kelvin=3800)
+    light.turn_on(entity_id='light.hall_door', brightness=38, color_temp_kelvin=3800)
     light.turn_on(entity_id='light.rislampa')
     switch.turn_on(entity_id='switch.matsal_altandorr')
     switch.turn_on(entity_id='switch.matsal_piano')
     switch.turn_on(entity_id='switch.koksfonster')
+    switch.turn_on(entity_id='switch.sovrum')
+    
     for x in range(2):
         #light.turn_on(entity_id='light.liv_room_table_lamp',brightness='1') # Temp disable when high energy prices
         #task.sleep(0.5)
@@ -76,6 +104,7 @@ def state_goto_window():
     light.turn_off(entity_id='light.hall_inner')
     light.turn_off(entity_id='light.hall_door')
     light.turn_off(entity_id='light.rislampa')
+    switch.turn_off(entity_id='switch.sovrum')
 
     for x in range(2):
         light.turn_off(entity_id='light.liv_room_table_lamp')
@@ -91,15 +120,17 @@ def state_goto_morning():
     task.unique('state_goto_py')
     log.info(f"********* MORNING *********** State: " + str(input_select.light_mode) )
     light.turn_off(entity_id='light.tradfri_bulb')
-    switch.turn_off(entity_id='switch.matsal_altandorr')
-    switch.turn_on(entity_id='switch.matsal_piano')
-    switch.turn_on(entity_id='switch.koksfonster')
+    switch.turn_on(entity_id='switch.matsal_altandorr')
+    switch.turn_off(entity_id='switch.matsal_piano')
+    switch.turn_off(entity_id='switch.koksfonster')
     light.turn_off(entity_id='light.hall_inner')
-    light.turn_on(entity_id='light.hall_door')
+    light.turn_on(entity_id='light.hall_door', brightness=25, color_temp_kelvin=2570)
     light.turn_off(entity_id='light.rislampa')
+    switch.turn_off(entity_id='switch.sovrum')
 
     for x in range(2):
-        light.turn_on(entity_id='light.liv_room_corner_lamp',brightness='1')
+        #light.turn_on(entity_id='light.liv_room_corner_lamp',brightness='1')
+        light.turn_off(entity_id='light.liv_room_corner_lamp')
         task.sleep(0.5)
     
     pyscript.kitchen_worklights_button_trigger()
@@ -117,7 +148,8 @@ def state_goto_all_off():
     switch.turn_off(entity_id='switch.koksfonster')
     switch.turn_off(entity_id='switch.matsal_altandorr')
     switch.turn_off(entity_id='switch.matsal_piano')
-    #switch.turn_off(entity_id='switch.tradfri_outlet')  # Sovrum OFF  # Temp disable when high energy prices
+    switch.turn_off(entity_id='switch.sovrum')
+
     for x in range(2):
         #light.turn_off(entity_id='light.liv_room_table_lamp')  # Temp disable when high energy prices
         #task.sleep(0.5)

+ 58 - 0
scenes.yaml

@@ -64,3 +64,61 @@
       entity_only: true
     light.liv_room_table_lamp:
       entity_only: true
+- id: '1699285801154'
+  name: Test Scene A
+  entities:
+    light.hall_door:
+      min_color_temp_kelvin: 2202
+      max_color_temp_kelvin: 4000
+      min_mireds: 250
+      max_mireds: 454
+      supported_color_modes:
+      - color_temp
+      color_mode: color_temp
+      brightness: 217
+      color_temp_kelvin: 2590
+      color_temp: 386
+      hs_color:
+      - 28.647
+      - 69.357
+      rgb_color:
+      - 255
+      - 162
+      - 78
+      xy_color:
+      - 0.538
+      - 0.388
+      friendly_name: Hall_door
+      supported_features: 32
+      state: 'on'
+  icon: mdi:sail-boat
+  metadata: {}
+- id: '1699285823238'
+  name: Test Scene B
+  entities:
+    light.hall_door:
+      min_color_temp_kelvin: 2202
+      max_color_temp_kelvin: 4000
+      min_mireds: 250
+      max_mireds: 454
+      supported_color_modes:
+      - color_temp
+      color_mode: color_temp
+      brightness: 36
+      color_temp_kelvin: 4000
+      color_temp: 250
+      hs_color:
+      - 26.812
+      - 34.87
+      rgb_color:
+      - 255
+      - 205
+      - 166
+      xy_color:
+      - 0.421
+      - 0.364
+      friendly_name: Hall_door
+      supported_features: 32
+      state: 'on'
+  icon: mdi:ferry
+  metadata: {}