pi 4 anni fa
parent
commit
e0c07afd71
7 ha cambiato i file con 93 aggiunte e 28 eliminazioni
  1. 1 0
      .gitignore
  2. 8 3
      configuration.yaml
  3. 4 0
      input_booleans.yaml
  4. 8 0
      lights.yaml
  5. 10 7
      pyscript/bedroom.py
  6. 4 3
      pyscript/home_automations.py
  7. 58 15
      pyscript/state_goto.py

+ 1 - 0
.gitignore

@@ -17,6 +17,7 @@ logs
 .vscode
 .Trash-*
 deps/
+pyscript/__pycache__/
 
 # Ignored Files
 secrets.yaml

+ 8 - 3
configuration.yaml

@@ -13,9 +13,10 @@ recorder:
   purge_keep_days: 5
   db_url: mysql://hassio:hassiopassword@192.168.1.110/hass?charset=utf8
 logger:
+  default: info
   logs:
     rflink: debug
-    homeassistant.components.rflink: debug
+#    homeassistant.components.rflink: debug
 history:
 
 pyscript:
@@ -28,12 +29,16 @@ rflink:
   ignore_devices:
     - newkaku_000001_01
 
+
 binary_sensor:
    - platform: rflink
      devices:
        newkaku_02ddc7fa_4:
-        name: Bedroom door
-        device_class: door
+         name: Bedroom door
+         device_class: door
+
+   - platform: workday
+     country: SE
 
 
 # Text to speech

+ 4 - 0
input_booleans.yaml

@@ -3,3 +3,7 @@
 exterior_lights_wanted_state:
   name: Exterior lights, wanted state
   icon: mdi:lightbulb
+
+movie_mode:
+  name: Movie mode
+  icon: mdi:movie

+ 8 - 0
lights.yaml

@@ -31,4 +31,12 @@
       type: switchable
       aliases:
         - newkaku_006d7076_0
+    
+    newkaku_001ab10a_1:           # Dimmer CMR-101
+      name: Liv_room_table_lamp
+      type: switchable
+    newkaku_001ab10a_2:           # Dimmer MWMR-251
+      name: Liv_room_corner_lamp
+      type: switchable
+
 

+ 10 - 7
pyscript/bedroom.py

@@ -1,14 +1,12 @@
 
-@state_trigger("binary_sensor.bedroom_door")
-def bedroom_door_sensor():
-    log.info(f"********* BEDROOM DOOR: "+binary_sensor.bedroom_door+" ***********")
-    handle_bedroom_light()
+
+
 
 
 @service
-@task_unique("handle_bedroom_light")
 def handle_bedroom_light():
-    log.info(f"********* BEDROOM LIGHT CONTROL ***********" + light.main_button_4 + " - "+ binary_sensor.bedroom_door)
+    task.unique('handle_bedroom_light')
+    log.info(f"********* BEDROOM LIGHT CONTROL **** Btn_4:" + light.main_button_4 + " Door:"+ binary_sensor.bedroom_door)
     task.sleep(1)
     if light.main_button_4 == 'on' and binary_sensor.bedroom_door == 'on':
         # If OPEN
@@ -16,4 +14,9 @@ def handle_bedroom_light():
     else:
         switch.turn_off(entity_id='switch.tradfri_outlet')
 
-    
+
+@state_trigger("binary_sensor.bedroom_door")
+def bedroom_door_sensor():
+    task.unique('bedroom_door_sensor')
+    log.info(f"********* BEDROOM DOOR: "+binary_sensor.bedroom_door+" ***********")
+    pyscript.handle_bedroom_light()

+ 4 - 3
pyscript/home_automations.py

@@ -12,7 +12,8 @@ def automate_home_auto_lights_off():
 
 
 # Activate morning lights when Thomas gets up
-@time_trigger("once(06:20:00)")
+@time_trigger("once(06:18:00)")
 def morning_lights_thomas():
-    if switch.eng_heat_a == 'on' or switch.eng_heat_b == 'on':
-        pyscript.state_goto_morning();
+    if binary_sensor.workday_sensor == 'on':
+        if switch.eng_heat_a == 'on' or switch.eng_heat_b == 'on':
+            pyscript.state_goto_morning();

+ 58 - 15
pyscript/state_goto.py

@@ -1,4 +1,5 @@
 
+
 def getCurrentState():
     if( light.main_button_1 == 'on' and     # All ON
         light.main_button_2 == 'on' and
@@ -21,21 +22,21 @@ def getCurrentState():
         light.main_button_4 == 'off' ):
         return 4
 
-# Important info:
-#
-# We are not allowed to resend buttons 1 and 2
-# 1: Glas bulb lamp in living room
-# 2: Corner lamp (IKEA-big-bulb) in living room
-# If ON is sent multiple times, then they will change DIM mode.
-
 @service
 def state_goto_all_on():
     task.unique('state_goto_py')
-    log.info(f"********* ALL ON ***********")
+    cs = getCurrentState()
+    log.info(f"********* ALL ON *********** State: " + str(cs) )
     light.turn_on(entity_id='light.tradfri_bulb')
     for x in range(2):
         switch.turn_on(entity_id='switch.group_button_all')
-        task.sleep(1)
+        task.sleep(1.0)
+
+    if light.liv_room_table_lamp == 'off':
+        light.turn_on(entity_id='light.liv_room_table_lamp')
+        task.sleep(0.5)
+    if light.liv_room_corner_lamp == 'off':
+        light.turn_on(entity_id='light.liv_room_corner_lamp')
 
     pyscript.handle_bedroom_light()
 
@@ -44,7 +45,7 @@ def state_goto_all_on():
 def state_goto_window():
     task.unique('state_goto_py')
     cs = getCurrentState()
-    log.info(f"********* WINDOW ***********")
+    log.info(f"********* WINDOW *********** State: " + str(cs) )
     light.turn_off(entity_id='light.tradfri_bulb')
     
     if cs == 4 or cs == 2:  # From Off or already Window
@@ -59,6 +60,10 @@ def state_goto_window():
         for x in range(2):
             switch.turn_off(entity_id='switch.group_button_all')
             task.sleep(0.5)
+            light.turn_off(entity_id='light.liv_room_table_lamp')
+            task.sleep(0.5)
+            light.turn_off(entity_id='light.liv_room_corner_lamp')
+            task.sleep(0.5)
         for x in range(2):
             light.turn_on(entity_id=' light.main_button_4')
             task.sleep(0.5)
@@ -69,33 +74,71 @@ def state_goto_window():
 def state_goto_morning():
     task.unique('state_goto_py')
     cs = getCurrentState()
-    log.info(f"********* MORNING ***********")
+    log.info(f"********* MORNING *********** State: " + str(cs) )
     light.turn_off(entity_id='light.tradfri_bulb')
     if cs == 4 or cs == 3:  # Off or already Morning
         for x in range(2):
             light.turn_on(entity_id=' light.main_button_4')
             task.sleep(0.5)
-        light.turn_on(entity_id=' light.main_button_2')
+            light.turn_on(entity_id=' light.main_button_2')
+            task.sleep(0.5)
+        if light.liv_room_corner_lamp == 'off':
+            light.turn_on(entity_id='light.liv_room_corner_lamp')
     elif cs == 2:           # From Window
-        light.turn_on(entity_id=' light.main_button_2')
+        for x in range(2):
+            light.turn_on(entity_id=' light.main_button_2')
+            task.sleep(0.5)
+        if light.liv_room_corner_lamp == 'off':
+            light.turn_on(entity_id='light.liv_room_corner_lamp')
     else:                   # From ALL ON
         for x in range(2):
             switch.turn_off(entity_id='switch.group_button_all')
             task.sleep(0.5)
-        light.turn_on(entity_id=' light.main_button_2')
         for x in range(2):
+            light.turn_on(entity_id=' light.main_button_2')
+            task.sleep(0.5)
             light.turn_on(entity_id=' light.main_button_4')
             task.sleep(0.5)
+        if light.liv_room_corner_lamp == 'off':
+            light.turn_on(entity_id='light.liv_room_corner_lamp')
     
     pyscript.handle_bedroom_light()
 
 @service
 def state_goto_all_off():
     task.unique('state_goto_py')
-    log.info(f"********* ALL OFF ***********")
+    cs = getCurrentState()
+    log.info(f"********* ALL OFF *********** State: " + str(cs) )
     light.turn_off(entity_id='light.tradfri_bulb')
     switch.turn_off(entity_id='switch.tradfri_outlet')  # Sovrum OFF
     for x in range(2):
         switch.turn_off(entity_id='switch.group_button_all')
         task.sleep(0.5)
+        light.turn_off(entity_id='light.liv_room_table_lamp')
+        task.sleep(0.5)
+        light.turn_off(entity_id='light.liv_room_corner_lamp')
+        task.sleep(0.5)
+
+@state_trigger("input_boolean.movie_mode")
+def movie_mode_button_trigger():
+    cs = getCurrentState()
+    log.info(f"********* MOVIE MODE *********** To:" + input_boolean.movie_mode + " State: " + str(cs) )
+    if input_boolean.movie_mode == 'off' and switch.group_button_all == 'on':
+        log.info(f"Movie mode, turn lights ON")
+        if light.liv_room_table_lamp == 'off':
+            light.turn_on(entity_id='light.liv_room_table_lamp')
+            task.sleep(0.5)
+        if light.liv_room_corner_lamp == 'off':
+            light.turn_on(entity_id='light.liv_room_corner_lamp')
+ 
+    else:
+        log.info(f"Movie mode, turn lights OFF")
+        for x in range(2):
+            light.turn_off(entity_id='light.liv_room_table_lamp')
+            task.sleep(0.5)
+            light.turn_off(entity_id='light.liv_room_corner_lamp')
+            task.sleep(0.5)
+
+
 
+