|
@@ -1,40 +1,61 @@
|
|
from homeassistant.const import EVENT_STATE_CHANGED
|
|
from homeassistant.const import EVENT_STATE_CHANGED
|
|
|
|
+from datetime import datetime, time
|
|
|
|
+
|
|
|
|
+@state_trigger("input_select.light_mode")
|
|
|
|
+def monitor_service_calls(value=None):
|
|
|
|
+ if not value is None:
|
|
|
|
+ log.info(f"Light state change to: {value}")
|
|
|
|
+ if value == 'All on':
|
|
|
|
+ log.info("Go to All on")
|
|
|
|
+ pyscript.state_goto_all_on()
|
|
|
|
+ elif value == 'All off':
|
|
|
|
+ log.info("Go to All off")
|
|
|
|
+ pyscript.state_goto_all_off()
|
|
|
|
+ elif value == 'Morning':
|
|
|
|
+ log.info("Go to Morning")
|
|
|
|
+ pyscript.state_goto_morning()
|
|
|
|
+ elif value == 'Windows':
|
|
|
|
+ log.info("Go to Windows")
|
|
|
|
+ pyscript.state_goto_window()
|
|
|
|
+ else:
|
|
|
|
+ log.info("Light state was None")
|
|
|
|
+
|
|
|
|
+@service
|
|
|
|
+def handleWallButtonPressed():
|
|
|
|
+ log.info(f"The wall button has been pressed. Curr state: {input_select.light_mode}")
|
|
|
|
+
|
|
|
|
+ currHour = datetime.now().time().hour
|
|
|
|
+
|
|
|
|
+ if( input_select.light_mode == 'All on' ):
|
|
|
|
+ input_select.light_mode = 'All off'
|
|
|
|
+
|
|
|
|
+ elif( input_select.light_mode == 'Morning' ):
|
|
|
|
+ input_select.light_mode = 'All off'
|
|
|
|
+
|
|
|
|
+ elif( input_select.light_mode == 'All off' ):
|
|
|
|
+
|
|
|
|
+ log.info(f'Is All off. Hour is: {currHour}')
|
|
|
|
+ if( currHour == 5 or currHour == 6 ):
|
|
|
|
+ input_select.light_mode = 'Morning'
|
|
|
|
+ else:
|
|
|
|
+ input_select.light_mode = 'All on'
|
|
|
|
+
|
|
|
|
+ elif( input_select.light_mode == 'Windows' ):
|
|
|
|
+ input_select.light_mode = 'All on'
|
|
|
|
|
|
-def getCurrentState():
|
|
|
|
- if( light.main_button_1 == 'on' and # All ON
|
|
|
|
- light.main_button_2 == 'on' and
|
|
|
|
- light.main_button_3 == 'on' and
|
|
|
|
- light.main_button_4 == 'on' ):
|
|
|
|
- return 1
|
|
|
|
- elif( light.main_button_1 == 'off' and # Window
|
|
|
|
- light.main_button_2 == 'off' and
|
|
|
|
- light.main_button_3 == 'off' and
|
|
|
|
- light.main_button_4 == 'on' ):
|
|
|
|
- return 2
|
|
|
|
- elif( light.main_button_1 == 'off' and # Morning
|
|
|
|
- light.main_button_2 == 'on' and
|
|
|
|
- light.main_button_3 == 'off' and
|
|
|
|
- light.main_button_4 == 'on' ):
|
|
|
|
- return 3
|
|
|
|
- elif( light.main_button_1 == 'off' and # All OFF
|
|
|
|
- light.main_button_2 == 'off' and
|
|
|
|
- light.main_button_3 == 'off' and
|
|
|
|
- light.main_button_4 == 'off' ):
|
|
|
|
- return 4
|
|
|
|
|
|
|
|
@service
|
|
@service
|
|
def state_goto_all_on():
|
|
def state_goto_all_on():
|
|
task.unique('state_goto_py')
|
|
task.unique('state_goto_py')
|
|
- cs = getCurrentState()
|
|
|
|
- log.info(f"********* ALL ON *********** State: " + str(cs) )
|
|
|
|
|
|
+ log.info(f"********* ALL ON *********** State: " + input_select.light_mode )
|
|
light.turn_on(entity_id='light.tradfri_bulb') # Stora flyglampan
|
|
light.turn_on(entity_id='light.tradfri_bulb') # Stora flyglampan
|
|
light.turn_on(entity_id='light.hall_inner')
|
|
light.turn_on(entity_id='light.hall_inner')
|
|
light.turn_on(entity_id='light.hall_door')
|
|
light.turn_on(entity_id='light.hall_door')
|
|
- #switch.turn_on(entity_id='switch.matsal')
|
|
|
|
|
|
+ light.turn_on(entity_id='light.rislampa')
|
|
|
|
+ switch.turn_on(entity_id='switch.matsal_altandorr')
|
|
|
|
+ switch.turn_on(entity_id='switch.matsal_piano')
|
|
switch.turn_on(entity_id='switch.koksfonster')
|
|
switch.turn_on(entity_id='switch.koksfonster')
|
|
for x in range(2):
|
|
for x in range(2):
|
|
- switch.turn_on(entity_id='switch.group_button_all')
|
|
|
|
- task.sleep(0.5)
|
|
|
|
#light.turn_on(entity_id='light.liv_room_table_lamp',brightness='1') # Temp disable when high energy prices
|
|
#light.turn_on(entity_id='light.liv_room_table_lamp',brightness='1') # Temp disable when high energy prices
|
|
#task.sleep(0.5)
|
|
#task.sleep(0.5)
|
|
light.turn_on(entity_id='light.liv_room_corner_lamp',brightness='1')
|
|
light.turn_on(entity_id='light.liv_room_corner_lamp',brightness='1')
|
|
@@ -47,36 +68,20 @@ def state_goto_all_on():
|
|
@service
|
|
@service
|
|
def state_goto_window():
|
|
def state_goto_window():
|
|
task.unique('state_goto_py')
|
|
task.unique('state_goto_py')
|
|
- cs = getCurrentState()
|
|
|
|
- log.info(f"********* WINDOW *********** State: " + str(cs) )
|
|
|
|
|
|
+ log.info(f"********* WINDOW *********** State: " + input_select.light_mode )
|
|
light.turn_off(entity_id='light.tradfri_bulb')
|
|
light.turn_off(entity_id='light.tradfri_bulb')
|
|
- #switch.turn_off(entity_id='switch.matsal')
|
|
|
|
switch.turn_on(entity_id='switch.koksfonster')
|
|
switch.turn_on(entity_id='switch.koksfonster')
|
|
|
|
+ switch.turn_off(entity_id='switch.matsal_altandorr')
|
|
|
|
+ switch.turn_off(entity_id='switch.matsal_piano')
|
|
light.turn_off(entity_id='light.hall_inner')
|
|
light.turn_off(entity_id='light.hall_inner')
|
|
light.turn_off(entity_id='light.hall_door')
|
|
light.turn_off(entity_id='light.hall_door')
|
|
|
|
+ light.turn_off(entity_id='light.rislampa')
|
|
|
|
|
|
-
|
|
|
|
- if cs == 4 or cs == 2: # From Off or already Window
|
|
|
|
- for x in range(2):
|
|
|
|
- light.turn_on(entity_id=' light.main_button_4')
|
|
|
|
- task.sleep(0.5)
|
|
|
|
- elif cs == 3: # From morning
|
|
|
|
- for x in range(2):
|
|
|
|
- light.turn_off(entity_id=' light.main_button_2')
|
|
|
|
- task.sleep(0.5)
|
|
|
|
- light.turn_off(entity_id='light.liv_room_corner_lamp')
|
|
|
|
- task.sleep(0.5)
|
|
|
|
- else: # From ALL ON
|
|
|
|
- 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)
|
|
|
|
|
|
+ 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)
|
|
|
|
|
|
pyscript.kitchen_worklights_button_trigger()
|
|
pyscript.kitchen_worklights_button_trigger()
|
|
#pyscript.handle_bedroom_light()
|
|
#pyscript.handle_bedroom_light()
|
|
@@ -84,39 +89,18 @@ def state_goto_window():
|
|
@service
|
|
@service
|
|
def state_goto_morning():
|
|
def state_goto_morning():
|
|
task.unique('state_goto_py')
|
|
task.unique('state_goto_py')
|
|
- cs = getCurrentState()
|
|
|
|
- log.info(f"********* MORNING *********** State: " + str(cs) )
|
|
|
|
|
|
+ log.info(f"********* MORNING *********** State: " + str(input_select.light_mode) )
|
|
light.turn_off(entity_id='light.tradfri_bulb')
|
|
light.turn_off(entity_id='light.tradfri_bulb')
|
|
- #switch.turn_off(entity_id='switch.matsal')
|
|
|
|
|
|
+ switch.turn_off(entity_id='switch.matsal_altandorr')
|
|
|
|
+ switch.turn_on(entity_id='switch.matsal_piano')
|
|
switch.turn_on(entity_id='switch.koksfonster')
|
|
switch.turn_on(entity_id='switch.koksfonster')
|
|
light.turn_off(entity_id='light.hall_inner')
|
|
light.turn_off(entity_id='light.hall_inner')
|
|
light.turn_on(entity_id='light.hall_door')
|
|
light.turn_on(entity_id='light.hall_door')
|
|
|
|
+ light.turn_off(entity_id='light.rislampa')
|
|
|
|
|
|
- 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')
|
|
|
|
- task.sleep(0.5)
|
|
|
|
- light.turn_on(entity_id='light.liv_room_corner_lamp',brightness='1')
|
|
|
|
- task.sleep(0.5)
|
|
|
|
- elif cs == 2: # From Window
|
|
|
|
- for x in range(2):
|
|
|
|
- light.turn_on(entity_id=' light.main_button_2')
|
|
|
|
- task.sleep(0.5)
|
|
|
|
- light.turn_on(entity_id='light.liv_room_corner_lamp',brightness='1')
|
|
|
|
- task.sleep(0.5)
|
|
|
|
- else: # From ALL ON
|
|
|
|
- for x in range(2):
|
|
|
|
- switch.turn_off(entity_id='switch.group_button_all')
|
|
|
|
- task.sleep(0.5)
|
|
|
|
- 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)
|
|
|
|
- light.turn_on(entity_id='light.liv_room_corner_lamp',brightness='1')
|
|
|
|
- task.sleep(0.5)
|
|
|
|
|
|
+ for x in range(2):
|
|
|
|
+ light.turn_on(entity_id='light.liv_room_corner_lamp',brightness='1')
|
|
|
|
+ task.sleep(0.5)
|
|
|
|
|
|
pyscript.kitchen_worklights_button_trigger()
|
|
pyscript.kitchen_worklights_button_trigger()
|
|
#pyscript.handle_bedroom_light()
|
|
#pyscript.handle_bedroom_light()
|
|
@@ -124,18 +108,17 @@ def state_goto_morning():
|
|
@service
|
|
@service
|
|
def state_goto_all_off():
|
|
def state_goto_all_off():
|
|
task.unique('state_goto_py')
|
|
task.unique('state_goto_py')
|
|
- cs = getCurrentState()
|
|
|
|
- log.info(f"********* ALL OFF *********** State: " + str(cs) )
|
|
|
|
|
|
+ log.info(f"********* ALL OFF *********** State: " + input_select.light_mode )
|
|
light.turn_off(entity_id='light.tradfri_bulb')
|
|
light.turn_off(entity_id='light.tradfri_bulb')
|
|
light.turn_off(entity_id='light.hall_inner')
|
|
light.turn_off(entity_id='light.hall_inner')
|
|
light.turn_off(entity_id='light.hall_door')
|
|
light.turn_off(entity_id='light.hall_door')
|
|
|
|
+ light.turn_off(entity_id='light.rislampa')
|
|
|
|
|
|
switch.turn_off(entity_id='switch.koksfonster')
|
|
switch.turn_off(entity_id='switch.koksfonster')
|
|
- #switch.turn_off(entity_id='switch.matsal') # Temp disable when high energy prices
|
|
|
|
|
|
+ switch.turn_off(entity_id='switch.matsal_altandorr')
|
|
|
|
+ switch.turn_off(entity_id='switch.matsal_piano')
|
|
#switch.turn_off(entity_id='switch.tradfri_outlet') # Sovrum OFF # Temp disable when high energy prices
|
|
#switch.turn_off(entity_id='switch.tradfri_outlet') # Sovrum OFF # Temp disable when high energy prices
|
|
for x in range(2):
|
|
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') # Temp disable when high energy prices
|
|
#light.turn_off(entity_id='light.liv_room_table_lamp') # Temp disable when high energy prices
|
|
#task.sleep(0.5)
|
|
#task.sleep(0.5)
|
|
light.turn_off(entity_id='light.liv_room_corner_lamp')
|
|
light.turn_off(entity_id='light.liv_room_corner_lamp')
|
|
@@ -144,13 +127,10 @@ def state_goto_all_off():
|
|
pyscript.kitchen_worklights_button_trigger()
|
|
pyscript.kitchen_worklights_button_trigger()
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
@state_trigger("input_boolean.movie_mode")
|
|
@state_trigger("input_boolean.movie_mode")
|
|
def movie_mode_button_trigger():
|
|
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 *********** To:" + input_boolean.movie_mode + " State: " + input_select.light_mode )
|
|
|
|
+ if input_boolean.movie_mode == 'off' and input_select.light_mode == 'All on':
|
|
log.info(f"Movie mode, turn lights ON")
|
|
log.info(f"Movie mode, turn lights ON")
|
|
for x in range(2):
|
|
for x in range(2):
|
|
light.turn_on(entity_id='light.liv_room_table_lamp',brightness='1')
|
|
light.turn_on(entity_id='light.liv_room_table_lamp',brightness='1')
|
|
@@ -167,12 +147,3 @@ def movie_mode_button_trigger():
|
|
task.sleep(0.5)
|
|
task.sleep(0.5)
|
|
|
|
|
|
|
|
|
|
-@event_trigger(EVENT_STATE_CHANGED, "entity_id=='input_button.av'")
|
|
|
|
-def on_ui_button_all_off_clicked(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_clicked(entity_id, new_state, old_state):
|
|
|
|
- pyscript.state_goto_all_on()
|
|
|
|
-
|
|
|
|
-
|
|
|