alias: Master Bathroom Lights to On id: automation_master_bathroom_lights_to_on mode: single # Hide warnings when triggered while in delay. max_exceeded: silent trigger: - platform: state entity_id: - input_select.master_bathroom_mode - input_select.automatic_light_profile - platform: state entity_id: input_boolean.bathroom_occupied to: "on" # Only turn on the lights when necessary condition: - condition: or conditions: # Either when motion is detected - condition: template value_template: "{{ trigger.entity_id == 'input_boolean.bathroom_occupied' }}" # Or when the scene changes while the lights are already on - condition: and conditions: - condition: or conditions: - condition: template value_template: "{{ trigger.entity_id == 'input_select.master_bathroom_mode' }}" - condition: template value_template: "{{ trigger.entity_id == 'input_select.automatic_light_profile' }}" - condition: state entity_id: input_boolean.bathroom_occupied state: "on" variables: switch_name: switch.master_bathroom_motion_switch light_name: master_bathroom_hue mode_name: input_select.master_bathroom_mode action: - alias: "Make sure Z-Wave switch is turned on" action: homeassistant.turn_on target: entity_id: - switch.master_bathroom_motion_switch - switch.master_bathroom_switch - choose: - alias: "If the room is set to manual, just turn the lights on" conditions: - alias: "Room set to manual" condition: state entity_id: input_select.master_bathroom_mode state: Manual sequence: - action: light.turn_on target: entity_id: light.master_bathroom_hue - alias: "If the room is set to auto and the lights are on, change to the Automatic Light Profile scene with a transition" conditions: - alias: "Room set to auto" condition: state entity_id: input_select.master_bathroom_mode state: Auto - alias: "Lights are on" condition: state entity_id: light.master_bathroom_hue state: "on" sequence: - action: scene.turn_on data: transition: "{{ states('input_number.light_scene_transition') }}" target: entity_id: "scene.{{light_name}}_{{states('input_select.automatic_light_profile').lower().replace(' ','_')}}" - alias: "If the room is set to auto and the lights are off, change to the Automatic Light Profile scene without a transition" conditions: - alias: "Room set to auto" condition: state entity_id: input_select.master_bathroom_mode state: Auto - alias: "Lights are off" condition: state entity_id: light.master_bathroom_hue state: "off" sequence: - action: scene.turn_on target: entity_id: "scene.{{light_name}}_{{states('input_select.automatic_light_profile').lower().replace(' ','_')}}" - alias: "If the room is not set to auto and the lights are on, change to the Master Bathroom Mode scene with a transition" conditions: - alias: "Room not manual or auto and lights are on" condition: state entity_id: light.master_bathroom_hue state: "on" sequence: - action: scene.turn_on data: transition: "{{ states('input_number.light_scene_transition') }}" target: entity_id: "scene.{{light_name}}_{{states(mode_name).lower().replace(' ','_')}}" - alias: "If the room is not set to auto and the lights are on, change to the Master Bathroom Mode scene without a transition" conditions: - alias: "Room not manual or auto and lights are off" condition: state entity_id: light.master_bathroom_hue state: "off" sequence: - action: scene.turn_on target: entity_id: "scene.{{light_name}}_{{states(mode_name).lower().replace(' ','_')}}" - delay: 1