blueprint: name: Smart Vacuum & Light Sync V1.00 description: > This Home Assistant automation synchronizes your home lights with the movements of your robot vacuum. It automatically turns on the light in the room where the vacuum is cleaning or entering, and switches it off when the vacuum leaves or stops. domain: automation input: vacuum_entity: name: "Vacuum entity" description: > Select your robot vacuum entity. Example: vacuum.l40s_pro_ultra selector: entity: domain: vacuum room_sensor: name: "Room sensor" description: > Sensor that reports the current room of the vacuum. Example: sensor.l40s_pro_ultra_current_room selector: entity: domain: sensor lights_mapping_text: name: "Room → Light mapping (JSON)" description: > JSON mapping between room names and light entities. Example: {"Bathroom": "light.lumieres_sdb", "Dining Hall": "light.lumieres_sam", "Living Room": "light.lumieres_salon", "Kitchen": "light.lumieres_cuisine"} selector: text: {} presence_entities: name: "Presence entities (optional)" description: > List of person entities to check if someone is home. Example: person.vincent default: [] selector: entity: domain: person multiple: true light_sensor: name: "Light sensor (optional)" description: > Sensor measuring ambient light (lux) to avoid turning lights on if already bright. default: "" selector: entity: domain: sensor light_threshold: name: "Light threshold (lux)" description: > Maximum lux value under which lights will turn on. Example: 100 default: 100 selector: number: min: 0 max: 10000 unit_of_measurement: lux light_brightness: name: "Light brightness (optional)" description: > Brightness percentage for lights when turned on. Leave empty to keep the last brightness state of the light. default: "" selector: number: min: 0 max: 100 step: 1 unit_of_measurement: "%" trigger: - platform: state entity_id: !input room_sensor - platform: state entity_id: !input vacuum_entity to: - cleaning - returning - paused - idle - docked - error action: - variables: room_sensor: !input room_sensor vacuum_entity: !input vacuum_entity lights_map: !input lights_mapping_text presence_entities: !input presence_entities light_sensor: !input light_sensor light_threshold: !input light_threshold light_brightness: !input light_brightness room: "{{ states[room_sensor].state }}" previous_room: "{{ trigger.from_state.state if trigger.entity_id == room_sensor else '' }}" vacuum_state: "{{ states[vacuum_entity].state }}" - choose: - conditions: - condition: template value_template: > {% set presence_ok = ( presence_entities | length == 0 or (expand(presence_entities) | selectattr('state','eq','home') | list | length == 0) ) %} {% set lux_ok = ( light_sensor == "" or (states(light_sensor) | float(0) <= light_threshold) ) %} {{ presence_ok and lux_ok }} sequence: - choose: - conditions: - condition: template value_template: "{{ vacuum_state in ['cleaning','returning'] and room in (lights_map | from_json) }}" sequence: - choose: - conditions: - condition: template value_template: "{{ light_brightness != '' }}" sequence: - service: light.turn_on data: brightness_pct: "{{ light_brightness | int }}" target: entity_id: "{{ (lights_map | from_json)[room] }}" - conditions: - condition: template value_template: "{{ light_brightness == '' }}" sequence: - service: light.turn_on target: entity_id: "{{ (lights_map | from_json)[room] }}" - choose: - conditions: - condition: template value_template: "{{ previous_room != '' and previous_room != room and previous_room in (lights_map | from_json) }}" sequence: - service: light.turn_off target: entity_id: "{{ (lights_map | from_json)[previous_room] }}" - choose: - conditions: - condition: template value_template: "{{ vacuum_state in ['paused','error','idle','docked'] and room in (lights_map | from_json) }}" sequence: - service: light.turn_off target: entity_id: "{{ (lights_map | from_json)[room] }}" mode: restart