kitchen.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from homeassistant.const import EVENT_STATE_CHANGED
  2. # Reacts to when the Kitchen Worklights button is changed
  3. # This could be from HA UI or from web-interface
  4. @state_trigger("input_boolean.kitchen_worklights")
  5. def kitchen_worklights_button_trigger():
  6. log.info(f"Kitchen worklight changed. State: {input_boolean.kitchen_worklights}")
  7. if( input_boolean.kitchen_worklights=='on' or light.hall_door == 'on' ):
  8. log.info("Kitchen LED: Sec switch ON")
  9. if( switch.kok_led_sec_switch == 'on' ):
  10. log.info("K LED Sec Switch already On, go directly to PWW-Control")
  11. handle_kitchen_worklights()
  12. else:
  13. switch.turn_on(entity_id='switch.kok_led_sec_switch')
  14. else:
  15. log.info("Kitchen LED: Sec switch OFF")
  16. switch.turn_off(entity_id='switch.kok_led_sec_switch')
  17. # Triggers when the IKEA Switch changes state. Goes On or Off
  18. @event_trigger(EVENT_STATE_CHANGED, "entity_id=='switch.kok_led_sec_switch'")
  19. def kitchen_worklights_security_switch_trigger(entity_id, new_state, old_state):
  20. log.info(f"kitchen_worklights_security_switch_trigger() {switch.kok_led_sec_switch}")
  21. if( switch.kok_led_sec_switch=='on' ):
  22. log.info("Kitchen LED: Control PWM Wait...")
  23. task.sleep(0.5)
  24. log.info("Kitchen LED: Go....")
  25. handle_kitchen_worklights()
  26. # Controls the PWM of the kitchen workbench LED-Strips
  27. # Does not control the IKEA Switch that turns everything On/Off
  28. def handle_kitchen_worklights():
  29. log.info(f"handle_kitchen_worklights WL:{input_boolean.kitchen_worklights} HALL:{light.hall_door}")
  30. if( input_boolean.kitchen_worklights == 'on' ):
  31. log.info("K LED Full mode...")
  32. light.turn_on(entity_id='light.kitchen_worktop_4k',brightness='63')
  33. light.turn_on(entity_id='light.kitchen_worktop_27k',brightness='127')
  34. elif( light.hall_door == 'on' ):
  35. log.info("K LED Soft mode...")
  36. light.turn_off(entity_id='light.kitchen_worktop_4k')
  37. light.turn_on(entity_id='light.kitchen_worktop_27k',brightness='12')
  38. else:
  39. log.info("K LED Off mode...")
  40. light.turn_off(entity_id='light.kitchen_worktop_4k')
  41. light.turn_off(entity_id='light.kitchen_worktop_27k')