From 89f8b3bf9d54a5c0d67c0189e1aec8e94cd91824 Mon Sep 17 00:00:00 2001
From: Przemek Grondek <przemek@grondek.pl>
Date: Fri, 5 Aug 2022 00:09:51 +0200
Subject: [PATCH] Kitchen lights cleanup

---
 configuration/automations/kitchen-button.yaml | 77 +------------------
 configuration/automations/kitchen-motion.yaml | 62 +--------------
 scripts/94.lights-kitchen.yaml                | 67 ++++++++++++++++
 3 files changed, 72 insertions(+), 134 deletions(-)
 create mode 100644 scripts/94.lights-kitchen.yaml

diff --git a/configuration/automations/kitchen-button.yaml b/configuration/automations/kitchen-button.yaml
index ebc8edb..b52ba59 100644
--- a/configuration/automations/kitchen-button.yaml
+++ b/configuration/automations/kitchen-button.yaml
@@ -10,43 +10,7 @@
       type: remote_button_short_press
       subtype: button_1
   action:
-    - choose:
-        - conditions:
-            - condition: state
-              entity_id: input_select.home_mode
-              state: Day
-          sequence:
-            - choose:
-                - conditions:
-                    - condition: state
-                      entity_id: input_boolean.sleep_mode
-                      state: 'on'
-                  sequence:
-                    - service: light.turn_on
-                      entity_id: light.kitchen_lights
-                      data:
-                        brightness_pct: 100
-                        kelvin: 2000
-                - conditions:
-                    - condition: state
-                      entity_id: input_boolean.sleep_mode
-                      state: 'off'
-                  sequence:
-                    - service: light.turn_on
-                      entity_id: light.kitchen_lights
-                      data:
-                        brightness_pct: 100
-                        kelvin: 3200
-        - conditions:
-            - condition: state
-              entity_id: input_select.home_mode
-              state: Night
-          sequence:
-            - service: light.turn_on
-              entity_id: light.kitchen_lights
-              data:
-                brightness_pct: 5
-                kelvin: 2700
+    - service: script.kitchen_lights_on
 
 - id: kitchen-button-2 # Upper right
   alias: '[Kitchen] Button 2'
@@ -72,9 +36,7 @@
       type: remote_button_short_press
       subtype: button_3
   action:
-    - service: light.turn_off
-      target:
-        entity_id: light.kitchen_lights
+    - service: script.kitchen_lights_off
 
 - id: kitchen-button-4 # Lower Right
   alias: '[Kitchen] Button 4'
@@ -183,38 +145,5 @@
       type: remote_button_long_press
       subtype: dim_up
   action:
-    - choose:
-        - conditions:
-            - condition: state
-              entity_id: light.kitchen_lights
-              state: 'on'
-          sequence:
-            - service: light.turn_off
-              entity_id: light.kitchen_lights
-        - conditions:
-            - condition: state
-              entity_id: light.kitchen_lights
-              state: 'off'
-          sequence:
-            - choose:
-                - conditions:
-                    - condition: state
-                      entity_id: input_boolean.sleep_mode
-                      state: 'on'
-                  sequence:
-                    - service: light.turn_on
-                      entity_id: light.kitchen_lights
-                      data:
-                        brightness_pct: 100
-                        kelvin: 2000
-                - conditions:
-                    - condition: state
-                      entity_id: input_boolean.sleep_mode
-                      state: 'off'
-                  sequence:
-                    - service: light.turn_on
-                      entity_id: light.kitchen_lights
-                      data:
-                        brightness_pct: 100
-                        kelvin: 3200
+    - service: script.kitchen_lights_on
   mode: single
diff --git a/configuration/automations/kitchen-motion.yaml b/configuration/automations/kitchen-motion.yaml
index eca7010..6318b75 100644
--- a/configuration/automations/kitchen-motion.yaml
+++ b/configuration/automations/kitchen-motion.yaml
@@ -10,49 +10,7 @@
       entity_id: binary_sensor.kitchen_tabletop_motion_detection
       to: 'on'
   action:
-    - choose:
-        - conditions:
-            - condition: state
-              entity_id: input_select.home_mode
-              state: Day
-            - condition: numeric_state
-              entity_id: sensor.office_illuminance
-              below: '150'
-          sequence:
-            - choose:
-                - conditions:
-                    - condition: state
-                      entity_id: input_boolean.sleep_mode
-                      state: 'on'
-                  sequence:
-                    - service: light.turn_on
-                      entity_id: light.kitchen_lights
-                      data:
-                        brightness_pct: 100
-                        kelvin: 2000
-                - conditions:
-                    - condition: state
-                      entity_id: input_boolean.sleep_mode
-                      state: 'off'
-                  sequence:
-                    - service: light.turn_on
-                      entity_id: light.kitchen_lights
-                      data:
-                        brightness_pct: 100
-                        kelvin: 3200
-        - conditions:
-            - condition: state
-              entity_id: input_select.home_mode
-              state: Night
-            - condition: numeric_state
-              entity_id: sensor.office_illuminance
-              below: '100'
-          sequence:
-            - service: light.turn_on
-              entity_id: light.kitchen_lights
-              data:
-                brightness_pct: 5
-                kelvin: 2700
+    - service: script.kitchen_lights_on
 
 - id: kitchen-lights-off
   alias: '[Kitchen] Lights Off'
@@ -85,20 +43,4 @@
       state: 'off'
       for: '0:02:00'
   action:
-    - service: light.turn_off
-      entity_id: light.kitchen_lights
-
-- id: kitchen-sink-light-off
-  alias: '[Kitchen] Sink light off'
-  mode: single
-  trigger:
-    - platform: state
-      entity_id: binary_sensor.kitchen_sink_motion_sensor
-      to: 'off'
-      for: '0:05:00'
-  condition: [ ]
-  action:
-    - service: light.turn_off
-      data: { }
-      target:
-        entity_id: light.kitchen_sink_lighstrip
+    - service: script.kitchen_lights_off
diff --git a/scripts/94.lights-kitchen.yaml b/scripts/94.lights-kitchen.yaml
new file mode 100644
index 0000000..af21890
--- /dev/null
+++ b/scripts/94.lights-kitchen.yaml
@@ -0,0 +1,67 @@
+kitchen_lights_toggle:
+  alias: '[Kitchen] Lights toggle'
+  sequence:
+    - choose:
+        - conditions:
+            - condition: state
+              entity_id: light.kitchen_lights
+              state: 'on'
+          sequence:
+            - service: script.kitchen_lights_off
+        - conditions:
+            - condition: state
+              entity_id: light.kitchen_lights
+              state: 'off'
+          sequence:
+            - service: script.kitchen_lights_on
+
+kitchen_lights_on:
+  alias: '[Kitchen] Lights on'
+  sequence:
+    - choose:
+        - conditions:
+            - condition: state
+              entity_id: input_select.home_mode
+              state: Day
+          sequence:
+            - choose:
+                - conditions:
+                    - condition: state
+                      entity_id: input_boolean.sleep_mode
+                      state: 'on'
+                  sequence:
+                    - service: light.turn_on
+                      entity_id: light.kitchen_lights
+                      data:
+                        brightness_pct: 100
+                        kelvin: 2000
+                - conditions:
+                    - condition: state
+                      entity_id: input_boolean.sleep_mode
+                      state: 'off'
+                  sequence:
+                    - service: light.turn_on
+                      entity_id: light.kitchen_lights
+                      data:
+                        brightness_pct: 100
+                        kelvin: 3200
+        - conditions:
+            - condition: state
+              entity_id: input_select.home_mode
+              state: Night
+          sequence:
+            - service: light.turn_on
+              entity_id: light.kitchen_lights
+              data:
+                brightness_pct: 5
+                kelvin: 2700
+
+
+kitchen_lights_off:
+  alias: '[Kitchen] Lights off'
+  sequence:
+    - service: light.turn_off
+      entity_id:
+        - light.kitchen_lights
+        - light.kitchen_sink_lighstrip
+        - switch.kitchen_big_light_switch
\ No newline at end of file