1234567891011121314151617181920212223242526 |
- @state_trigger("input_boolean.piano_light_wanted_state")
- @task_unique("piano_light_control", kill_me=True)
- def control_piano_light():
- # Set max number of iterations
- maxIterations = 10
- # Loop until we have succeeded to controlling the light
- while(
- ( (sensor.piano_lamp_repeater_status != input_boolean.piano_light_wanted_state) or
- ( light.piano_lamp!= input_boolean.piano_light_wanted_state) ) and maxIterations > 0
- ):
- # Find out if we should turn the light on or off
- action = "turn_off" if input_boolean.piano_light_wanted_state == 'off' else "turn_on"
-
- service.call("light", action, entity_id="light.piano_lamp")
- service.call("light", action, entity_id="light.piano_lamp_repeater")
- log.info("Sleeping 60s.....")
- trig_info = task.wait_until(state_trigger=["input_boolean.piano_light_wanted_state","sensor.piano_lamp_repeater_status"], timeout=60)
- maxIterations -= 1
-
- log.info(f"Exit control_piano_light")
|