Kaynağa Gözat

Fixed bug and added documentation for kitchen LED

pi 2 yıl önce
ebeveyn
işleme
5e6425d7d1
2 değiştirilmiş dosya ile 41 ekleme ve 4 silme
  1. 37 0
      pyscript/kitchen.py
  2. 4 4
      pyscript/state_goto.py

+ 37 - 0
pyscript/kitchen.py

@@ -1,7 +1,44 @@
 from homeassistant.const import EVENT_STATE_CHANGED
 
+"""
+Kitchen LED Documentation:
+Kitchen worktop lights use two different LED-Strips with two different color temperatures:
+2700 and 4000K. They are controlled individually with two MOSFET PWM controllers.
+The PWM-controller (STM32-board) receives its information via a serial line (9600) from
+the Pi3. The Pi3 sends data in ASCII format <1234ABCD> to control the 2 channels.
+The Pi3 has a Python-script running as a service kitchen_led.service that acts like two separate
+Home Assistant MQTT Lights: "Kitchen worktop 4K" and "Kitchen worktop 27K". They can be
+controller with On/Off and brightness individually.
+The lights can be in 3 different modes: 1:Off, 2:Soft and 3:Work
+
+3:Work is controlled by a manual switch (a helper) called "input_boolean.kitchen_worklights"
+When change the value of the switch the function kitchen_worklights_button_trigger() reacts
+to the events and start a control-chain.
+
+2:Soft and 1:Off is controller when the household lights are changed between different modes.
+The function kitchen_worklights_button_trigger() is called directly from these goto-mode-functions.
+
+As a security measure the whole Power Supply to the LED-controller is electrically controlled
+with an IKEA Switch. So when the LEDs are Off, then the circuit is fully electrically Off.
+
+The full chain is:
+1. Either by trigger or functional call the function kitchen_worklights_button_trigger() is called.
+It checks if the LEDs are to be one of the On-modes or Off. It then controls the IKEA Switch to turn the
+whole Kitchen LED on or off (electrically with a relay in the IKEA Switch). 
+If the IKEA Switch was already On, then it calls handle_kitchen_worklights()
+
+2. If the IKEA Switch was off and was turned on in step 1, then the event-trigger-function
+kitchen_worklights_security_switch_trigger() reacts to that state-change.
+If change Off-On then it waits a samll time before calling the third step handle_kitchen_worklights()
+If On-Off, then calls that function directly.
+
+3. The last step in function handle_kitchen_worklights() is controlling the two separate
+MQTT-Lights in Home Assistant to achieve the setup that is wanted in each of the three modes.
+"""
+
 # Reacts to when the Kitchen Worklights button is changed
 # This could be from HA UI or from web-interface
+@service
 @state_trigger("input_boolean.kitchen_worklights")
 def kitchen_worklights_button_trigger():
     log.info(f"Kitchen worklight changed. State: {input_boolean.kitchen_worklights}")

+ 4 - 4
pyscript/state_goto.py

@@ -40,7 +40,7 @@ def state_goto_all_on():
         light.turn_on(entity_id='light.liv_room_corner_lamp',brightness='1')
         task.sleep(0.5)
 
-    kitchen_worklights_button_trigger()
+    pyscript.kitchen_worklights_button_trigger()
     #pyscript.handle_bedroom_light()   # Temp disable when high energy prices
 
 
@@ -78,7 +78,7 @@ def state_goto_window():
             light.turn_on(entity_id=' light.main_button_4')
             task.sleep(0.5)
     
-    kitchen_worklights_button_trigger()
+    pyscript.kitchen_worklights_button_trigger()
     #pyscript.handle_bedroom_light()
 
 @service
@@ -118,7 +118,7 @@ def state_goto_morning():
             light.turn_on(entity_id='light.liv_room_corner_lamp',brightness='1')
             task.sleep(0.5)
     
-    kitchen_worklights_button_trigger()
+    pyscript.kitchen_worklights_button_trigger()
     #pyscript.handle_bedroom_light()
 
 @service
@@ -141,7 +141,7 @@ def state_goto_all_off():
         light.turn_off(entity_id='light.liv_room_corner_lamp')
         task.sleep(0.5)
     input_boolean.movie_mode = 'off'
-    kitchen_worklights_button_trigger()
+    pyscript.kitchen_worklights_button_trigger()