@state_trigger("binary_sensor.bedroom_door") def bedroom_door_sensor(): log.info(f"********* BEDROOM DOOR: "+binary_sensor.bedroom_door+" ***********") handle_bedroom_light() @service @task_unique("handle_bedroom_light") def handle_bedroom_light(): log.info(f"********* BEDROOM LIGHT CONTROL ***********" + light.main_button_4 + " - "+ binary_sensor.bedroom_door) task.sleep(1) if light.main_button_4 == 'on' and binary_sensor.bedroom_door == 'on': # If OPEN switch.turn_on(entity_id='switch.tradfri_outlet') else: switch.turn_off(entity_id='switch.tradfri_outlet')