ext_lights_control.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #state.persist('pyscript.ext_light_has_been_day','false')
  2. #state.persist('pyscript.ext_light_has_been_night','false')
  3. # Set that it has been midnight, and that it's ok to turn the light on
  4. #@time_trigger("once(00:30:00)")
  5. #def ext_light_has_been_night():
  6. # pyscript.ext_light_has_been_night = 'true'
  7. # pyscript.home_auto_lights_off_has_been_night = 'true'
  8. # Set that it has been noon, and that it's ok to turn off the light
  9. #@time_trigger("once(12:30:00)")
  10. #def ext_light_has_been_day():
  11. # pyscript.ext_light_has_been_day = 'true'
  12. #@state_trigger("sensor.lux_outside_the_garage != 'unknown' and int(sensor.lux_outside_the_garage) < 100", state_hold_false=0 )
  13. #def automate_exterior_lights_on_in_evening():
  14. # if( pyscript.ext_light_has_been_day == 'true' ):
  15. # pyscript.ext_light_has_been_day = 'false'
  16. # input_boolean.exterior_lights_wanted_state = 'on'
  17. #@state_trigger("sensor.lux_outside_the_garage != 'unknown' and int(sensor.lux_outside_the_garage) > 50", state_hold_false=0)
  18. #def automate_exterior_lights_off_in_morning():
  19. # if( pyscript.ext_light_has_been_night == 'true' ):
  20. # pyscript.ext_light_has_been_night = 'false'
  21. # input_boolean.exterior_lights_wanted_state = 'off'
  22. #@state_trigger("input_boolean.exterior_lights_wanted_state")
  23. #@task_unique("control_ext_light", kill_me=True)
  24. #def control_ext_light():
  25. # Set max number of iterations
  26. # maxIterations = 5
  27. # Loop until we have succeeded to controlling the light
  28. """
  29. while(
  30. ( (sensor.exterior_light_status != input_boolean.exterior_lights_wanted_state) or
  31. ( light.exterior_lights!= input_boolean.exterior_lights_wanted_state) ) and maxIterations > 0
  32. ):
  33. # Find out if we should turn the light on or off
  34. action = "turn_off" if input_boolean.exterior_lights_wanted_state == 'off' else "turn_on"
  35. service.call("light", action, entity_id="light.exterior_lights")
  36. service.call("light", action, entity_id="light.exterior_lights_repeater")
  37. log.info("Sleeping 60s.....")
  38. trig_info = task.wait_until(state_trigger=["input_boolean.exterior_lights_wanted_state","sensor.exterior_light_status"], timeout=60)
  39. maxIterations -= 1
  40. log.info(f"Exit control_ext_light")
  41. """