| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- @time_trigger("once(12:30:00)")
- def set_has_been_day_flag(**kwargs):
- # Set ext_light_has_been_day flag at 12:30 every day.
- log.info("Setting ext_light_has_been_day = ON (daily reset at 12:30)")
- input_boolean.ext_light_has_been_day = 'on'
- @time_trigger("once(00:30:00)")
- def set_has_been_night_flag(**kwargs):
- # Set night flags at 00:30 every day.
- log.info("Setting has_been_night flags = ON (00:30)")
- input_boolean.ext_light_has_been_night = 'on'
- input_boolean.home_auto_lights_off_has_been_night = 'on'
- @state_trigger("sensor.outside_lux != 'unknown' and int(sensor.outside_lux) > 710", state_hold_false=0)
- @state_active("input_boolean.ext_light_has_been_night == 'on'")
- def turn_off_exterior_lights_morning(**kwargs):
- # Turn off exterior lights in the morning when lux goes above 710.
- log.info(f"Lux {sensor.outside_lux} > 710, turning off exterior lights")
- input_boolean.ext_light_has_been_night = 'off'
- input_boolean.exterior_lights_wanted_state = 'off'
- @state_trigger("sensor.outside_lux != 'unknown' and int(sensor.outside_lux) < 500", state_hold_false=0)
- @state_active("input_boolean.ext_light_has_been_day == 'on'")
- def turn_on_exterior_lights_evening(**kwargs):
- # Turn on exterior lights in the evening when lux drops below 500.
- log.info(f"Lux {sensor.outside_lux} < 500, turning on exterior lights")
- input_boolean.ext_light_has_been_day = 'off'
- input_boolean.exterior_lights_wanted_state = 'on'
- @state_trigger("input_boolean.exterior_lights_wanted_state")
- @task_unique("control_ext_light", kill_me=True)
- def sync_exterior_lights(value=None, **kwargs):
-
- # Keep exterior lights in sync with wanted state (input_boolean).
- action = "turn_off" if input_boolean.exterior_lights_wanted_state == 'off' else "turn_on"
- isChristmas = True if input_boolean.christmas == 'on' else False
- log.info(f"sync_exterior_lights input: {value} Action: {action} Christmas:{isChristmas}")
- service.call("switch", action, entity_id="switch.1_mini_gen3_wood_shed")
- service.call("switch", action, entity_id="switch.1_mini_gen3_front_door")
- if isChristmas:
- max_iterations = 3
- iteration = 1
- while(
- ( (sensor.exterior_light_status != input_boolean.exterior_lights_wanted_state) or
- (light.exterior_lights != input_boolean.exterior_lights_wanted_state) ) and
- iteration < max_iterations ):
- log.info(f"Christmas lights sync iteration {iteration} of {max_iterations}. Action: {action}, exterior_light_status: {sensor.exterior_light_status}, exterior_lights: {light.exterior_lights}, wanted_state: {input_boolean.exterior_lights_wanted_state}")
- service.call("light", action, entity_id="light.exterior_lights")
- service.call("light", action, entity_id="light.exterior_lights_repeater")
- log.info("Sleeping 6s.....")
- trig_info = task.wait_until(state_trigger=["input_boolean.exterior_lights_wanted_state","sensor.exterior_light_status"], timeout=6)
- log.info(f"Woke up from wait_until: {trig_info}")
- iteration += 1
- @service
- def thomas_testing():
- log.info(f"Running Thomas testing service {int(sensor.outside_lux)}")
- #set_has_been_day_flag()
|