Jelajahi Sumber

Added Kitchen Worklights

pi 2 tahun lalu
induk
melakukan
b208d51cb6
5 mengubah file dengan 57 tambahan dan 19 penghapusan
  1. 2 0
      configuration.yaml
  2. 13 15
      mqtt.yaml
  3. 33 3
      pyscript/state_goto.py
  4. 5 1
      pyscript/wall_buttons.py
  5. 4 0
      switches.yaml

+ 2 - 0
configuration.yaml

@@ -26,6 +26,8 @@ logger:
 
 mobile_app:
 
+input_button:
+
 history:
 system_health:
 

+ 13 - 15
mqtt.yaml

@@ -26,28 +26,26 @@ binary_sensor:
 
 light:
   - schema: json
-    name: "Kitchen worktop lights"
-    unique_id: "kitchen_worktop_lights"
-    state_topic: "kitchen/worktop/lights"
-    command_topic: "kitchen/worktop/lights/set"
-    availability:
-      - topic: "kitchen/worktop/lights/available"
+    name: "Kitchen worktop 4K"
+    unique_id: "kitchen_worktop_lights_4K"
+    state_topic: "kitchen/worktop/lights_4K"
+    command_topic: "kitchen/worktop/lights_4K/set"
+#    availability:
+#      - topic: "kitchen/worktop/lights_4K/available"
     retain: true
     optimistic: false
     qos: 0
     brightness_scale: 1000
-    max_mireds: 370
-    min_mireds: 250
     brightness: true
-    color_mode: true
-    supported_color_modes: ["color_temp"]
 
   - schema: json
-    name: "Kitchen test"
-    unique_id: "kitchen_test"
-    state_topic: "kitchen/worktop/lights_test"
-    command_topic: "kitchen/worktop/lights_test/set"
-    retain: false
+    name: "Kitchen worktop 27K"
+    unique_id: "kitchen_worktop_lights_27K"
+    state_topic: "kitchen/worktop/lights_27K"
+    command_topic: "kitchen/worktop/lights_27K/set"
+#    availability:
+#      - topic: "kitchen/worktop/lights_27K/available"
+    retain: true
     optimistic: false
     qos: 0
     brightness_scale: 1000

+ 33 - 3
pyscript/state_goto.py

@@ -1,4 +1,4 @@
-
+from homeassistant.const import EVENT_STATE_CHANGED
 
 def getCurrentState():
     if( light.main_button_1 == 'on' and     # All ON
@@ -39,6 +39,7 @@ def state_goto_all_on():
         light.turn_on(entity_id='light.liv_room_corner_lamp',brightness='1')
         task.sleep(0.5)
 
+    handle_kitchen_worklights()
     #pyscript.handle_bedroom_light()   # Temp disable when high energy prices
 
 
@@ -75,7 +76,8 @@ def state_goto_window():
             light.turn_on(entity_id=' light.main_button_4')
             task.sleep(0.5)
     
-    pyscript.handle_bedroom_light()
+    handle_kitchen_worklights()
+    #pyscript.handle_bedroom_light()
 
 @service
 def state_goto_morning():
@@ -113,7 +115,8 @@ def state_goto_morning():
             light.turn_on(entity_id='light.liv_room_corner_lamp',brightness='1')
             task.sleep(0.5)
     
-    pyscript.handle_bedroom_light()
+    handle_kitchen_worklights()
+    #pyscript.handle_bedroom_light()
 
 @service
 def state_goto_all_off():
@@ -134,6 +137,26 @@ def state_goto_all_off():
         light.turn_off(entity_id='light.liv_room_corner_lamp')
         task.sleep(0.5)
     input_boolean.movie_mode = 'off'
+    handle_kitchen_worklights()
+
+@state_trigger("input_boolean.kitchen_worklights")
+def kitchen_worklights_button_trigger():
+    log.info(f"Kitchen worklight changed. State: {input_boolean.kitchen_worklights}")
+    handle_kitchen_worklights()
+
+def handle_kitchen_worklights():
+    log.info("handle_kitchen_worklights")
+    if( input_boolean.kitchen_worklights == 'on' ):
+        light.turn_on(entity_id='light.kitchen_worktop_4k',brightness='63')
+        light.turn_on(entity_id='light.kitchen_worktop_27k',brightness='127')
+    elif( light.hall_door == 'on' ):
+        light.turn_off(entity_id='light.kitchen_worktop_4k')
+        light.turn_on(entity_id='light.kitchen_worktop_27k',brightness='12')
+    else:
+        light.turn_off(entity_id='light.kitchen_worktop_4k')
+        light.turn_off(entity_id='light.kitchen_worktop_27k')
+
+
 
 
 @state_trigger("input_boolean.movie_mode")
@@ -157,5 +180,12 @@ def movie_mode_button_trigger():
             task.sleep(0.5)
 
 
+@event_trigger(EVENT_STATE_CHANGED, "entity_id=='input_button.av'")
+def on_ui_button_all_off_clicken(entity_id, new_state, old_state):
+    pyscript.state_goto_all_off()
+
+@event_trigger(EVENT_STATE_CHANGED, "entity_id=='input_button.allt_pa'")
+def on_ui_button_all_on_clicken(entity_id, new_state, old_state):
+    pyscript.state_goto_all_on()
 
     

+ 5 - 1
pyscript/wall_buttons.py

@@ -44,7 +44,7 @@ got button_pressed: kwargs={
 @event_trigger( "button_pressed" )
 def hallway_wall_button(entity_id=None, state=None):
 
-    log.info(f"****************  got EVENT_CALL_SERVICE with Id:{entity_id}  State:{state}")
+    log.info(f"*************** *  got EVENT_CALL_SERVICE with Id:{entity_id}  State:{state}")
 
     if( entity_id == 'switch.hall_switch' ):
         if( switch.group_button_all == 'on'):
@@ -65,3 +65,7 @@ def hallway_wall_button(entity_id=None, state=None):
     
     if( entity_id == 'switch.mode_panel_4' ):   # All OFF
         pyscript.state_goto_all_off()
+
+    if( entity_id == 'switch.mode_panel_kwl' ):   # Kitchen work lights
+        input_boolean.toggle(entity_id='input_boolean.kitchen_worklights')
+        # This will trigger kitchen_worklights_button_trigger()

+ 4 - 0
switches.yaml

@@ -39,4 +39,8 @@
       fire_event: True
     newkaku_00001234_4:
       name: Mode panel 4
+      fire_event: True
+    
+    newkaku_00001235_1:
+      name: Mode panel KWL
       fire_event: True