blueprint:
  name: Smart Light
  description: "# \U0001F506 Smart Light\n**Version: 2.3**\n\nSmart Lighting: Your
    Lights, Your Way - Take Control and Customize it to Perfection!\U0001F4A1✨\n\n**If
    you like my blueprints, and would like to show your support or just say thank
    you?** [Click Here](https://www.paypal.com/donate/?hosted_button_id=WAZS3QSDTPGA8)
    \U0001F642\n\n<details> <summary><b>The Automation Process:</b> \U0001F448</summary>\n\n\n
    \ - **Trigger Options:**\n\n    Activate lights, switches, scenes, and scripts
    when the automation is triggered.\n\n    - **Entity State:**\n      - Turn lights
    ON when an entity changes from OFF to ON.\n      - Turn lights OFF when an entity
    changes from ON to OFF.\n\n    - **Sun Elevation:**\n      - Turn lights ON when
    the sun's elevation falls below a set value.\n      - Turn lights OFF when the
    sun's elevation rises above a set value. \n\n    - **Ambient Light:**\n      -
    Turn lights ON when ambient light falls below a set LUX value.\n      - Turn lights
    OFF when ambient light rises above a set LUX value. \n\n    - **Time-Based Option:**\n
    \     - Define start and end times to turn lights ON and OFF.\n\n  - **Light Control
    Options:**\n      - Utilize \"Light Control\" to adjust brightness, colour temperature,
    colour, and transition times.\n\n  - **Dynamic Lighting Options:**\n    - Opt
    for 'Dynamic Lighting' to continuously adjust brightness based on lux values or
    adapt colour temperature and brightness according to the sun's changing elevation.\n\n
    \ - **Night Lights Mode:**\n    - Enable 'Night Lights' for softer illumination
    during night time activities, automatically enabled based on conditions.\n\n  -
    **Manual Override:**\n    - Use \"Bypass Options\" for manual bypassing of trigger
    sensors, providing manual control and additional customization.\n\n  - **Weekdays
    Condition Option:**\n    - Specify the weekday selections to define when the automation
    can run.\n</details>\n\nNeed help?\n- FAQ: [Click Here](https://community.home-assistant.io/t/527354/2)\n-
    Community Support Including Updates: [Click Here](https://community.home-assistant.io/t/527354)\n\nRequired
    = *\n"
  domain: automation
  input:
    trigger_entity:
      name: Trigger - Entity State
      icon: mdi:cog-outline
      collapsed: true
      input:
        include_entity_state:
          name: Use The Entity State Option (Optional)
          description: "This option adds triggers that activate when the specified
            entity changes its state. When the entity changes its state from OFF to
            ON, it will turn your lights ON. When the entity changes its state from
            ON to OFF, it will turn your lights OFF.\n\nYou can choose the ON trigger,
            the OFF trigger, or both. For more information about triggers and how
            they can be used, [Click Here](https://community.home-assistant.io/t/527354/110)\n\nIf
            you would like to use a motion sensor, please consider using my \U0001F4A1Sensor
            Light Blueprint [Click Here](https://community.home-assistant.io/t/481048)\n"
          default: []
          selector:
            select:
              multiple: true
              options:
              - label: ON State
                value: entity_on
              - label: OFF State
                value: entity_off
              sort: false
              custom_value: false
        entity_input:
          name: Input Entity
          description: 'Please select an entity with an ON/OFF state.

            '
          default: []
          selector:
            entity: {}
    trigger_sun:
      name: Trigger - Sun Elevation
      icon: mdi:weather-sunny
      collapsed: true
      input:
        include_sun:
          name: Use The Sun Option (Optional)
          description: 'This option adds triggers that activate when the sun''s elevation
            value crosses its set threshold. When it goes below the **Sun Elevation
            Falling** value, it will turn your lights ON. When it goes above the **Sun
            Elevation Rising** value, it will turn your lights OFF.


            You can choose the ON trigger, the OFF trigger, or both. For more information
            about triggers and how they can be used, [Click Here](https://community.home-assistant.io/t/527354/110)


            For more information on sun settings [Click Here](https://community.home-assistant.io/t/527354/83)

            '
          default: []
          selector:
            select:
              multiple: true
              options:
              - label: Sun Elevation Falling - ON
                value: sun_falling
              - label: Sun Elevation Rising - OFF
                value: sun_rising
              sort: false
              custom_value: false
        sun_elevation:
          name: Sun Elevation Falling
          description: 'The sun elevation falling refers to the angle between the
            sun and the horizon when the sun is setting. A negative value indicates
            that the sun is BELOW the horizon. For example, a setting guide of -1.5
            corresponds to dusk

            '
          default: -1.5
          selector:
            number:
              min: -10.0
              max: 5.0
              step: 0.5
              unit_of_measurement: degrees
              mode: slider
        sun_elevation_rising:
          name: Sun Elevation Rising
          description: 'The sun elevation rising refers to the angle between the sun
            and the horizon during sunrise. A negative value indicates that the sun
            is BELOW the horizon. For example, a setting guide of -4.0 corresponds
            to dawn.

            '
          default: -4.0
          selector:
            number:
              min: -10.0
              max: 5.0
              step: 0.5
              unit_of_measurement: degrees
              mode: slider
    trigger_ambient:
      name: Trigger - Ambient
      icon: mdi:theme-light-dark
      collapsed: true
      input:
        include_ambient:
          name: Use The Ambient Option (Optional)
          description: 'This option adds triggers that activate when the ambient light
            LUX value crosses its set threshold. When it goes below the **Low LUX
            Value**, it will turn your lights ON. When it goes above the **High LUX
            Value**, it will turn your lights OFF.


            You can choose the ON trigger, the OFF trigger, or both. For more information
            about triggers and how they can be used, [Click Here](https://community.home-assistant.io/t/527354/110)

            '
          default: []
          selector:
            select:
              multiple: true
              options:
              - label: Low Lux Value - ON
                value: ambient_low
              - label: High Lux Value - OFF
                value: ambient_high
              sort: false
              custom_value: false
        ambient_light_sensor:
          name: Ambient Light Sensor
          description: 'Select the ambient light sensor.

            '
          default: []
          selector:
            entity:
              filter:
              - domain:
                - sensor
                device_class:
                - illuminance
              multiple: false
        ambient_light_value:
          name: Ambient Light - Low Lux Value
          description: 'Set the Ambient Light Low Lux Value. The light will turn ON
            when the lux level is below the set value. This value must be equal or
            lower than the "High Lux Value" below. Guide is 20 lux (dusk).

            '
          default: 20
          selector:
            number:
              min: 0.0
              max: 500.0
              step: 10.0
              unit_of_measurement: lux
              mode: slider
        ambient_light_value_off:
          name: Ambient Light - High Lux Value
          description: 'Set the Ambient Light High Lux Value. The light will turn
            OFF when the lux level is above the set value. This value must be equal
            or higher than the "Low Lux Value" above.  Setting a value higher than
            the low value allows for an offset. Guide is 80 lux (dawn).

            '
          default: 80
          selector:
            number:
              min: 0.0
              max: 1000.0
              step: 10.0
              unit_of_measurement: lux
              mode: slider
    trigger_time:
      name: Trigger - Time
      icon: mdi:clock-outline
      collapsed: true
      input:
        include_time:
          name: Use The Time Options (Optional)
          description: 'This option adds triggers that activate when the specified
            time value crosses its set threshold. When the time is below the **ON
            Time** setting, it will turn your lights ON. When the time is above the
            **OFF Time** setting, it will turn your lights OFF.


            You can choose the ON trigger, the OFF trigger, or both. For more information
            about triggers and how they can be used, [Click Here](https://community.home-assistant.io/t/527354/110)

            '
          default: []
          selector:
            select:
              multiple: true
              options:
              - label: ON Time
                value: time_on
              - label: OFF Time
                value: time_off
              sort: false
              custom_value: false
        after_time:
          name: ON Time
          description: 'Set the on time.

            '
          default: 00:00:00
          selector:
            time: {}
        before_time:
          name: OFF Time
          description: 'Set the off time.

            '
          default: 00:00:00
          selector:
            time: {}
    lights:
      name: Lights *
      icon: mdi:lightbulb-outline
      collapsed: true
      input:
        light_switch:
          name: Lights - Switches - Scenes - Scripts *
          description: 'The lights, switches, scenes, and scripts that will be activated
            by the trigger. If adding a scene or script, please refer to the ''Scenes
            & Scripts - Toggle Helper'' section and the ''Scenes & Scripts - Turn
            OFF'' section below.


            **NOTE** - You can only use entities. Areas, devices and labels are not
            supported.

            '
          default: []
          selector:
            target:
              entity:
              - domain:
                - light
                - switch
                - scene
                - script
        boolean_scenes_scripts:
          name: Scenes & Scripts - Toggle Helper
          description: 'To ensure the smooth operation of the automation, it''s recommended
            to create an independent toggle helper when selecting a scene or script
            in "Lights - Switches - Scenes - Scripts" above and then enter it here.

            '
          default: []
          selector:
            entity:
              filter:
              - domain:
                - input_boolean
              multiple: false
        end_scenes:
          name: Scenes - Scripts To Turn OFF
          description: 'If you have selected a scene or a script to be turned ON above
            in "Lights - Switches - Scenes - Scripts" and you would like it to be
            turned OFF after the time delay, then you must create a scene or a script
            with everything OFF and enter it here.

            '
          default: []
          selector:
            entity:
              multiple: true
              filter:
              - domain:
                - scene
                - script
    lights_settings:
      name: Light Control
      icon: mdi:lightbulb-on-outline
      collapsed: true
      input:
        include_light_control:
          name: Use The Light Control Options (Optional)
          description: 'Select if you would like to use brightness or transition.
            These settings will only affect a ''light'' entity that supports each
            selected option. The settings for brightness and transition are provided
            below.

            '
          default: []
          selector:
            select:
              multiple: true
              options:
              - label: Use Brightness
                value: use_brightness
              - label: Use Transition
                value: use_transition
              sort: false
              custom_value: false
        light_brightness:
          name: Brightness
          description: 'The brightness setting for the lights when they are turned
            ON.

            '
          default: 100
          selector:
            number:
              min: 1.0
              max: 100.0
              mode: slider
              step: 1.0
              unit_of_measurement: '%'
        light_transition_on:
          name: Transition - ON
          description: 'The transition setting for the lights when they are turned
            ON.

            '
          default: 1
          selector:
            number:
              min: 0.0
              max: 5.0
              mode: slider
              step: 0.5
              unit_of_measurement: seconds
        light_transition_off:
          name: Transition - OFF
          description: 'The transition setting for the lights when they are turned
            OFF.

            '
          default: 1
          selector:
            number:
              min: 0.0
              max: 30.0
              mode: slider
              step: 1.0
              unit_of_measurement: seconds
        include_light_colour_control:
          name: Use The Light Colour Control Options (Optional)
          description: 'Select if you would like to use colour temperature, RGB, RGBW
            or RGBWW colour. These settings will only affect a ''light'' entity that
            supports each selected option. The settings for colour temperature, RGB,
            RGBW and RGBWW colour are provided below.

            '
          default: disable_colour_control
          selector:
            select:
              options:
              - label: Use Colour Temperature
                value: use_colour_temperature
              - label: Use RGB Colour
                value: use_rgb_colour
              - label: Use RGBW Colour
                value: use_rgbw_colour
              - label: Use RGBWW Colour
                value: use_rgbww_colour
              - label: Disable Colour Control
                value: disable_colour_control
              multiple: false
              sort: false
              custom_value: false
        light_colour_temperature:
          name: Colour Temperature
          description: 'The colour temperature setting for the lights when they are
            turned ON.

            '
          default: 5000
          selector:
            number:
              min: 2000.0
              max: 8000.0
              mode: slider
              step: 100.0
              unit_of_measurement: kelvin
        light_rgb_colour:
          name: RGB Colour
          description: 'The RGB colour setting for the lights when they are turned
            ON.

            '
          default:
          - 255
          - 255
          - 255
          selector:
            color_rgb: {}
        light_rgbw_colour:
          name: RGBW Colour
          description: 'The RGBW colour setting for the lights when they are turned
            ON. Enter four integers between 0 and 255 to define the values for Red,
            Green, Blue, and White.

            '
          default:
          - 255
          - 255
          - 255
          - 255
          selector:
            object: {}
        light_rgbww_colour:
          name: RGBWW Colour
          description: 'The RGBWW colour setting for the lights when they are turned
            ON. Enter five integers between 0 and 255 to define the values for Red,
            Green, Blue, Cold White and Warm White.

            '
          default:
          - 255
          - 255
          - 255
          - 255
          - 255
          selector:
            object: {}
    dynamic_lighting_settings:
      name: Dynamic Lighting
      icon: mdi:creation-outline
      collapsed: true
      input:
        include_dynamic_lighting:
          name: Use The Dynamic Lighting Options (Optional)
          description: 'This option aims to make continual adjustments in your lighting
            setup by modulating brightness according to floating lux values or adapting
            colour temperature and brightness based on the sun''s changing elevation.
            Choose from nine preset options available in the dropdown menu.


            1 - Lux Controlled Brightness

            2 - Lux Controlled Brightness Inverted

            3 - Sun Elevation Lighting - Colour Temp

            4 - Sun Elevation Lighting - Brightness

            5 - Sun Elevation Lighting - Brightness Inverted

            6 - Sun Elevation Lighting - Colour Temp + Brightness

            7 - Sun Elevation Lighting - Colour Temp + Brightness Inverted

            8 - Sun Elevation Lighting - Colour Temp + Lux Controlled Brightness

            9 - Sun Elevation Lighting - Colour Temp + Lux Controlled Brightness Inverted


            A numbering system has been implemented to facilitate navigation within
            the dropdown selections. Each number corresponds to a specific configuration,
            aiding users in identifying and adjusting the settings used within each
            selection. For instance, when selecting "3 - Sun Elevation Lighting -
            Colour Temp" as a dropdown option, settings marked "Used in options 3,
            6, 7, 8 or 9" are required for that respective selection because number
            3 is included in those options.


            For more information on dynamic lighting settings [Click Here](https://community.home-assistant.io/t/481048/837)

            '
          default: disable_dynamic_lighting
          selector:
            select:
              mode: dropdown
              options:
              - label: Disable Dynamic Lighting
                value: disable_dynamic_lighting
              - label: 1 - Lux Controlled Brightness
                value: enable_lux_controled_brightness
              - label: 2 - Lux Controlled Brightness Inverted
                value: enable_lux_controled_brightness_inv
              - label: 3 - Sun Elevation Lighting - Colour Temp
                value: enable_sun_elevation_colour
              - label: 4 - Sun Elevation Lighting - Brightness
                value: enable_sun_elevation_brightness
              - label: 5 - Sun Elevation Lighting - Brightness Inverted
                value: enable_sun_elevation_brightness_inv
              - label: 6 - Sun Elevation Lighting - Colour Temp + Brightness
                value: enable_sun_elevation_colour_brightness
              - label: 7 - Sun Elevation Lighting - Colour Temp + Brightness Inverted
                value: enable_sun_elevation_colour_brightness_inv
              - label: 8 - Sun Elevation Lighting - Colour Temp + Lux Controlled Brightness
                value: enable_sun_elevation_colour_lux_brightness
              - label: 9 - Sun Elevation Lighting - Colour Temp + Lux Controlled Brightness
                  Inverted
                value: enable_sun_elevation_colour_lux_brightness_inv
              multiple: false
              sort: false
              custom_value: false
        dynamic_lighting_lux_sensor:
          name: Dynamic Lighting - Ambient Light Sensor
          description: '**Used in options 1, 2, 8 or 9** - Enter the specific ambient
            light sensor to be used, based on the chosen settings.

            '
          default: []
          selector:
            entity:
              filter:
              - domain:
                - sensor
                device_class:
                - illuminance
              multiple: false
        dynamic_lighting_max_lux:
          name: Dynamic Lighting - Max Lux Value
          description: '**Used in options 1, 2, 8 or 9** - Specify the maximum lux
            value. Once the lux level meets or surpasses this set point, your lights
            will adjust to either their maximum or minimum brightness, depending on
            your chosen option.  This value indicates when you prefer your lights
            to start turning on or off.

            '
          default: 400
          selector:
            number:
              min: 10.0
              max: 900.0
              step: 10.0
              unit_of_measurement: lux
              mode: slider
        dynamic_lighting_min_lux:
          name: Dynamic Lighting - Min Lux Value
          description: '**Used in options 1, 2, 8 or 9** - Specify the minimum lux
            value. Once the lux level meets or surpasses this set point, your lights
            will adjust to either their maximum or minimum brightness, depending on
            your chosen option.  This value indicates when you prefer your lights
            to start turning on or off.

            '
          default: 40
          selector:
            number:
              min: 0.0
              max: 600.0
              step: 10.0
              unit_of_measurement: lux
              mode: slider
        dynamic_lighting_max_brightness:
          name: Dynamic Lighting - Max Brightness Value
          description: '**Used in options 1, 2, 4, 5, 6, 7, 8 or 9** - Define the
            maximum brightness value, determines the peak brightness level for your
            lights.

            '
          default: 100
          selector:
            number:
              min: 10.0
              max: 100.0
              step: 1.0
              unit_of_measurement: '%'
              mode: slider
        dynamic_lighting_min_brightness:
          name: Dynamic Lighting - Min Brightness Value
          description: '**Used in options 1, 2, 4, 5, 6, 7, 8 or 9** - Specify the
            minimum brightness value, establishing the lowest brightness level for
            your lights. When setting the brightness to 0%, the light will be turned
            off.

            '
          default: 0
          selector:
            number:
              min: 0.0
              max: 100.0
              step: 1.0
              unit_of_measurement: '%'
              mode: slider
        dynamic_lighting_boolean:
          name: Dynamic Lighting - Toggle Helper (Optional)
          description: '**Used in options 1, 2, 3, 4, 5, 6, 7, 8 or 9** - If you have
            chosen a brightness level of 0%, then it''s essential to create an independent
            toggle helper and enter it here. This toggle helper can also address issues
            if the automation doesn''t behave as expected due to the occasional unavailability
            of light entities. While it may not always be necessary, if you''re open
            to creating toggle helpers, it''s highly recommended to utilize this option
            to ensure proper functionality of the automation.

            '
          default: []
          selector:
            entity:
              filter:
              - domain:
                - input_boolean
              multiple: false
        dynamic_lighting_max_colour_temp:
          name: Dynamic Lighting - Max Colour Temperature
          description: '**Used in options 3, 6, 7, 8 or 9** - Specify the highest
            colour temperature value, determining the coolest colour setting for your
            lights.

            '
          default: 5000
          selector:
            number:
              min: 2500.0
              max: 8000.0
              mode: slider
              step: 100.0
              unit_of_measurement: kelvin
        dynamic_lighting_min_colour_temp:
          name: Dynamic Lighting - Min Colour Temperature
          description: '**Used in options 3, 6, 7, 8 or 9** - Set the lowest colour
            temperature value, defining the warmest colour setting for your lights.

            '
          default: 3000
          selector:
            number:
              min: 2000.0
              max: 7500.0
              mode: slider
              step: 100.0
              unit_of_measurement: kelvin
        dynamic_lighting_sun_elevation_start_rising:
          name: Dynamic Lighting - Sun Elevation Rising - Start Point
          description: '**Used in options 3, 4, 5, 6, 7, 8 or 9** - When the sun rises
            above the sensor''s starting point, both the colour temperature and brightness
            percentage will transition linearly from their minimum to maximum values
            until they reach the rising endpoint, based on the chosen settings.

            '
          default: -1.5
          selector:
            number:
              min: -10.0
              max: 30.0
              step: 0.5
              unit_of_measurement: degrees
              mode: slider
        dynamic_lighting_sun_elevation_end_rising:
          name: Dynamic Lighting - Sun Elevation Rising - End Point
          description: '**Used in options 3, 4, 5, 6, 7, 8 or 9** - When the sun rises
            above the sensor''s endpoint, the maximum colour temperature and maximum
            brightness value will be established according to the chosen settings.

            '
          default: 15
          selector:
            number:
              min: 0.0
              max: 90.0
              step: 0.5
              unit_of_measurement: degrees
              mode: slider
        dynamic_lighting_sun_elevation_start_falling:
          name: Dynamic Lighting - Sun Elevation Descending - Start Point
          description: '**Used in options 3, 4, 5, 6, 7, 8 or 9** - When the sun descends
            below the sensor''s starting point, both the colour temperature and brightness
            percentage will transition linearly from their maximum to minimum values
            until they reach the descending endpoint, based on the chosen settings.

            '
          default: 15
          selector:
            number:
              min: 0.0
              max: 90.0
              step: 0.5
              unit_of_measurement: degrees
              mode: slider
        dynamic_lighting_sun_elevation_end_falling:
          name: Dynamic Lighting - Sun Elevation Descending - End Point
          description: '**Used in options 3, 4, 5, 6, 7, 8 or 9** - When the sun descends
            below the sensor''s endpoint, the minimum colour temperature and minimum
            brightness value will  be established according to the chosen settings.

            '
          default: -4.0
          selector:
            number:
              min: -10.0
              max: 30.0
              step: 0.5
              unit_of_measurement: degrees
              mode: slider
        dynamic_lighting_heartbeat:
          name: Dynamic Lighting - Heartbeat
          description: "**Used in options 1, 2, 8 or 9** - Define the heartbeat rate,
            setting the operational speed. During each heartbeat, it evaluates the
            lux value, light brightness, and targeted brightness based on the chosen
            settings,\n    adjusting the brightness as per the selections.\n"
          default: 1
          selector:
            number:
              min: 0.25
              max: 10.0
              step: 0.25
              unit_of_measurement: minutes
              mode: slider
        dynamic_lighting_step_value:
          name: Dynamic Lighting - Step Value
          description: '**Used in options 1, 2, 8 or 9** - With every heartbeat, the
            system evaluates the lux value, light brightness, and the targeted brightness.
            If the targeted brightness surpasses the predefined step value, the system
            applies the set step value to gracefully moderate the rate of changes,
            facilitating a smoother transition in light brightness.

            '
          default: 4
          selector:
            number:
              min: 1.0
              max: 100.0
              step: 1.0
              unit_of_measurement: '%'
              mode: slider
        dynamic_lighting_dead_zone:
          name: Dynamic Lighting - Dead Zone (±)
          description: '**Used in options 1, 2, 8 or 9** - With every heartbeat, the
            system evaluates the current light brightness and the targeted brightness.
            If the targeted brightness falls within the defined dead zone, the system
            maintains the current light brightness. This prevents minor fluctuations
            in light intensity that could be bothersome to the eye.

            '
          default: 7
          selector:
            number:
              min: 0.0
              max: 15.0
              step: 1.0
              unit_of_measurement: '%'
              mode: slider
    bypass_settings:
      name: Bypass
      icon: mdi:cog-pause-outline
      collapsed: true
      input:
        include_bypass:
          name: Use The Bypass Options (Optional)
          description: 'Select if you would like to enable an option. Each option
            allows manual control of your lights but alters its behaviour by either
            turning ON, OFF, or keeping its current state when the bypass is switched
            ON. When enabling an option, please enter the bypass switch into the corresponding
            input below.

            '
          default: []
          selector:
            select:
              options:
              - label: 1 - Enable the Bypass - Turn lights ON
                value: bypass_enabled_turn_on
              - label: 2 - Enable the Bypass - Turn lights OFF
                value: bypass_enabled_turn_off
              - label: 3 - Enable the Bypass - Keep the lights current state
                value: bypass_enabled_stop
              multiple: true
              sort: false
              custom_value: false
        bypass_lights_on:
          name: Bypass Switch - Turn lights ON
          description: 'Select the switches that will turn your lights ON, bypass
            the trigger sensor, and allow your lights to function as normal. Please
            note that the entity cannot be included in the ''Lights - Switches - Scenes
            - Scripts'' or ''Night Lights'' selections.

            '
          default: []
          selector:
            entity:
              multiple: true
        bypass_lights_off:
          name: Bypass Switch - Turn lights OFF
          description: 'Select the switches that will turn your lights OFF, bypass
            the trigger sensor, and allow your lights to function as normal. Please
            note that the entity cannot be included in the ''Lights - Switches - Scenes
            - Scripts'' or ''Night Lights'' selections.

            '
          default: []
          selector:
            entity:
              multiple: true
        bypass_lights_stop:
          name: Bypass Switch - Keep The Lights Current State
          description: 'Select the switches that will keep your lights current state,
            bypass the trigger sensor, and allow your lights to function as normal.
            Please note that the entity cannot be included in the ''Lights - Switches
            - Scenes - Scripts'' or ''Night Lights'' selections.

            '
          default: []
          selector:
            entity:
              multiple: true
        bypass_time_delay:
          name: Bypass - Time Delay
          description: 'This is only used in two bypass scenarios; when the lights
            are already ON and when the automation turns the lights OFF. The first
            scenario occurs when you have selected option 2 above to "Enable the Bypass
            - Turn lights OFF". The second scenario occurs when you turn the bypass
            OFF, the trigger sensor is OFF, and your lights are ON. In both scenarios,
            the automation will turn your lights OFF after the set time delay.

            '
          default: 0
          selector:
            number:
              min: 0.0
              max: 10.0
              step: 0.25
              unit_of_measurement: minutes
              mode: slider
        include_bypass_auto_off:
          name: Use The Bypass Auto OFF Option (Optional)
          description: 'This is used when you turn ON the bypass and want it to automatically
            turn OFF after a set time delay. You can choose which bypass option you
            would like to apply the auto OFF feature to

            '
          default: []
          selector:
            select:
              options:
              - label: Enable the auto OFF for the bypass switch - Turn lights ON
                value: bypass_auto_off_enabled_on
              - label: Enable the auto OFF for the bypass switch - Turn lights OFF
                value: bypass_auto_off_enabled_off
              - label: Enable the auto OFF for the bypass switch - Keep The Lights
                  Current State
                value: bypass_auto_off_enabled_stop
              multiple: true
              sort: false
              custom_value: false
        bypass_auto_off_delay:
          name: Bypass Auto OFF - Time Delay
          description: 'Set the bypass auto OFF time delay. The time delay starts
            from the last bypass that was turned ON.

            '
          default: 60
          selector:
            number:
              min: 1.0
              max: 240.0
              step: 1.0
              unit_of_measurement: minutes
              mode: slider
    weekdays:
      name: Weekdays
      icon: mdi:calendar-week
      collapsed: true
      input:
        include_weekdays:
          name: Use The Weekdays Option (Optional)
          description: 'This option adds a condition to operate only on specified
            weekdays. It applies globally to all triggers.

            '
          default: weekday_disabled
          selector:
            select:
              options:
              - label: Enable the weekday option
                value: weekday_enabled
              - label: Disable the weekday option
                value: weekday_disabled
              multiple: false
              sort: false
              custom_value: false
        weekday_options:
          name: Weekdays
          description: 'Select the days of the week on which you want the automation
            to run.

            '
          default:
          - mon
          - tue
          - wed
          - thu
          - fri
          - sat
          - sun
          selector:
            select:
              multiple: true
              mode: list
              options:
              - label: Monday
                value: mon
              - label: Tuesday
                value: tue
              - label: Wednesday
                value: wed
              - label: Thursday
                value: thu
              - label: Friday
                value: fri
              - label: Saturday
                value: sat
              - label: Sunday
                value: sun
              sort: false
              custom_value: false
    night_lights_trigger_settings:
      name: Night Lights Settings
      icon: mdi:weather-night
      collapsed: true
      input:
        include_night_lights:
          name: Use The Night Lights Options (Optional)
          description: 'Enabling the night lights option allows for separate and customizable
            lighting control when night light conditions are met. Night light condition
            options include entity state, time, or sun elevation. Please choose the
            condition option you would like to use below.


            This feature is particularly beneficial for creating a soothing ambiance
            with softer lighting at night. The flexibility of these options allows
            for personalized adjustments, enhancing your nighttime ambiance and comfort,
            especially when moving around during the night.

            '
          default: night_lights_disabled
          selector:
            select:
              options:
              - label: Enable the night lights options
                value: night_lights_enabled
              - label: Disable the night lights options
                value: night_lights_disabled
              multiple: false
              sort: false
              custom_value: false
        night_lights_conditions:
          name: Night Lights Conditions (Required For Night Lights)
          description: 'Select any night light condition from the options provided.
            Ensure you''ve enabled **Use the night lights options** in the section
            above and choose at least one **Night Lights Condition** for night lights
            to operate.


            Settings for each option are provided below.

            '
          default: []
          selector:
            select:
              multiple: true
              options:
              - label: Enable entity state option
                value: entity_state_enabled
              - label: Enable time option
                value: time_enabled
              - label: Enable sun elevation option
                value: sun_enabled
              sort: false
              custom_value: false
        night_lights_entity_state:
          name: Night Lights - Entity State
          description: 'Select an entity that will trigger the activation of night
            lights when turned ON. This could be your phone on **Do Not Disturb**,
            a helper, a bed sensor, etc. Please note that the selected entity cannot
            be included in the **Lights - Switches - Scenes - Scripts** or **Night
            Lights** selections.

            '
          default: []
          selector:
            entity:
              multiple: true
        night_lights_after_time:
          name: Night Lights - Start Time
          description: 'Set the start time.

            '
          default: 00:00:00
          selector:
            time: {}
        night_lights_before_time:
          name: Night Lights - End Time
          description: 'Set the end time.

            '
          default: 00:00:00
          selector:
            time: {}
        night_lights_sun_elevation:
          name: Night Lights - Sun Elevation Falling
          description: 'The sun elevation falling refers to the angle between the
            sun and the horizon when the sun is setting. A negative value indicates
            that the sun is BELOW the horizon. For example, a setting guide of -1.5
            corresponds to dusk.

            '
          default: -1.5
          selector:
            number:
              min: -10.0
              max: 5.0
              step: 0.5
              unit_of_measurement: degrees
              mode: slider
        night_lights_sun_elevation_rising:
          name: Night Lights - Sun Elevation Rising
          description: 'The sun elevation rising refers to the angle between the sun
            and the horizon during sunrise. A negative value indicates that the sun
            is BELOW the horizon. For example, a setting guide of -4.0 corresponds
            to dawn.

            '
          default: -4.0
          selector:
            number:
              min: -10.0
              max: 5.0
              step: 0.5
              unit_of_measurement: degrees
              mode: slider
    night_lights_settings:
      name: Night Lights
      icon: mdi:lightbulb-night-outline
      collapsed: true
      input:
        night_lights:
          name: Night Lights
          description: 'The lights, switches, scenes, and scripts that will be activated
            by the trigger sensor/s. If adding a scene or script, please refer to
            the ''Night Lights - Scenes & Scripts - Toggle Helper'' section below
            and the ''Scenes - Scripts To Turn OFF'' section above.


            **NOTE** - You can only use entities. Areas, devices and labels are not
            supported.

            '
          default: {}
          selector:
            target:
              entity:
              - domain:
                - light
                - switch
                - scene
                - script
        night_boolean_scenes_scripts:
          name: Night Lights - Scenes & Scripts - Toggle Helper
          description: 'To ensure the smooth operation of the automation, it''s recommended
            to create an independent toggle helper when selecting a scene or script
            in "Night Lights" above and then enter it here.

            '
          default: []
          selector:
            entity:
              filter:
              - domain:
                - input_boolean
              multiple: false
    night_lights_light_control_settings:
      name: Night Light Control
      icon: mdi:lightbulb-on-80
      collapsed: true
      input:
        include_night_light_control:
          name: Night Lights - Use The Light Control Options (Optional)
          description: "Select if you would like to use brightness or transition.
            These settings will only affect a 'light' entity that supports each selected
            option. The settings for brightness and transition are provided below.
            \n\nSelecting **If lights are ON, adjust the lights when crossing over**
            option ensures that the light control settings will be applied to any
            lights that are already ON during the transition from normal lights to
            night lights and vice versa.\n\nSelecting **Yes - Manage OFF script when
            crossing over** is beneficial for scripts containing if-then-else actions
            that toggle various functions on and off during the transition from normal
            lights to night lights and vice versa.\n"
          default: []
          selector:
            select:
              multiple: true
              options:
              - label: Use brightness
                value: use_brightness
              - label: Use transition
                value: use_transition
              - label: If lights are ON, adjust the lights when crossing over
                value: if_lights_are_on_adjust_when_crossing_over
              - label: Yes - Manage OFF script when crossing over
                value: manage_scripts_crossing_over
              sort: false
              custom_value: false
        night_light_brightness:
          name: Night Lights - Brightness
          description: 'The brightness setting of the night lights when they are turned
            ON.

            '
          default: 20
          selector:
            number:
              min: 1.0
              max: 100.0
              mode: slider
              step: 1.0
              unit_of_measurement: '%'
        night_light_transition_on:
          name: Night Lights - Transition - ON
          description: 'The transition of the night lights when they are turned ON.

            '
          default: 1
          selector:
            number:
              min: 0.0
              max: 5.0
              mode: slider
              step: 0.5
              unit_of_measurement: seconds
        night_light_transition_off:
          name: Night Lights - Transition - OFF
          description: 'The transition of the night lights when they are turned OFF.

            '
          default: 1
          selector:
            number:
              min: 0.0
              max: 30.0
              mode: slider
              step: 1.0
              unit_of_measurement: seconds
        include_night_light_colour_control:
          name: Use The Night Light Colour Control Options (Optional)
          description: 'Select if you would like to use colour temperature, RGB, RGBW
            or RGBWW colour. These settings will only affect a ''light'' entity that
            supports each selected option. The settings for colour temperature, RGB,
            RGBW and RGBWW colour are provided below

            '
          default: disable_colour_control
          selector:
            select:
              options:
              - label: Use Colour Temperature
                value: use_colour_temperature
              - label: Use RGB Colour
                value: use_rgb_colour
              - label: Use RGBW Colour
                value: use_rgbw_colour
              - label: Use RGBWW Colour
                value: use_rgbww_colour
              - label: Disable Colour Control
                value: disable_colour_control
              multiple: false
              sort: false
              custom_value: false
        night_light_colour_temperature:
          name: Night Lights - Colour Temperature
          description: 'The colour temperature setting for the night lights when they
            are turned ON.

            '
          default: 5000
          selector:
            number:
              min: 2000.0
              max: 8000.0
              mode: slider
              step: 100.0
              unit_of_measurement: kelvin
        night_light_rgb_colour:
          name: Night Lights - RGB Colour
          description: 'The RGB colour setting for the lights when they are turned
            ON.

            '
          default:
          - 255
          - 255
          - 255
          selector:
            color_rgb: {}
        night_light_rgbw_colour:
          name: Night Lights - RGBW Colour
          description: 'The RGBW colour setting for the lights when they are turned
            ON. Enter four integers between 0 and 255 to define the values for Red,
            Green, Blue, and White.

            '
          default:
          - 255
          - 255
          - 255
          - 255
          selector:
            object: {}
        night_light_rgbww_colour:
          name: Night Lights - RGBWW Colour
          description: 'The RGBWW colour setting for the lights when they are turned
            ON. Enter five integers between 0 and 255 to define the values for Red,
            Green, Blue, Cold White and Warm White.

            '
          default:
          - 255
          - 255
          - 255
          - 255
          - 255
          selector:
            object: {}
  source_url: https://gist.github.com/Blackshome/e6c8f1bf846bab2fa4431934a0a85770
mode: restart
max_exceeded: silent
variables:
  include_entity_state: !input include_entity_state
  entity_input: !input entity_input
  include_sun: !input include_sun
  sun_elevation: !input sun_elevation
  sun_elevation_rising: !input sun_elevation_rising
  include_ambient: !input include_ambient
  ambient_light_sensor: !input ambient_light_sensor
  ambient_light_value: !input ambient_light_value
  ambient_light_value_off: !input ambient_light_value_off
  include_time: !input include_time
  after_time: !input after_time
  before_time: !input before_time
  light_switch: !input light_switch
  boolean_scenes_scripts: !input boolean_scenes_scripts
  end_scenes: !input end_scenes
  include_light_control: !input include_light_control
  light_brightness: !input light_brightness
  light_transition_on: !input light_transition_on
  light_transition_off: !input light_transition_off
  include_light_colour_control: !input include_light_colour_control
  light_colour_temperature: !input light_colour_temperature
  light_rgb_colour: !input light_rgb_colour
  light_rgbw_colour: !input light_rgbw_colour
  light_rgbww_colour: !input light_rgbww_colour
  include_dynamic_lighting: !input include_dynamic_lighting
  dynamic_lighting_lux_sensor: !input dynamic_lighting_lux_sensor
  dynamic_lighting_max_lux: !input dynamic_lighting_max_lux
  dynamic_lighting_min_lux: !input dynamic_lighting_min_lux
  dynamic_lighting_max_brightness: !input dynamic_lighting_max_brightness
  dynamic_lighting_min_brightness: !input dynamic_lighting_min_brightness
  dynamic_lighting_boolean: !input dynamic_lighting_boolean
  dynamic_lighting_max_colour_temp: !input dynamic_lighting_max_colour_temp
  dynamic_lighting_min_colour_temp: !input dynamic_lighting_min_colour_temp
  dynamic_lighting_sun_elevation_start_rising: !input dynamic_lighting_sun_elevation_start_rising
  dynamic_lighting_sun_elevation_end_rising: !input dynamic_lighting_sun_elevation_end_rising
  dynamic_lighting_sun_elevation_start_falling: !input dynamic_lighting_sun_elevation_start_falling
  dynamic_lighting_sun_elevation_end_falling: !input dynamic_lighting_sun_elevation_end_falling
  dynamic_lighting_heartbeat: !input dynamic_lighting_heartbeat
  dynamic_lighting_step_value: !input dynamic_lighting_step_value
  dynamic_lighting_dead_zone: !input dynamic_lighting_dead_zone
  include_bypass: !input include_bypass
  bypass_lights_on: !input bypass_lights_on
  bypass_lights_off: !input bypass_lights_off
  bypass_lights_stop: !input bypass_lights_stop
  bypass_time_delay: !input bypass_time_delay
  include_bypass_auto_off: !input include_bypass_auto_off
  bypass_auto_off_delay: !input bypass_auto_off_delay
  include_weekdays: !input include_weekdays
  weekday_options: !input weekday_options
  include_night_lights: !input include_night_lights
  night_lights_conditions: !input night_lights_conditions
  night_lights_entity_state: !input night_lights_entity_state
  night_lights_after_time: !input night_lights_after_time
  night_lights_before_time: !input night_lights_before_time
  night_lights_sun_elevation: !input night_lights_sun_elevation
  night_lights_sun_elevation_rising: !input night_lights_sun_elevation_rising
  night_lights: !input night_lights
  night_boolean_scenes_scripts: !input night_boolean_scenes_scripts
  include_night_light_control: !input include_night_light_control
  night_light_brightness: !input night_light_brightness
  night_light_transition_on: !input night_light_transition_on
  night_light_transition_off: !input night_light_transition_off
  include_night_light_colour_control: !input include_night_light_colour_control
  night_light_colour_temperature: !input night_light_colour_temperature
  night_light_rgb_colour: !input night_light_rgb_colour
  night_light_rgbw_colour: !input night_light_rgbw_colour
  night_light_rgbww_colour: !input night_light_rgbww_colour
  light_entities_off: '{{ expand(light_switch.entity_id) | selectattr(''domain'',
    ''eq'', ''light'') | selectattr(''state'', ''eq'', ''off'') | map(attribute=''entity_id'')
    | list }}'
  switch_entities_off: '{{ expand(light_switch.entity_id) | selectattr(''domain'',
    ''eq'', ''switch'') | selectattr(''state'', ''eq'', ''off'') | map(attribute=''entity_id'')
    | list }}'
  light_data: "{% set light = namespace(data={}) %} {% if 'use_transition' in include_light_control
    %}\n  {% set light.data = dict(light.data, **{ 'transition': light_transition_on
    }) %}\n{% endif %} {% if 'use_brightness' in include_light_control %}\n  {% set
    light.data = dict(light.data, **{ 'brightness_pct': light_brightness }) %}\n{%
    endif %} {% if include_light_colour_control == 'use_colour_temperature' %}\n  {%
    set light.data = dict(light.data, **{ 'color_temp_kelvin': light_colour_temperature
    }) %}\n{% endif %} {% if include_light_colour_control == 'use_rgb_colour' %}\n
    \ {% set light.data = dict(light.data, **{ 'rgb_color': light_rgb_colour }) %}\n{%
    endif %} {% if include_light_colour_control == 'use_rgbw_colour' %}\n  {% set
    light.data = dict(light.data, **{ 'rgbw_color': light_rgbw_colour }) %}\n{% endif
    %} {% if include_light_colour_control == 'use_rgbww_colour' %}\n  {% set light.data
    = dict(light.data, **{ 'rgbww_color': light_rgbww_colour }) %}\n{% endif %} {{
    light.data }}"
  light_entities: '{{ expand(light_switch.entity_id) | selectattr(''domain'', ''eq'',
    ''light'') | map(attribute=''entity_id'') | list }}'
  switch_entities: '{{ expand(light_switch.entity_id) | selectattr(''domain'', ''eq'',
    ''switch'') | map(attribute=''entity_id'') | list }}'
  scene_entities: "{% set a = light_switch.entity_id %} {% if boolean_scenes_scripts
    == [] %}\n  {{ expand(a) | selectattr('domain', 'eq', 'scene') | map(attribute='entity_id')
    | list }}\n{% elif is_state(boolean_scenes_scripts, 'off') %}\n  {{ expand(a)
    | selectattr('domain', 'eq', 'scene') | map(attribute='entity_id') | list }}\n{%
    else %}\n  []\n{% endif %}"
  script_entities: "{% set a = light_switch.entity_id %} {% if boolean_scenes_scripts
    == [] %}\n  {{ expand(a) | selectattr('domain', 'eq', 'script') | map(attribute='entity_id')
    | list }}\n{% elif is_state(boolean_scenes_scripts, 'off') %}\n  {{ expand(a)
    | selectattr('domain', 'eq', 'script') | map(attribute='entity_id') | list }}\n{%
    else %}\n  []\n{% endif %}"
  boolean_scenes_scripts_helper: "{% if boolean_scenes_scripts | length > 0 and states(boolean_scenes_scripts)
    == 'off' %}\n  {{ boolean_scenes_scripts }}\n{% else %}\n  []\n{% endif %}"
  end_scene_entities: '{{ end_scenes | select(''match'', ''^scene\..*'') | list }}'
  end_script_entities: '{{ end_scenes | select(''match'', ''^script\..*'') | list
    }}'
  night_light_entities_off: "{% set b =  night_lights and night_lights.entity_id %}
    {% if b %}\n  {{ expand(b) | selectattr('domain', 'eq', 'light') | selectattr('state',
    'eq', 'off') | map(attribute='entity_id') | list }}\n{% else %}\n  []\n{% endif
    %}"
  night_switch_entities_off: "{% set b =  night_lights and night_lights.entity_id
    %} {% if b %}\n  {{ expand(b) | selectattr('domain', 'eq', 'switch') | selectattr('state',
    'eq', 'off') | map(attribute='entity_id') | list }}\n{% else %}\n  []\n{% endif
    %}"
  night_light_data: "{% set light = namespace(data={}) %} {% if 'use_transition' in
    include_night_light_control %}\n  {% set light.data = dict(light.data, **{ 'transition':
    night_light_transition_on }) %}\n{% endif %} {% if 'use_brightness' in include_night_light_control
    %}\n  {% set light.data = dict(light.data, **{ 'brightness_pct': night_light_brightness
    }) %}\n{% endif %} {% if include_night_light_colour_control == 'use_colour_temperature'
    %}\n  {% set light.data = dict(light.data, **{ 'color_temp_kelvin': night_light_colour_temperature
    }) %}\n{% endif %} {% if include_night_light_colour_control == 'use_rgb_colour'
    %}\n  {% set light.data = dict(light.data, **{ 'rgb_color': night_light_rgb_colour
    }) %}\n{% endif %} {% if include_night_light_colour_control == 'use_rgbw_colour'
    %}\n  {% set light.data = dict(light.data, **{ 'rgbw_color': night_light_rgbw_colour
    }) %}\n{% endif %} {% if include_night_light_colour_control == 'use_rgbww_colour'
    %}\n  {% set light.data = dict(light.data, **{ 'rgbww_color': night_light_rgbww_colour
    }) %}\n{% endif %} {{ light.data }}"
  night_light_entities: "{% set b =  night_lights and night_lights.entity_id %} {%
    if b %}\n  {{ expand(b) | selectattr('domain', 'eq', 'light') | map(attribute='entity_id')
    | list }}\n{% else %}\n  []\n{% endif %}"
  night_switch_entities: "{% set b =  night_lights and night_lights.entity_id %} {%
    if b %}\n  {{ expand(b) | selectattr('domain', 'eq', 'switch') | map(attribute='entity_id')
    | list }}\n{% else %}\n  []\n{% endif %}"
  night_scene_entities: "{% set b = night_lights and night_lights.entity_id %} {%
    if night_boolean_scenes_scripts == [] %}\n  {{ expand(b) | selectattr('domain',
    'eq', 'scene') | map(attribute='entity_id') | list }}\n{% elif is_state(night_boolean_scenes_scripts,
    'off') %}\n  {{ expand(b) | selectattr('domain', 'eq', 'scene') | map(attribute='entity_id')
    | list }}\n{% else %}\n  []\n{% endif %}"
  night_script_entities: "{% set b = night_lights and night_lights.entity_id %} {%
    if night_boolean_scenes_scripts == [] %}\n  {{ expand(b) | selectattr('domain',
    'eq', 'script') | map(attribute='entity_id') | list }}\n{% elif is_state(night_boolean_scenes_scripts,
    'off') %}\n  {{ expand(b) | selectattr('domain', 'eq', 'script') | map(attribute='entity_id')
    | list }}\n{% else %}\n  []\n{% endif %}"
  night_boolean_scenes_scripts_helper: "{% if night_boolean_scenes_scripts | length
    > 0 and states(night_boolean_scenes_scripts) == 'off' %}\n  {{ night_boolean_scenes_scripts
    }}\n{% else %}\n  []\n{% endif %}"
  crossover_lights_light: "{% set a = light_switch.entity_id %} {% set b =  night_lights
    and night_lights.entity_id %} {% if a and b %}\n  {{ expand(a) | reject('in',
    expand(b)) | selectattr('domain', 'eq', 'light') | map(attribute='entity_id')
    | list }}\n{% else %}\n  []\n{% endif %}"
  crossover_lights_switch: "{% set a = light_switch.entity_id %} {% set b =  night_lights
    and night_lights.entity_id %} {% if a and b %}\n  {{ expand(a) | reject('in',
    expand(b)) | selectattr('domain', 'eq', 'switch') | map(attribute='entity_id')
    | list }}\n{% else %}\n  []\n{% endif %}"
  crossover_night_lights_light_on: "{% set b =  night_lights and night_lights.entity_id
    %} {% if b %}\n  {{ expand(b) | selectattr('domain', 'eq', 'light') | selectattr('state',
    'eq', 'on') | map(attribute='entity_id') | list }}\n{% else %}\n  []\n{% endif
    %}"
  crossover_night_lights_light: "{% set a = light_switch.entity_id %} {% set b =  night_lights
    and night_lights.entity_id %} {% if a and b %}\n  {{ expand(b) | reject('in',
    expand(a)) | selectattr('domain', 'eq', 'light') | map(attribute='entity_id')
    | list }}\n{% else %}\n  []\n{% endif %}"
  crossover_night_lights_switch: "{% set a = light_switch.entity_id %} {% set b =
    \ night_lights and night_lights.entity_id %} {% if a and b %}\n  {{ expand(b)
    | reject('in', expand(a)) | selectattr('domain', 'eq', 'switch') | map(attribute='entity_id')
    | list }}\n{% else %}\n  []\n{% endif %}"
  crossover_lights_light_on: "{% set a = light_switch.entity_id %} {% if a %}\n  {{
    expand(a) | selectattr('domain', 'eq', 'light') | selectattr('state', 'eq', 'on')
    | map(attribute='entity_id') | list }}\n{% else %}\n  []\n{% endif %}"
trigger:
- platform: state
  id: t0
  entity_id: !input entity_input
  from: 'off'
  to: 'on'
- platform: state
  id: t1
  entity_id: !input entity_input
  from: 'on'
  to: 'off'
- platform: numeric_state
  id: t2
  entity_id: sun.sun
  attribute: elevation
  below: !input sun_elevation
- platform: numeric_state
  id: t3
  entity_id: sun.sun
  attribute: elevation
  above: !input sun_elevation_rising
- platform: numeric_state
  id: t4
  entity_id: !input ambient_light_sensor
  below: !input ambient_light_value
- platform: numeric_state
  id: t5
  entity_id: !input ambient_light_sensor
  above: !input ambient_light_value_off
- platform: time
  id: t6
  at: !input after_time
- platform: time
  id: t7
  at: !input before_time
- platform: state
  id: t8_on
  entity_id: !input bypass_lights_on
  from: 'off'
  to: 'on'
- platform: state
  id: t8_off
  entity_id: !input bypass_lights_off
  from: 'off'
  to: 'on'
- platform: state
  id: t8_stop
  entity_id: !input bypass_lights_stop
  from: 'off'
  to: 'on'
- platform: state
  id: t9_on
  entity_id: !input bypass_lights_on
  from: 'on'
  to: 'off'
- platform: state
  id: t9_off
  entity_id: !input bypass_lights_off
  from: 'on'
  to: 'off'
- platform: state
  id: t9_stop
  entity_id: !input bypass_lights_stop
  from: 'on'
  to: 'off'
- platform: state
  id: t10
  entity_id: !input night_lights_entity_state
  from: 'off'
  to: 'on'
- platform: time
  id: t11
  at: !input night_lights_after_time
- platform: numeric_state
  id: t12
  entity_id: sun.sun
  attribute: elevation
  below: !input night_lights_sun_elevation
- platform: state
  id: t13
  entity_id: !input night_lights_entity_state
  from: 'on'
  to: 'off'
- platform: time
  id: t14
  at: !input night_lights_before_time
- platform: numeric_state
  id: t15
  entity_id: sun.sun
  attribute: elevation
  above: !input night_lights_sun_elevation_rising
- platform: homeassistant
  id: t16
  event: start
condition:
- condition: or
  conditions:
  - condition: and
    conditions:
    - '{{ ''entity_on'' in include_entity_state }}'
    - condition: trigger
      id: t0
    - condition: state
      entity_id: !input entity_input
      match: any
      state: 'on'
  - condition: and
    conditions:
    - '{{ ''entity_off'' in include_entity_state }}'
    - condition: trigger
      id: t1
    - condition: state
      entity_id: !input entity_input
      match: any
      state: 'off'
  - condition: and
    conditions:
    - '{{ ''sun_falling'' in include_sun }}'
    - condition: trigger
      id: t2
  - condition: and
    conditions:
    - '{{ ''sun_rising'' in include_sun }}'
    - condition: trigger
      id: t3
  - condition: and
    conditions:
    - '{{ ''ambient_low'' in include_ambient }}'
    - condition: trigger
      id: t4
  - condition: and
    conditions:
    - '{{ ''ambient_high'' in include_ambient }}'
    - condition: trigger
      id: t5
  - condition: and
    conditions:
    - '{{ ''time_on'' in include_time }}'
    - condition: trigger
      id: t6
  - condition: and
    conditions:
    - '{{ ''time_off'' in include_time }}'
    - condition: trigger
      id: t7
  - condition: and
    conditions:
    - condition: trigger
      id: t8_on
    - '{{ ''bypass_enabled_turn_on'' in include_bypass }}'
  - condition: and
    conditions:
    - condition: trigger
      id: t8_off
    - '{{ ''bypass_enabled_turn_off'' in include_bypass }}'
  - condition: and
    conditions:
    - condition: trigger
      id: t8_stop
    - '{{ ''bypass_enabled_stop'' in include_bypass }}'
  - condition: and
    conditions:
    - condition: trigger
      id: t9_on
    - '{{ ''bypass_enabled_turn_on'' in include_bypass }}'
  - condition: and
    conditions:
    - condition: trigger
      id: t9_off
    - '{{ ''bypass_enabled_turn_off'' in include_bypass }}'
  - condition: and
    conditions:
    - condition: trigger
      id: t9_stop
    - '{{ ''bypass_enabled_stop'' in include_bypass }}'
  - condition: and
    conditions:
    - condition: trigger
      id: t16
    - condition: or
      conditions:
      - '{{ (expand(light_switch.entity_id) | selectattr(''state'', ''=='', ''on'')
        | list | count > 0) }}'
      - condition: template
        value_template: "{% if boolean_scenes_scripts != [] %}\n  {{ is_state(boolean_scenes_scripts,
          'on') }}\n{% endif %}"
  - condition: and
    conditions:
    - condition: trigger
      id: t10
    - '{{ include_night_lights == ''night_lights_enabled'' }}'
    - '{{ ''entity_state_enabled'' in night_lights_conditions }}'
    - condition: state
      entity_id: !input night_lights_entity_state
      match: any
      state: 'on'
    - condition: or
      conditions:
      - '{{ (expand(light_switch.entity_id) | selectattr(''state'', ''=='', ''on'')
        | list | count > 0) }}'
      - '{{ (include_night_lights == ''night_lights_enabled'') and (expand(night_lights.entity_id)
        | selectattr(''state'', ''=='', ''on'') | list | count > 0) }}'
      - condition: template
        value_template: '{{ ''manage_scripts_crossing_over'' in include_night_light_control
          }}'
      - condition: template
        value_template: "{% if boolean_scenes_scripts != [] %}\n  {{ is_state(boolean_scenes_scripts,
          'on') }}\n{% endif %}"
      - condition: template
        value_template: "{% if night_boolean_scenes_scripts != [] %}\n  {{ is_state(night_boolean_scenes_scripts,
          'on') }}\n{% endif %}"
  - condition: and
    conditions:
    - condition: trigger
      id: t11
    - '{{ include_night_lights == ''night_lights_enabled'' }}'
    - '{{ ''time_enabled'' in night_lights_conditions }}'
    - condition: or
      conditions:
      - '{{ (expand(light_switch.entity_id) | selectattr(''state'', ''=='', ''on'')
        | list | count > 0) }}'
      - '{{ (include_night_lights == ''night_lights_enabled'') and (expand(night_lights.entity_id)
        | selectattr(''state'', ''=='', ''on'') | list | count > 0) }}'
      - condition: template
        value_template: '{{ ''manage_scripts_crossing_over'' in include_night_light_control
          }}'
      - condition: template
        value_template: "{% if boolean_scenes_scripts != [] %}\n  {{ is_state(boolean_scenes_scripts,
          'on') }}\n{% endif %}"
      - condition: template
        value_template: "{% if night_boolean_scenes_scripts != [] %}\n  {{ is_state(night_boolean_scenes_scripts,
          'on') }}\n{% endif %}"
  - condition: and
    conditions:
    - condition: trigger
      id: t12
    - '{{ include_night_lights == ''night_lights_enabled'' }}'
    - '{{ ''sun_enabled'' in night_lights_conditions }}'
    - condition: or
      conditions:
      - '{{ (expand(light_switch.entity_id) | selectattr(''state'', ''=='', ''on'')
        | list | count > 0) }}'
      - '{{ (include_night_lights == ''night_lights_enabled'') and (expand(night_lights.entity_id)
        | selectattr(''state'', ''=='', ''on'') | list | count > 0) }}'
      - condition: template
        value_template: '{{ ''manage_scripts_crossing_over'' in include_night_light_control
          }}'
      - condition: template
        value_template: "{% if boolean_scenes_scripts != [] %}\n  {{ is_state(boolean_scenes_scripts,
          'on') }}\n{% endif %}"
      - condition: template
        value_template: "{% if night_boolean_scenes_scripts != [] %}\n  {{ is_state(night_boolean_scenes_scripts,
          'on') }}\n{% endif %}"
  - condition: and
    conditions:
    - condition: trigger
      id: t13
    - '{{ include_night_lights == ''night_lights_enabled'' }}'
    - '{{ ''entity_state_enabled'' in night_lights_conditions }}'
    - condition: state
      entity_id: !input night_lights_entity_state
      state: 'off'
    - condition: or
      conditions:
      - '{{ (expand(light_switch.entity_id) | selectattr(''state'', ''=='', ''on'')
        | list | count > 0) }}'
      - '{{ (include_night_lights == ''night_lights_enabled'') and (expand(night_lights.entity_id)
        | selectattr(''state'', ''=='', ''on'') | list | count > 0) }}'
      - condition: template
        value_template: '{{ ''manage_scripts_crossing_over'' in include_night_light_control
          }}'
      - condition: template
        value_template: "{% if boolean_scenes_scripts != [] %}\n  {{ is_state(boolean_scenes_scripts,
          'on') }}\n{% endif %}"
      - condition: template
        value_template: "{% if night_boolean_scenes_scripts != [] %}\n  {{ is_state(night_boolean_scenes_scripts,
          'on') }}\n{% endif %}"
  - condition: and
    conditions:
    - condition: trigger
      id: t14
    - '{{ include_night_lights == ''night_lights_enabled'' }}'
    - '{{ ''time_enabled'' in night_lights_conditions }}'
    - condition: or
      conditions:
      - '{{ (expand(light_switch.entity_id) | selectattr(''state'', ''=='', ''on'')
        | list | count > 0) }}'
      - '{{ (include_night_lights == ''night_lights_enabled'') and (expand(night_lights.entity_id)
        | selectattr(''state'', ''=='', ''on'') | list | count > 0) }}'
      - condition: template
        value_template: '{{ ''manage_scripts_crossing_over'' in include_night_light_control
          }}'
      - condition: template
        value_template: "{% if boolean_scenes_scripts != [] %}\n  {{ is_state(boolean_scenes_scripts,
          'on') }}\n{% endif %}"
      - condition: template
        value_template: "{% if night_boolean_scenes_scripts != [] %}\n  {{ is_state(night_boolean_scenes_scripts,
          'on') }}\n{% endif %}"
  - condition: and
    conditions:
    - condition: trigger
      id: t15
    - '{{ include_night_lights == ''night_lights_enabled'' }}'
    - '{{ ''sun_enabled'' in night_lights_conditions }}'
    - condition: or
      conditions:
      - '{{ (expand(light_switch.entity_id) | selectattr(''state'', ''=='', ''on'')
        | list | count > 0) }}'
      - '{{ (include_night_lights == ''night_lights_enabled'') and (expand(night_lights.entity_id)
        | selectattr(''state'', ''=='', ''on'') | list | count > 0) }}'
      - condition: template
        value_template: '{{ ''manage_scripts_crossing_over'' in include_night_light_control
          }}'
      - condition: template
        value_template: "{% if boolean_scenes_scripts != [] %}\n  {{ is_state(boolean_scenes_scripts,
          'on') }}\n{% endif %}"
      - condition: template
        value_template: "{% if night_boolean_scenes_scripts != [] %}\n  {{ is_state(night_boolean_scenes_scripts,
          'on') }}\n{% endif %}"
  - condition: and
    conditions:
    - condition: trigger
      id: t16
    - alias: Check if any triggers are ON
      condition: or
      conditions:
      - condition: or
        conditions:
        - '{{ (''entity_on'' in include_entity_state ) and (states[entity_input].state
          == ''on'') }}'
        - '{{ (''entity_off'' in include_entity_state ) and (states[entity_input].state
          == ''on'') }}'
      - condition: or
        conditions:
        - '{{ (''sun_falling'' in include_sun) and (is_state_attr(''sun.sun'', ''rising'',
          false)) and (state_attr(''sun.sun'',''elevation'') <= sun_elevation | float(90))
          }}'
        - '{{ (''sun_rising'' in include_sun) and (is_state_attr(''sun.sun'', ''rising'',
          true)) and (state_attr(''sun.sun'',''elevation'') <= sun_elevation_rising
          | float(90)) }}'
      - condition: or
        conditions:
        - '{{ (''ambient_low'' in include_ambient) and (states[ambient_light_sensor].state
          | int < ambient_light_value | int) }}'
        - '{{ (''ambient_high'' in include_ambient) and (states[ambient_light_sensor].state
          | int < ambient_light_value_off | int) and (expand(light_switch.entity_id)
          | selectattr(''state'', ''=='', ''on'') | list | count > 0) }}'
      - condition: or
        conditions:
        - condition: and
          conditions:
          - condition: template
            value_template: '{{ (''time_on'' in include_time) and (''time_off'' in
              include_time) }}'
          - condition: time
            after: !input after_time
            before: !input before_time
  - condition: and
    conditions:
    - condition: trigger
      id: t16
    - condition: or
      conditions:
      - '{{ (expand(light_switch.entity_id) | selectattr(''state'', ''=='', ''on'')
        | list | count > 0) }}'
      - '{{ (include_night_lights == ''night_lights_enabled'') and (expand(night_lights.entity_id)
        | selectattr(''state'', ''=='', ''on'') | list | count > 0) }}'
      - condition: template
        value_template: "{% if boolean_scenes_scripts != [] %}\n  {{ is_state(boolean_scenes_scripts,
          'on') }}\n{% endif %}"
      - condition: template
        value_template: "{% if night_boolean_scenes_scripts != [] %}\n  {{ is_state(night_boolean_scenes_scripts,
          'on') }}\n{% endif %}"
  - condition: and
    conditions:
    - '{{ (''bypass_auto_off_enabled_on'' in include_bypass_auto_off) or (''bypass_auto_off_enabled_off''
      in include_bypass_auto_off) or (''bypass_auto_off_enabled_stop'' in include_bypass_auto_off)
      }}'
    - condition: trigger
      id: t16
    - condition: or
      conditions:
      - condition: state
        entity_id: !input bypass_lights_on
        match: any
        state: 'on'
      - condition: state
        entity_id: !input bypass_lights_off
        match: any
        state: 'on'
      - condition: state
        entity_id: !input bypass_lights_stop
        match: any
        state: 'on'
- condition: or
  conditions:
  - '{{ include_bypass == [] }}'
  - condition: and
    conditions:
    - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
      in include_bypass) and (''bypass_enabled_stop'' in include_bypass) }}'
    - condition: state
      entity_id: !input bypass_lights_on
      state: 'off'
    - condition: state
      entity_id: !input bypass_lights_off
      state: 'off'
    - condition: state
      entity_id: !input bypass_lights_stop
      state: 'off'
  - condition: and
    conditions:
    - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
      in include_bypass) and (''bypass_enabled_stop'' not in include_bypass) }}'
    - condition: state
      entity_id: !input bypass_lights_on
      state: 'off'
    - condition: state
      entity_id: !input bypass_lights_off
      state: 'off'
  - condition: and
    conditions:
    - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
      not in include_bypass) and (''bypass_enabled_stop'' in include_bypass) }}'
    - condition: state
      entity_id: !input bypass_lights_on
      state: 'off'
    - condition: state
      entity_id: !input bypass_lights_stop
      state: 'off'
  - condition: and
    conditions:
    - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
      in include_bypass) and (''bypass_enabled_stop'' in include_bypass) }}'
    - condition: state
      entity_id: !input bypass_lights_off
      state: 'off'
    - condition: state
      entity_id: !input bypass_lights_stop
      state: 'off'
  - condition: and
    conditions:
    - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
      not in include_bypass) and (''bypass_enabled_stop'' not in include_bypass) }}'
    - condition: state
      entity_id: !input bypass_lights_on
      state: 'off'
  - condition: and
    conditions:
    - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
      in include_bypass) and (''bypass_enabled_stop'' not in include_bypass) }}'
    - condition: state
      entity_id: !input bypass_lights_off
      state: 'off'
  - condition: and
    conditions:
    - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
      not in include_bypass) and (''bypass_enabled_stop'' in include_bypass) }}'
    - condition: state
      entity_id: !input bypass_lights_stop
      state: 'off'
  - condition: trigger
    id:
    - t8_on
    - t8_off
    - t8_stop
    - t9_on
    - t9_off
    - t9_stop
    - t16
- condition: or
  conditions:
  - '{{ include_weekdays == ''weekday_disabled'' }}'
  - '{{ (expand(light_switch.entity_id) | selectattr(''state'', ''=='', ''on'') |
    list | count > 0) }}'
  - '{{ (expand(night_lights.entity_id) | selectattr(''state'', ''=='', ''on'') |
    list | count > 0) }}'
  - condition: and
    conditions:
    - condition: time
      weekday: !input weekday_options
    - '{{ include_weekdays == ''weekday_enabled'' }}'
  - condition: trigger
    id:
    - t8_on
    - t8_off
    - t8_stop
    - t9_on
    - t9_off
    - t9_stop
action:
- choose:
  - alias: Check if night lights are enabled and within conditions
    conditions:
    - condition: and
      conditions:
      - alias: Check if night lights is enabled
        condition: or
        conditions:
        - '{{ ''night_lights_enabled'' in include_night_lights }}'
      - alias: Check if night lights entity state is enabled
        condition: or
        conditions:
        - '{{ (''time_enabled'' in night_lights_conditions) and not (''entity_state_enabled''
          in night_lights_conditions) }}'
        - '{{ (''sun_enabled'' in night_lights_conditions) and not (''entity_state_enabled''
          in night_lights_conditions) }}'
        - condition: and
          conditions:
          - '{{ ''entity_state_enabled'' in night_lights_conditions }}'
          - condition: state
            entity_id: !input night_lights_entity_state
            state: 'on'
            match: any
      - alias: Check if night lights time is enabled
        condition: or
        conditions:
        - '{{ (''entity_state_enabled'' in night_lights_conditions)  and not (''time_enabled''
          in night_lights_conditions) }}'
        - '{{ (''sun_enabled'' in night_lights_conditions)  and not (''time_enabled''
          in night_lights_conditions) }}'
        - condition: and
          conditions:
          - '{{ ''time_enabled'' in night_lights_conditions }}'
          - condition: time
            after: !input night_lights_after_time
            before: !input night_lights_before_time
      - alias: Check if night lights sun is enabled
        condition: or
        conditions:
        - '{{ (''entity_state_enabled'' in night_lights_conditions)  and not (''sun_enabled''
          in night_lights_conditions) }}'
        - '{{ (''time_enabled'' in night_lights_conditions)  and not (''sun_enabled''
          in night_lights_conditions) }}'
        - '{{ (''sun_enabled'' in night_lights_conditions) and (((is_state_attr(''sun.sun'',
          ''rising'', false)) and (state_attr(''sun.sun'',''elevation'') <= night_lights_sun_elevation
          | float(90))) or ((is_state_attr(''sun.sun'', ''rising'', true)) and (state_attr(''sun.sun'',''elevation'')
          <= night_lights_sun_elevation_rising | float(90)))) }}'
    sequence:
    - choose:
      - alias: By-pass is turned on & check by-pass option - Turn lights off
        conditions:
        - condition: trigger
          id: t8_off
        sequence:
        - alias: Wait the number of minutes set in the by-pass time delay
          delay:
            minutes: !input bypass_time_delay
        - choose:
          - alias: If transition is selected
            conditions:
            - condition: template
              value_template: '{{ ''use_transition'' in include_night_light_control
                }}'
            sequence:
            - alias: Turn off the lights
              service: light.turn_off
              target:
                entity_id: '{{ night_light_entities }}'
              data:
                transition: '{{ night_light_transition_off }}'
            - alias: Turn off the scenes
              service: scene.turn_on
              data:
                entity_id: '{{ end_scene_entities }}'
                transition: '{{ night_light_transition_off }}'
          - alias: If transition is not selected
            conditions:
            - condition: template
              value_template: '{{ ''use_transition'' not in include_night_light_control
                }}'
            sequence:
            - alias: Turn off the lights
              service: light.turn_off
              target:
                entity_id: '{{ night_light_entities }}'
            - alias: Turn off the scenes
              service: scene.turn_on
              data:
                entity_id: '{{ end_scene_entities }}'
        - alias: Turn off the switches
          service: switch.turn_off
          target:
            entity_id: '{{ night_switch_entities }}'
        - alias: Turn off the script
          service: script.turn_on
          data:
            entity_id: '{{ end_script_entities }}'
        - alias: Turn off the boolean for scenes and scripts
          service: input_boolean.turn_off
          data:
            entity_id: !input boolean_scenes_scripts
        - alias: Turn off the boolean for scenes and scripts
          service: input_boolean.turn_off
          data:
            entity_id: !input night_boolean_scenes_scripts
        - alias: Check by-pass settings and preform the correct action
          if:
          - alias: Check if the by-pass auto off is enabled
            condition: template
            value_template: '{{ (''bypass_auto_off_enabled_on'' in include_bypass_auto_off)
              or (''bypass_auto_off_enabled_off'' in include_bypass_auto_off) or (''bypass_auto_off_enabled_stop''
              in include_bypass_auto_off) }}'
          then:
          - alias: Wait the number of minutes set in the by-pass auto off time delay
            delay:
              minutes: !input bypass_auto_off_delay
          - alias: Parallel Actions for the by-pass auto off
            parallel:
            - sequence:
              - choose:
                - conditions:
                  - condition: template
                    value_template: '{{ (''bypass_enabled_turn_on'' in include_bypass)
                      and (''bypass_auto_off_enabled_on'' in include_bypass_auto_off)
                      }}'
                  sequence:
                  - alias: Turn off the by-pass
                    service: homeassistant.turn_off
                    entity_id: !input bypass_lights_on
            - sequence:
              - choose:
                - conditions:
                  - condition: template
                    value_template: '{{ (''bypass_enabled_turn_off'' in include_bypass)
                      and (''bypass_auto_off_enabled_off'' in include_bypass_auto_off)
                      }}'
                  sequence:
                  - alias: Turn off the by-pass
                    service: homeassistant.turn_off
                    entity_id: !input bypass_lights_off
            - sequence:
              - choose:
                - conditions:
                  - condition: template
                    value_template: '{{ (''bypass_enabled_stop'' in include_bypass)
                      and (''bypass_auto_off_enabled_stop'' in include_bypass_auto_off)
                      }}'
                  sequence:
                  - alias: Turn off the by-pass
                    service: homeassistant.turn_off
                    entity_id: !input bypass_lights_stop
          - stop: Stop the automation
          else:
          - stop: Stop the automation
      - alias: By-pass is turned on & check by-pass option - Keep the current lights
          state
        conditions:
        - condition: trigger
          id: t8_stop
        sequence:
        - alias: Check by-pass settings and preform the correct action
          if:
          - alias: Check if the by-pass auto off is enabled
            condition: template
            value_template: '{{ (''bypass_auto_off_enabled_on'' in include_bypass_auto_off)
              or (''bypass_auto_off_enabled_off'' in include_bypass_auto_off) or (''bypass_auto_off_enabled_stop''
              in include_bypass_auto_off) }}'
          then:
          - alias: Wait the number of minutes set in the by-pass auto off time delay
            delay:
              minutes: !input bypass_auto_off_delay
          - alias: Parallel Actions for the by-pass auto off
            parallel:
            - sequence:
              - choose:
                - conditions:
                  - condition: template
                    value_template: '{{ (''bypass_enabled_turn_on'' in include_bypass)
                      and (''bypass_auto_off_enabled_on'' in include_bypass_auto_off)
                      }}'
                  sequence:
                  - alias: Turn off the by-pass
                    service: homeassistant.turn_off
                    entity_id: !input bypass_lights_on
            - sequence:
              - choose:
                - conditions:
                  - condition: template
                    value_template: '{{ (''bypass_enabled_turn_off'' in include_bypass)
                      and (''bypass_auto_off_enabled_off'' in include_bypass_auto_off)
                      }}'
                  sequence:
                  - alias: Turn off the by-pass
                    service: homeassistant.turn_off
                    entity_id: !input bypass_lights_off
            - sequence:
              - choose:
                - conditions:
                  - condition: template
                    value_template: '{{ (''bypass_enabled_stop'' in include_bypass)
                      and (''bypass_auto_off_enabled_stop'' in include_bypass_auto_off)
                      }}'
                  sequence:
                  - alias: Turn off the by-pass
                    service: homeassistant.turn_off
                    entity_id: !input bypass_lights_stop
          - stop: Stop the automation
          else:
          - stop: Stop the automation
    - choose:
      - alias: By-pass is turned off & check if the trigger is off
        conditions:
        - condition: trigger
          id:
          - t9_on
          - t9_off
          - t9_stop
        - alias: Check if all triggers are OFF
          condition: and
          conditions:
          - condition: or
            conditions:
            - '{{ include_entity_state == [] }}'
            - '{{ (''entity_on'' not in include_entity_state ) }}'
            - '{{ (''entity_on'' in include_entity_state ) and (states[entity_input].state
              == ''off'') }}'
            - '{{ (''entity_off'' in include_entity_state ) and (states[entity_input].state
              == ''off'') }}'
          - condition: or
            conditions:
            - '{{ include_sun == [] }}'
            - '{{ (''sun_falling'' in include_sun) and (is_state_attr(''sun.sun'',
              ''rising'', false)) and (state_attr(''sun.sun'',''elevation'') >= sun_elevation
              | float(90)) }}'
            - '{{ (''sun_rising'' in include_sun) and (is_state_attr(''sun.sun'',
              ''rising'', true)) and (state_attr(''sun.sun'',''elevation'') >= sun_elevation_rising
              | float(90)) }}'
          - condition: or
            conditions:
            - '{{ include_ambient == [] }}'
            - '{{ (''ambient_high'' in include_ambient) and (states[ambient_light_sensor].state
              | int > ambient_light_value_off | int) }}'
            - condition: and
              conditions:
              - '{{ (''ambient_low'' in include_ambient) and (states[ambient_light_sensor].state
                | int > ambient_light_value | int) }}'
              - '{{ (''ambient_high'' not in include_ambient) }}'
          - condition: or
            conditions:
            - '{{ include_time == [] }}'
            - '{{ (''time_on'' not in include_time) and (''time_off'' in include_time)
              }}'
            - '{{ (''time_on'' in include_time) and (''time_off'' not in include_time)
              }}'
            - condition: and
              conditions:
              - condition: template
                value_template: '{{ (''time_on'' in include_time) and (''time_off''
                  in include_time) }}'
              - condition: time
                after: !input before_time
                before: !input after_time
        sequence:
        - choose:
          - alias: Check all by-pass are off
            conditions:
            - condition: or
              conditions:
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                  in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_on
                  state: 'off'
                - condition: state
                  entity_id: !input bypass_lights_off
                  state: 'off'
                - condition: state
                  entity_id: !input bypass_lights_stop
                  state: 'off'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                  in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_on
                  state: 'off'
                - condition: state
                  entity_id: !input bypass_lights_off
                  state: 'off'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                  not in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_on
                  state: 'off'
                - condition: state
                  entity_id: !input bypass_lights_stop
                  state: 'off'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                  in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_off
                  state: 'off'
                - condition: state
                  entity_id: !input bypass_lights_stop
                  state: 'off'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                  not in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_on
                  state: 'off'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                  in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_off
                  state: 'off'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                  not in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_stop
                  state: 'off'
            sequence:
            - alias: Wait the number of minutes set in the by-pass time delay
              delay:
                minutes: !input bypass_time_delay
            - choose:
              - alias: If transition is selected
                conditions:
                - condition: template
                  value_template: '{{ ''use_transition'' in include_night_light_control
                    }}'
                sequence:
                - alias: Turn off the lights
                  service: light.turn_off
                  target:
                    entity_id: '{{ night_light_entities }}'
                  data:
                    transition: '{{ night_light_transition_off }}'
                - alias: Turn off the scenes
                  service: scene.turn_on
                  data:
                    entity_id: '{{ end_scene_entities }}'
                    transition: '{{ night_light_transition_off }}'
              - alias: If transition is not selected
                conditions:
                - condition: template
                  value_template: '{{ ''use_transition'' not in include_night_light_control
                    }}'
                sequence:
                - alias: Turn off the lights
                  service: light.turn_off
                  target:
                    entity_id: '{{ night_light_entities }}'
                - alias: Turn off the scenes
                  service: scene.turn_on
                  data:
                    entity_id: '{{ end_scene_entities }}'
            - alias: Turn off the switches
              service: switch.turn_off
              target:
                entity_id: '{{ night_switch_entities }}'
            - alias: Turn off the script
              service: script.turn_on
              data:
                entity_id: '{{ end_script_entities }}'
            - alias: Turn off the boolean for scenes and scripts
              service: input_boolean.turn_off
              data:
                entity_id: !input boolean_scenes_scripts
            - alias: Turn off the boolean for scenes and scripts
              service: input_boolean.turn_off
              data:
                entity_id: !input night_boolean_scenes_scripts
            - stop: Stop the automation
          - alias: Trigger is off and check if any by-passes are on
            conditions:
            - condition: or
              conditions:
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                  in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                  }}'
                - condition: or
                  conditions:
                  - condition: state
                    entity_id: !input bypass_lights_on
                    match: any
                    state: 'on'
                  - condition: state
                    entity_id: !input bypass_lights_off
                    match: any
                    state: 'on'
                  - condition: state
                    entity_id: !input bypass_lights_stop
                    match: any
                    state: 'on'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                  in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                  }}'
                - condition: or
                  conditions:
                  - condition: state
                    entity_id: !input bypass_lights_on
                    match: any
                    state: 'on'
                  - condition: state
                    entity_id: !input bypass_lights_off
                    match: any
                    state: 'on'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                  not in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                  }}'
                - condition: or
                  conditions:
                  - condition: state
                    entity_id: !input bypass_lights_on
                    match: any
                    state: 'on'
                  - condition: state
                    entity_id: !input bypass_lights_stop
                    match: any
                    state: 'on'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                  in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                  }}'
                - condition: or
                  conditions:
                  - condition: state
                    entity_id: !input bypass_lights_off
                    match: any
                    state: 'on'
                  - condition: state
                    entity_id: !input bypass_lights_stop
                    match: any
                    state: 'on'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                  not in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_on
                  match: any
                  state: 'on'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                  in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_off
                  match: any
                  state: 'on'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                  not in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_stop
                  match: any
                  state: 'on'
            sequence:
            - alias: Check by-pass settings and preform the correct action
              if:
              - alias: Check if the by-pass auto off is enabled
                condition: template
                value_template: '{{ (''bypass_auto_off_enabled_on'' in include_bypass_auto_off)
                  or (''bypass_auto_off_enabled_off'' in include_bypass_auto_off)
                  or (''bypass_auto_off_enabled_stop'' in include_bypass_auto_off)
                  }}'
              then:
              - alias: Wait the number of minutes set in the by-pass auto off time
                  delay
                delay:
                  minutes: !input bypass_auto_off_delay
              - alias: Parallel Actions for the by-pass auto off
                parallel:
                - sequence:
                  - choose:
                    - conditions:
                      - condition: template
                        value_template: '{{ (''bypass_enabled_turn_on'' in include_bypass)
                          and (''bypass_auto_off_enabled_on'' in include_bypass_auto_off)
                          }}'
                      sequence:
                      - alias: Turn off the by-pass
                        service: homeassistant.turn_off
                        entity_id: !input bypass_lights_on
                - sequence:
                  - choose:
                    - conditions:
                      - condition: template
                        value_template: '{{ (''bypass_enabled_turn_off'' in include_bypass)
                          and (''bypass_auto_off_enabled_off'' in include_bypass_auto_off)
                          }}'
                      sequence:
                      - alias: Turn off the by-pass
                        service: homeassistant.turn_off
                        entity_id: !input bypass_lights_off
                - sequence:
                  - choose:
                    - conditions:
                      - condition: template
                        value_template: '{{ (''bypass_enabled_stop'' in include_bypass)
                          and (''bypass_auto_off_enabled_stop'' in include_bypass_auto_off)
                          }}'
                      sequence:
                      - alias: Turn off the by-pass
                        service: homeassistant.turn_off
                        entity_id: !input bypass_lights_stop
            - stop: Stop the automation
      - alias: By-pass is turned off & check if the trigger is on
        conditions:
        - condition: trigger
          id:
          - t9_on
          - t9_off
          - t9_stop
        - alias: Check if any triggers are ON
          condition: or
          conditions:
          - condition: or
            conditions:
            - '{{ (''entity_on'' in include_entity_state ) and (states[entity_input].state
              == ''on'') }}'
            - '{{ (''entity_off'' in include_entity_state ) and (states[entity_input].state
              == ''on'') }}'
          - condition: or
            conditions:
            - '{{ (''sun_falling'' in include_sun) and (is_state_attr(''sun.sun'',
              ''rising'', false)) and (state_attr(''sun.sun'',''elevation'') <= sun_elevation
              | float(90)) }}'
            - '{{ (''sun_rising'' in include_sun) and (is_state_attr(''sun.sun'',
              ''rising'', true)) and (state_attr(''sun.sun'',''elevation'') <= sun_elevation_rising
              | float(90)) }}'
          - condition: or
            conditions:
            - '{{ (''ambient_low'' in include_ambient) and (states[ambient_light_sensor].state
              | int < ambient_light_value | int) }}'
            - '{{ (''ambient_high'' in include_ambient) and (states[ambient_light_sensor].state
              | int < ambient_light_value_off | int) and (expand(night_lights.entity_id)
              | selectattr(''state'', ''=='', ''on'') | list | count > 0) }}'
          - condition: or
            conditions:
            - condition: and
              conditions:
              - condition: template
                value_template: '{{ (''time_on'' in include_time) and (''time_off''
                  in include_time) }}'
              - condition: time
                after: !input after_time
                before: !input before_time
        sequence:
        - choose:
          - alias: Check weekdays
            conditions:
            - condition: and
              conditions:
              - '{{ include_weekdays == ''weekday_enabled'' }}'
              - condition: not
                conditions:
                - condition: time
                  weekday: !input weekday_options
            sequence:
            - alias: Wait the number of minutes set in the by-pass time delay
              delay:
                minutes: !input bypass_time_delay
            - choose:
              - alias: If transition is selected
                conditions:
                - condition: template
                  value_template: '{{ ''use_transition'' in include_night_light_control
                    }}'
                sequence:
                - alias: Turn off the lights
                  service: light.turn_off
                  target:
                    entity_id: '{{ night_light_entities }}'
                  data:
                    transition: '{{ night_light_transition_off }}'
                - alias: Turn off the scenes
                  service: scene.turn_on
                  data:
                    entity_id: '{{ end_scene_entities }}'
                    transition: '{{ night_light_transition_off }}'
              - alias: If transition is not selected
                conditions:
                - condition: template
                  value_template: '{{ ''use_transition'' not in include_night_light_control
                    }}'
                sequence:
                - alias: Turn off the lights
                  service: light.turn_off
                  target:
                    entity_id: '{{ night_light_entities }}'
                - alias: Turn off the scenes
                  service: scene.turn_on
                  data:
                    entity_id: '{{ end_scene_entities }}'
            - alias: Turn off the switches
              service: switch.turn_off
              target:
                entity_id: '{{ night_switch_entities }}'
            - alias: Turn off the script
              service: script.turn_on
              data:
                entity_id: '{{ end_script_entities }}'
            - alias: Turn off the boolean for scenes and scripts
              service: input_boolean.turn_off
              data:
                entity_id: !input night_boolean_scenes_scripts
            - stop: Stop the automation
          - alias: Check all by-pass are off and check conditions if enabled
            conditions:
            - condition: or
              conditions:
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                  in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_on
                  state: 'off'
                - condition: state
                  entity_id: !input bypass_lights_off
                  state: 'off'
                - condition: state
                  entity_id: !input bypass_lights_stop
                  state: 'off'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                  in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_on
                  state: 'off'
                - condition: state
                  entity_id: !input bypass_lights_off
                  state: 'off'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                  not in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_on
                  state: 'off'
                - condition: state
                  entity_id: !input bypass_lights_stop
                  state: 'off'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                  in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_off
                  state: 'off'
                - condition: state
                  entity_id: !input bypass_lights_stop
                  state: 'off'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                  not in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_on
                  state: 'off'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                  in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_off
                  state: 'off'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                  not in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_stop
                  state: 'off'
            - alias: Check if all triggers are OFF
              condition: and
              conditions:
              - condition: or
                conditions:
                - '{{ include_entity_state == [] }}'
                - '{{ (''entity_on'' not in include_entity_state ) }}'
                - '{{ (''entity_on'' in include_entity_state ) and (states[entity_input].state
                  == ''off'') }}'
                - '{{ (''entity_off'' in include_entity_state ) and (states[entity_input].state
                  == ''off'') }}'
              - condition: or
                conditions:
                - '{{ include_sun == [] }}'
                - condition: and
                  conditions:
                  - '{{ (''sun_falling'' not in include_sun) }}'
                  - '{{ (''sun_rising'' in include_sun) and (is_state_attr(''sun.sun'',
                    ''rising'', true)) and (state_attr(''sun.sun'',''elevation'')
                    >= sun_elevation_rising | float(90)) }}'
                - condition: and
                  conditions:
                  - '{{ (''sun_falling'' in include_sun) and (is_state_attr(''sun.sun'',
                    ''rising'', false)) and (state_attr(''sun.sun'',''elevation'')
                    >= sun_elevation | float(90)) }}'
                  - '{{ (''sun_rising'' in include_sun) and (is_state_attr(''sun.sun'',
                    ''rising'', true)) and (state_attr(''sun.sun'',''elevation'')
                    >= sun_elevation_rising | float(90)) }}'
              - condition: or
                conditions:
                - '{{ include_ambient == [] }}'
                - '{{ (''ambient_high'' in include_ambient) and (states[ambient_light_sensor].state
                  | int > ambient_light_value_off | int) }}'
                - condition: and
                  conditions:
                  - '{{ (''ambient_low'' in include_ambient) and (states[ambient_light_sensor].state
                    | int > ambient_light_value | int) }}'
                  - '{{ (''ambient_high'' not in include_ambient) }}'
              - condition: or
                conditions:
                - '{{ include_time == [] }}'
                - '{{ (''time_on'' not in include_time) and (''time_off'' in include_time)
                  }}'
                - '{{ (''time_on'' in include_time) and (''time_off'' not in include_time)
                  }}'
                - condition: and
                  conditions:
                  - condition: template
                    value_template: '{{ (''time_on'' in include_time) and (''time_off''
                      in include_time) }}'
                  - condition: time
                    after: !input before_time
                    before: !input after_time
            sequence:
            - alias: Wait the number of minutes set in the by-pass time delay
              delay:
                minutes: !input bypass_time_delay
            - choose:
              - alias: If transition is selected
                conditions:
                - condition: template
                  value_template: '{{ ''use_transition'' in include_night_light_control
                    }}'
                sequence:
                - alias: Turn off the lights
                  service: light.turn_off
                  target:
                    entity_id: '{{ night_light_entities }}'
                  data:
                    transition: '{{ night_light_transition_off }}'
                - alias: Turn off the scenes
                  service: scene.turn_on
                  data:
                    entity_id: '{{ end_scene_entities }}'
                    transition: '{{ night_light_transition_off }}'
              - alias: If transition is not selected
                conditions:
                - condition: template
                  value_template: '{{ ''use_transition'' not in include_night_light_control
                    }}'
                sequence:
                - alias: Turn off the lights
                  service: light.turn_off
                  target:
                    entity_id: '{{ night_light_entities }}'
                - alias: Turn off the scenes
                  service: scene.turn_on
                  data:
                    entity_id: '{{ end_scene_entities }}'
            - alias: Turn off the switches
              service: switch.turn_off
              target:
                entity_id: '{{ night_switch_entities }}'
            - alias: Turn off the script
              service: script.turn_on
              data:
                entity_id: '{{ end_script_entities }}'
            - alias: Turn off the boolean for scenes and scripts
              service: input_boolean.turn_off
              data:
                entity_id: !input night_boolean_scenes_scripts
            - stop: Stop the automation
          - alias: Motion trigger is on and check if any by-passes are on
            conditions:
            - condition: or
              conditions:
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                  in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                  }}'
                - condition: or
                  conditions:
                  - condition: state
                    entity_id: !input bypass_lights_on
                    match: any
                    state: 'on'
                  - condition: state
                    entity_id: !input bypass_lights_off
                    match: any
                    state: 'on'
                  - condition: state
                    entity_id: !input bypass_lights_stop
                    match: any
                    state: 'on'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                  in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                  }}'
                - condition: or
                  conditions:
                  - condition: state
                    entity_id: !input bypass_lights_on
                    match: any
                    state: 'on'
                  - condition: state
                    entity_id: !input bypass_lights_off
                    match: any
                    state: 'on'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                  not in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                  }}'
                - condition: or
                  conditions:
                  - condition: state
                    entity_id: !input bypass_lights_on
                    match: any
                    state: 'on'
                  - condition: state
                    entity_id: !input bypass_lights_stop
                    match: any
                    state: 'on'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                  in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                  }}'
                - condition: or
                  conditions:
                  - condition: state
                    entity_id: !input bypass_lights_off
                    match: any
                    state: 'on'
                  - condition: state
                    entity_id: !input bypass_lights_stop
                    match: any
                    state: 'on'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                  not in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_on
                  match: any
                  state: 'on'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                  in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_off
                  match: any
                  state: 'on'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                  not in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_stop
                  match: any
                  state: 'on'
            sequence:
            - alias: Check by-pass settings and preform the correct action
              if:
              - alias: Check if the by-pass auto off is enabled
                condition: template
                value_template: '{{ (''bypass_auto_off_enabled_on'' in include_bypass_auto_off)
                  or (''bypass_auto_off_enabled_off'' in include_bypass_auto_off)
                  or (''bypass_auto_off_enabled_stop'' in include_bypass_auto_off)
                  }}'
              then:
              - alias: Wait the number of minutes set in the by-pass auto off time
                  delay
                delay:
                  minutes: !input bypass_auto_off_delay
              - alias: Parallel Actions for the by-pass auto off
                parallel:
                - sequence:
                  - choose:
                    - conditions:
                      - condition: template
                        value_template: '{{ (''bypass_enabled_turn_on'' in include_bypass)
                          and (''bypass_auto_off_enabled_on'' in include_bypass_auto_off)
                          }}'
                      sequence:
                      - alias: Turn off the by-pass
                        service: homeassistant.turn_off
                        entity_id: !input bypass_lights_on
                - sequence:
                  - choose:
                    - conditions:
                      - condition: template
                        value_template: '{{ (''bypass_enabled_turn_off'' in include_bypass)
                          and (''bypass_auto_off_enabled_off'' in include_bypass_auto_off)
                          }}'
                      sequence:
                      - alias: Turn off the by-pass
                        service: homeassistant.turn_off
                        entity_id: !input bypass_lights_off
                - sequence:
                  - choose:
                    - conditions:
                      - condition: template
                        value_template: '{{ (''bypass_enabled_stop'' in include_bypass)
                          and (''bypass_auto_off_enabled_stop'' in include_bypass_auto_off)
                          }}'
                      sequence:
                      - alias: Turn off the by-pass
                        service: homeassistant.turn_off
                        entity_id: !input bypass_lights_stop
            - stop: Stop the automation
    - choose:
      - alias: Turn off normal lights when trigger by start night lights conditions
        conditions:
        - condition: trigger
          id:
          - t10
          - t11
          - t12
        sequence:
        - choose:
          - alias: light - switch - scene - script is ON
            conditions:
            - '{{ (expand(light_switch.entity_id) | selectattr(''state'', ''=='',
              ''on'') | list | count > 0) or (expand(night_lights.entity_id) | selectattr(''state'',
              ''=='', ''on'') | list | count > 0) or (is_state(boolean_scenes_scripts,
              ''on'')) }}'
            sequence:
            - choose:
              - alias: If transition is selected
                conditions:
                - condition: template
                  value_template: '{{ ''use_transition'' in include_light_control
                    }}'
                sequence:
                - alias: Turn off the lights
                  service: light.turn_off
                  target:
                    entity_id: '{{ crossover_lights_light }}'
                  data:
                    transition: '{{ light_transition_off }}'
              - alias: If transition is not selected
                conditions:
                - condition: template
                  value_template: '{{ ''use_transition'' not in include_light_control
                    }}'
                sequence:
                - alias: Turn off the lights
                  service: light.turn_off
                  target:
                    entity_id: '{{ crossover_lights_light }}'
            - alias: Turn off the switches
              service: switch.turn_off
              target:
                entity_id: '{{ crossover_lights_switch }}'
            - alias: Turn off the script
              service: script.turn_on
              data:
                entity_id: '{{ end_script_entities }}'
            - choose:
              - alias: Adjust the lights settings when crossing over if lights are
                  ON is selected in night light control
                conditions:
                - condition: template
                  value_template: '{{ ''if_lights_are_on_adjust_when_crossing_over''
                    in include_night_light_control }}'
                sequence:
                - choose:
                  - alias: If transition is selected
                    conditions:
                    - condition: template
                      value_template: '{{ ''use_transition'' in include_light_control
                        }}'
                    sequence:
                    - alias: Turn off the scenes
                      service: scene.turn_on
                      data:
                        entity_id: '{{ end_scene_entities }}'
                        transition: '{{ light_transition_off }}'
                  - alias: If transition is not selected
                    conditions:
                    - condition: template
                      value_template: '{{ ''use_transition'' not in include_light_control
                        }}'
                    sequence:
                    - alias: Turn off the scenes
                      service: scene.turn_on
                      data:
                        entity_id: '{{ end_scene_entities }}'
                - alias: Turn off the input boolean normal lights
                  service: input_boolean.turn_off
                  data:
                    entity_id: !input boolean_scenes_scripts
                - alias: Turn ON lights
                  service: light.turn_on
                  target:
                    entity_id: '{{ crossover_night_lights_light_on }}'
                  data: '{{ night_light_data }}'
          - alias: light - switch - scene - script is ON
            conditions:
            - '{{ ''manage_scripts_crossing_over'' in include_night_light_control
              }}'
            - '{{ (expand(light_switch.entity_id) | selectattr(''state'', ''=='',
              ''off'') | list | count > 0) or (expand(night_lights.entity_id) | selectattr(''state'',
              ''=='', ''off'') | list | count > 0) or (is_state(boolean_scenes_scripts,
              ''off'')) }}'
            sequence:
            - alias: Turn off the script
              service: script.turn_on
              data:
                entity_id: '{{ end_script_entities }}'
            - stop: Stop the automation
      - alias: Safe Guard when HA restarts
        conditions:
        - condition: trigger
          id: t16
        sequence:
        - choose:
          - alias: Check all by-pass are off and check conditions if enabled
            conditions:
            - condition: or
              conditions:
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                  in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_on
                  state: 'off'
                - condition: state
                  entity_id: !input bypass_lights_off
                  state: 'off'
                - condition: state
                  entity_id: !input bypass_lights_stop
                  state: 'off'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                  in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_on
                  state: 'off'
                - condition: state
                  entity_id: !input bypass_lights_off
                  state: 'off'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                  not in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_on
                  state: 'off'
                - condition: state
                  entity_id: !input bypass_lights_stop
                  state: 'off'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                  in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_off
                  state: 'off'
                - condition: state
                  entity_id: !input bypass_lights_stop
                  state: 'off'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                  not in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_on
                  state: 'off'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                  in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_off
                  state: 'off'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                  not in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_stop
                  state: 'off'
            sequence:
            - choose:
              - alias: Check if any light are ON and all triggers are OFF
                conditions:
                - alias: Check if any lights are ON
                  condition: or
                  conditions:
                  - '{{ (expand(light_switch.entity_id) | selectattr(''state'', ''=='',
                    ''on'') | list | count > 0) }}'
                  - '{{ (include_night_lights == ''night_lights_enabled'') and (expand(night_lights.entity_id)
                    | selectattr(''state'', ''=='', ''on'') | list | count > 0) }}'
                  - condition: template
                    value_template: "{% if boolean_scenes_scripts != [] %}\n  {{ is_state(boolean_scenes_scripts,
                      'on') }}\n{% endif %}"
                  - condition: template
                    value_template: "{% if night_boolean_scenes_scripts != [] %}\n
                      \ {{ is_state(night_boolean_scenes_scripts, 'on') }}\n{% endif
                      %}"
                - alias: Check if all triggers are OFF
                  condition: and
                  conditions:
                  - condition: or
                    conditions:
                    - '{{ include_entity_state == [] }}'
                    - '{{ (''entity_on'' not in include_entity_state ) }}'
                    - '{{ (''entity_on'' in include_entity_state ) and (states[entity_input].state
                      == ''off'') }}'
                    - '{{ (''entity_off'' in include_entity_state ) and (states[entity_input].state
                      == ''off'') }}'
                  - condition: or
                    conditions:
                    - '{{ include_sun == [] }}'
                    - '{{ (''sun_falling'' in include_sun) and (is_state_attr(''sun.sun'',
                      ''rising'', false)) and (state_attr(''sun.sun'',''elevation'')
                      >= sun_elevation | float(90)) }}'
                    - '{{ (''sun_rising'' in include_sun) and (is_state_attr(''sun.sun'',
                      ''rising'', true)) and (state_attr(''sun.sun'',''elevation'')
                      >= sun_elevation_rising | float(90)) }}'
                  - condition: or
                    conditions:
                    - '{{ include_ambient == [] }}'
                    - '{{ (''ambient_high'' in include_ambient) and (states[ambient_light_sensor].state
                      | int > ambient_light_value_off | int) }}'
                    - condition: and
                      conditions:
                      - '{{ (''ambient_low'' in include_ambient) and (states[ambient_light_sensor].state
                        | int > ambient_light_value | int) }}'
                      - '{{ (''ambient_high'' not in include_ambient) }}'
                  - condition: or
                    conditions:
                    - '{{ include_time == [] }}'
                    - '{{ (''time_on'' not in include_time) and (''time_off'' in include_time)
                      }}'
                    - '{{ (''time_on'' in include_time) and (''time_off'' not in include_time)
                      }}'
                    - condition: and
                      conditions:
                      - condition: template
                        value_template: '{{ (''time_on'' in include_time) and (''time_off''
                          in include_time) }}'
                      - condition: time
                        after: !input before_time
                        before: !input after_time
                sequence:
                - alias: Wait the number of minutes set in the by-pass time delay
                  delay:
                    minutes: !input bypass_time_delay
                - choose:
                  - alias: If transition is selected
                    conditions:
                    - condition: template
                      value_template: '{{ ''use_transition'' in include_light_control
                        }}'
                    sequence:
                    - alias: Turn off the normal lights
                      service: light.turn_off
                      target:
                        entity_id: '{{ light_entities }}'
                      data:
                        transition: '{{ night_light_transition_off }}'
                    - alias: Turn off the night lights
                      service: light.turn_off
                      target:
                        entity_id: '{{ night_light_entities }}'
                      data:
                        transition: '{{ night_light_transition_off }}'
                    - alias: Turn off the scenes
                      service: scene.turn_on
                      data:
                        entity_id: '{{ end_scene_entities }}'
                        transition: '{{ night_light_transition_off }}'
                  - alias: If transition is not selected
                    conditions:
                    - condition: template
                      value_template: '{{ ''use_transition'' not in include_light_control
                        }}'
                    sequence:
                    - alias: Turn off the normal lights
                      service: light.turn_off
                      target:
                        entity_id: '{{ light_entities }}'
                    - alias: Turn off the night lights
                      service: light.turn_off
                      target:
                        entity_id: '{{ night_light_entities }}'
                    - alias: Turn off the scenes
                      service: scene.turn_on
                      data:
                        entity_id: '{{ end_scene_entities }}'
                - alias: Turn off the normal switches
                  service: switch.turn_off
                  target:
                    entity_id: '{{ switch_entities }}'
                - alias: Turn off the night switches
                  service: switch.turn_off
                  target:
                    entity_id: '{{ night_switch_entities }}'
                - alias: Turn off the script
                  service: script.turn_on
                  data:
                    entity_id: '{{ end_script_entities }}'
                - alias: Turn off the boolean for normal lights scenes and scripts
                  service: input_boolean.turn_off
                  data:
                    entity_id: !input boolean_scenes_scripts
                - alias: Turn off the boolean for night lights scenes and scripts
                  service: input_boolean.turn_off
                  data:
                    entity_id: !input night_boolean_scenes_scripts
                - stop: Stop the automation
          - alias: Check if any by-passes are on
            conditions:
            - condition: or
              conditions:
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                  in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                  }}'
                - condition: or
                  conditions:
                  - condition: state
                    entity_id: !input bypass_lights_on
                    match: any
                    state: 'on'
                  - condition: state
                    entity_id: !input bypass_lights_off
                    match: any
                    state: 'on'
                  - condition: state
                    entity_id: !input bypass_lights_stop
                    match: any
                    state: 'on'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                  in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                  }}'
                - condition: or
                  conditions:
                  - condition: state
                    entity_id: !input bypass_lights_on
                    match: any
                    state: 'on'
                  - condition: state
                    entity_id: !input bypass_lights_off
                    match: any
                    state: 'on'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                  not in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                  }}'
                - condition: or
                  conditions:
                  - condition: state
                    entity_id: !input bypass_lights_on
                    match: any
                    state: 'on'
                  - condition: state
                    entity_id: !input bypass_lights_stop
                    match: any
                    state: 'on'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                  in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                  }}'
                - condition: or
                  conditions:
                  - condition: state
                    entity_id: !input bypass_lights_off
                    match: any
                    state: 'on'
                  - condition: state
                    entity_id: !input bypass_lights_stop
                    match: any
                    state: 'on'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                  not in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_on
                  match: any
                  state: 'on'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                  in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_off
                  match: any
                  state: 'on'
              - condition: and
                conditions:
                - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                  not in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                  }}'
                - condition: state
                  entity_id: !input bypass_lights_stop
                  match: any
                  state: 'on'
            sequence:
            - alias: Check by-pass auto off is enabled and preform the correct action
              if:
              - alias: Check if the by-pass auto off is enabled
                condition: template
                value_template: '{{ (''bypass_auto_off_enabled_on'' in include_bypass_auto_off)
                  or (''bypass_auto_off_enabled_off'' in include_bypass_auto_off)
                  or (''bypass_auto_off_enabled_stop'' in include_bypass_auto_off)
                  }}'
              then:
              - alias: Wait the number of minutes set in the by-pass auto off time
                  delay
                delay:
                  minutes: !input bypass_auto_off_delay
              - alias: Parallel Actions for the by-pass auto off
                parallel:
                - sequence:
                  - choose:
                    - conditions:
                      - condition: template
                        value_template: '{{ (''bypass_enabled_turn_on'' in include_bypass)
                          and (''bypass_auto_off_enabled_on'' in include_bypass_auto_off)
                          }}'
                      sequence:
                      - alias: Turn off the by-pass
                        service: homeassistant.turn_off
                        entity_id: !input bypass_lights_on
                - sequence:
                  - choose:
                    - conditions:
                      - condition: template
                        value_template: '{{ (''bypass_enabled_turn_off'' in include_bypass)
                          and (''bypass_auto_off_enabled_off'' in include_bypass_auto_off)
                          }}'
                      sequence:
                      - alias: Turn off the by-pass
                        service: homeassistant.turn_off
                        entity_id: !input bypass_lights_off
                - sequence:
                  - choose:
                    - conditions:
                      - condition: template
                        value_template: '{{ (''bypass_enabled_stop'' in include_bypass)
                          and (''bypass_auto_off_enabled_stop'' in include_bypass_auto_off)
                          }}'
                      sequence:
                      - alias: Turn off the by-pass
                        service: homeassistant.turn_off
                        entity_id: !input bypass_lights_stop
            - stop: Stop the automation
    - choose:
      - conditions:
        - condition: or
          conditions:
          - condition: trigger
            id:
            - t0
            - t2
            - t4
            - t6
            - t8_on
            - t10
            - t11
            - t12
            - t16
          - condition: and
            conditions:
            - condition: trigger
              id:
              - t9_on
              - t9_off
              - t9_stop
            - condition: or
              conditions:
              - '{{ (''entity_on'' in include_entity_state ) and (states[entity_input].state
                == ''on'') }}'
              - '{{ (''sun_falling'' in include_sun) and (is_state_attr(''sun.sun'',
                ''rising'', false)) and (state_attr(''sun.sun'',''elevation'') <=
                sun_elevation | float(90)) }}'
              - '{{ (''sun_rising'' in include_sun) and (is_state_attr(''sun.sun'',
                ''rising'', true)) and (state_attr(''sun.sun'',''elevation'') <= sun_elevation_rising
                | float(90)) }}'
              - '{{ (''ambient_low'' in include_ambient) and (states[ambient_light_sensor].state
                | int < ambient_light_value | int) }}'
              - '{{ (''ambient_high'' in include_ambient) and (states[ambient_light_sensor].state
                | int < ambient_light_value_off | int) and (expand(light_switch.entity_id)
                | selectattr(''state'', ''=='', ''on'') | list | count > 0) }}'
              - condition: and
                conditions:
                - condition: template
                  value_template: '{{ (''time_on'' in include_time) and (''time_off''
                    in include_time) }}'
                - condition: time
                  after: !input after_time
                  before: !input before_time
        sequence:
        - alias: Turn ON lights
          service: light.turn_on
          target:
            entity_id: '{{ night_light_entities_off }}'
          data: '{{ night_light_data }}'
        - choose:
          - alias: Check if normal lights scenes or scripts helper is on - This is
              for scenes only when crossing over
            conditions:
            - condition: template
              value_template: "{% if boolean_scenes_scripts == [] %}\n  false\n{%
                elif is_state(boolean_scenes_scripts, 'on') %}\n  true\n{% else %}\n
                \ false\n{% endif %}"
            sequence:
          - alias: If transition is selected
            conditions:
            - condition: template
              value_template: '{{ ''use_transition'' in include_night_light_control
                }}'
            sequence:
            - alias: Turn on the night scenes
              service: scene.turn_on
              target:
                entity_id: '{{ night_scene_entities }}'
              data:
                transition: '{{ night_light_transition_on }}'
            - alias: Turn on the boolean for scenes and scripts
              service: input_boolean.turn_on
              data:
                entity_id: '{{ night_boolean_scenes_scripts_helper }}'
          - alias: If transition is not selected
            conditions:
            - condition: template
              value_template: '{{ ''use_transition'' not in include_night_light_control
                }}'
            sequence:
            - alias: Turn on the night scenes
              service: scene.turn_on
              target:
                entity_id: '{{ night_scene_entities }}'
            - alias: Turn on the boolean for scenes and scripts
              service: input_boolean.turn_on
              data:
                entity_id: '{{ night_boolean_scenes_scripts_helper }}'
        - alias: Turn on the night switches
          service: switch.turn_on
          target:
            entity_id: '{{ night_switch_entities_off }}'
        - alias: Turn on the night scripts
          service: script.turn_on
          target:
            entity_id: '{{ night_script_entities }}'
        - choose:
          - alias: By-pass is enabled & check by-pass option - Turn lights on
            conditions:
            - condition: trigger
              id: t8_on
            sequence:
            - alias: Check by-pass settings and preform the correct action
              if:
              - alias: Check if the by-pass auto off is enabled
                condition: template
                value_template: '{{ (''bypass_auto_off_enabled_on'' in include_bypass_auto_off)
                  or (''bypass_auto_off_enabled_off'' in include_bypass_auto_off)
                  or (''bypass_auto_off_enabled_stop'' in include_bypass_auto_off)
                  }}'
              then:
              - alias: Wait the number of minutes set in the by-pass auto off time
                  delay
                delay:
                  minutes: !input bypass_auto_off_delay
              - alias: Parallel Actions for the by-pass auto off
                parallel:
                - sequence:
                  - choose:
                    - conditions:
                      - condition: template
                        value_template: '{{ (''bypass_enabled_turn_on'' in include_bypass)
                          and (''bypass_auto_off_enabled_on'' in include_bypass_auto_off)
                          }}'
                      sequence:
                      - alias: Turn off the by-pass
                        service: homeassistant.turn_off
                        entity_id: !input bypass_lights_on
                - sequence:
                  - choose:
                    - conditions:
                      - condition: template
                        value_template: '{{ (''bypass_enabled_turn_off'' in include_bypass)
                          and (''bypass_auto_off_enabled_off'' in include_bypass_auto_off)
                          }}'
                      sequence:
                      - alias: Turn off the by-pass
                        service: homeassistant.turn_off
                        entity_id: !input bypass_lights_off
                - sequence:
                  - choose:
                    - conditions:
                      - condition: template
                        value_template: '{{ (''bypass_enabled_stop'' in include_bypass)
                          and (''bypass_auto_off_enabled_stop'' in include_bypass_auto_off)
                          }}'
                      sequence:
                      - alias: Turn off the by-pass
                        service: homeassistant.turn_off
                        entity_id: !input bypass_lights_stop
              - stop: Stop the automation
              else:
              - stop: Stop the automation
      - conditions:
        - condition: trigger
          id:
          - t1
          - t3
          - t5
          - t7
        sequence:
        - choose:
          - alias: If transition is selected
            conditions:
            - condition: template
              value_template: '{{ ''use_transition'' in include_night_light_control
                }}'
            sequence:
            - alias: Turn off the lights
              service: light.turn_off
              target:
                entity_id: '{{ night_light_entities }}'
              data:
                transition: '{{ night_light_transition_off }}'
            - alias: Turn off the scenes
              service: scene.turn_on
              data:
                entity_id: '{{ end_scene_entities }}'
                transition: '{{ night_light_transition_off }}'
          - alias: If transition is not selected
            conditions:
            - condition: template
              value_template: '{{ ''use_transition'' not in include_night_light_control
                }}'
            sequence:
            - alias: Turn off the lights
              service: light.turn_off
              target:
                entity_id: '{{ night_light_entities }}'
            - alias: Turn off the scenes
              service: scene.turn_on
              data:
                entity_id: '{{ end_scene_entities }}'
        - alias: Turn off the switches
          service: switch.turn_off
          target:
            entity_id: '{{ night_switch_entities }}'
        - alias: Turn off the script
          service: script.turn_on
          data:
            entity_id: '{{ end_script_entities }}'
        - alias: Turn off the boolean for scenes and scripts
          service: input_boolean.turn_off
          data:
            entity_id: !input night_boolean_scenes_scripts
  default:
  - choose:
    - alias: By-pass is turned on & check by-pass option - Turn lights off
      conditions:
      - condition: trigger
        id: t8_off
      sequence:
      - alias: Wait the number of minutes set in the by-pass time delay
        delay:
          minutes: !input bypass_time_delay
      - choose:
        - alias: If transition is selected
          conditions:
          - condition: template
            value_template: '{{ ''use_transition'' in include_light_control }}'
          sequence:
          - alias: Turn off the lights
            service: light.turn_off
            target:
              entity_id: '{{ light_entities }}'
            data:
              transition: '{{ light_transition_off }}'
          - alias: Turn off the scenes
            service: scene.turn_on
            data:
              entity_id: '{{ end_scene_entities }}'
              transition: '{{ light_transition_off }}'
        - alias: If transition is not selected
          conditions:
          - condition: template
            value_template: '{{ ''use_transition'' not in include_light_control }}'
          sequence:
          - alias: Turn off the lights
            service: light.turn_off
            target:
              entity_id: '{{ light_entities }}'
          - alias: Turn off the scenes
            service: scene.turn_on
            data:
              entity_id: '{{ end_scene_entities }}'
      - alias: Turn off the switches
        service: switch.turn_off
        target:
          entity_id: '{{ switch_entities }}'
      - alias: Turn off the script
        service: script.turn_on
        data:
          entity_id: '{{ end_script_entities }}'
      - alias: Turn off the boolean for scenes and scripts
        service: input_boolean.turn_off
        data:
          entity_id: !input boolean_scenes_scripts
      - alias: Turn off the boolean for scenes and scripts
        service: input_boolean.turn_off
        data:
          entity_id: !input night_boolean_scenes_scripts
      - alias: Check by-pass settings and preform the correct action
        if:
        - alias: Check if the by-pass auto off is enabled
          condition: template
          value_template: '{{ (''bypass_auto_off_enabled_on'' in include_bypass_auto_off)
            or (''bypass_auto_off_enabled_off'' in include_bypass_auto_off) or (''bypass_auto_off_enabled_stop''
            in include_bypass_auto_off) }}'
        then:
        - alias: Wait the number of minutes set in the by-pass auto off time delay
          delay:
            minutes: !input bypass_auto_off_delay
        - alias: Parallel Actions for the by-pass auto off
          parallel:
          - sequence:
            - choose:
              - conditions:
                - condition: template
                  value_template: '{{ (''bypass_enabled_turn_on'' in include_bypass)
                    and (''bypass_auto_off_enabled_on'' in include_bypass_auto_off)
                    }}'
                sequence:
                - alias: Turn off the by-pass
                  service: homeassistant.turn_off
                  entity_id: !input bypass_lights_on
          - sequence:
            - choose:
              - conditions:
                - condition: template
                  value_template: '{{ (''bypass_enabled_turn_off'' in include_bypass)
                    and (''bypass_auto_off_enabled_off'' in include_bypass_auto_off)
                    }}'
                sequence:
                - alias: Turn off the by-pass
                  service: homeassistant.turn_off
                  entity_id: !input bypass_lights_off
          - sequence:
            - choose:
              - conditions:
                - condition: template
                  value_template: '{{ (''bypass_enabled_stop'' in include_bypass)
                    and (''bypass_auto_off_enabled_stop'' in include_bypass_auto_off)
                    }}'
                sequence:
                - alias: Turn off the by-pass
                  service: homeassistant.turn_off
                  entity_id: !input bypass_lights_stop
        - stop: Stop the automation
        else:
        - stop: Stop the automation
    - alias: By-pass is turned on & check by-pass option - Keep the current lights
        state
      conditions:
      - condition: trigger
        id: t8_stop
      sequence:
      - alias: Check by-pass settings and preform the correct action
        if:
        - alias: Check if the by-pass auto off is enabled
          condition: template
          value_template: '{{ (''bypass_auto_off_enabled_on'' in include_bypass_auto_off)
            or (''bypass_auto_off_enabled_off'' in include_bypass_auto_off) or (''bypass_auto_off_enabled_stop''
            in include_bypass_auto_off) }}'
        then:
        - alias: Wait the number of minutes set in the by-pass auto off time delay
          delay:
            minutes: !input bypass_auto_off_delay
        - alias: Parallel Actions for the by-pass auto off
          parallel:
          - sequence:
            - choose:
              - conditions:
                - condition: template
                  value_template: '{{ (''bypass_enabled_turn_on'' in include_bypass)
                    and (''bypass_auto_off_enabled_on'' in include_bypass_auto_off)
                    }}'
                sequence:
                - alias: Turn off the by-pass
                  service: homeassistant.turn_off
                  entity_id: !input bypass_lights_on
          - sequence:
            - choose:
              - conditions:
                - condition: template
                  value_template: '{{ (''bypass_enabled_turn_off'' in include_bypass)
                    and (''bypass_auto_off_enabled_off'' in include_bypass_auto_off)
                    }}'
                sequence:
                - alias: Turn off the by-pass
                  service: homeassistant.turn_off
                  entity_id: !input bypass_lights_off
          - sequence:
            - choose:
              - conditions:
                - condition: template
                  value_template: '{{ (''bypass_enabled_stop'' in include_bypass)
                    and (''bypass_auto_off_enabled_stop'' in include_bypass_auto_off)
                    }}'
                sequence:
                - alias: Turn off the by-pass
                  service: homeassistant.turn_off
                  entity_id: !input bypass_lights_stop
        - stop: Stop the automation
        else:
        - stop: Stop the automation
  - choose:
    - alias: By-pass is turned off & check if the trigger is off
      conditions:
      - condition: and
        conditions:
        - condition: trigger
          id:
          - t9_on
          - t9_off
          - t9_stop
        - alias: Check if all triggers are OFF
          condition: and
          conditions:
          - condition: or
            conditions:
            - '{{ include_entity_state == [] }}'
            - '{{ (''entity_on'' in include_entity_state ) and (states[entity_input].state
              == ''off'') }}'
            - '{{ (''entity_off'' in include_entity_state ) and (states[entity_input].state
              == ''off'') }}'
          - condition: or
            conditions:
            - '{{ include_sun == [] }}'
            - '{{ (''sun_falling'' in include_sun) and (is_state_attr(''sun.sun'',
              ''rising'', false)) and (state_attr(''sun.sun'',''elevation'') >= sun_elevation
              | float(90)) }}'
            - '{{ (''sun_rising'' in include_sun) and (is_state_attr(''sun.sun'',
              ''rising'', true)) and (state_attr(''sun.sun'',''elevation'') >= sun_elevation_rising
              | float(90)) }}'
          - condition: or
            conditions:
            - '{{ include_ambient == [] }}'
            - '{{ (''ambient_high'' in include_ambient) and (states[ambient_light_sensor].state
              | int > ambient_light_value_off | int) }}'
            - condition: and
              conditions:
              - '{{ (''ambient_low'' in include_ambient) and (states[ambient_light_sensor].state
                | int > ambient_light_value | int) }}'
              - '{{ (''ambient_high'' not in include_ambient) }}'
          - condition: or
            conditions:
            - '{{ include_time == [] }}'
            - '{{ (''time_on'' not in include_time) and (''time_off'' in include_time)
              }}'
            - '{{ (''time_on'' in include_time) and (''time_off'' not in include_time)
              }}'
            - condition: and
              conditions:
              - condition: template
                value_template: '{{ (''time_on'' in include_time) and (''time_off''
                  in include_time) }}'
              - condition: time
                after: !input before_time
                before: !input after_time
      sequence:
      - choose:
        - alias: Check all by-pass are off
          conditions:
          - condition: or
            conditions:
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_on
                state: 'off'
              - condition: state
                entity_id: !input bypass_lights_off
                state: 'off'
              - condition: state
                entity_id: !input bypass_lights_stop
                state: 'off'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_on
                state: 'off'
              - condition: state
                entity_id: !input bypass_lights_off
                state: 'off'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                not in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_on
                state: 'off'
              - condition: state
                entity_id: !input bypass_lights_stop
                state: 'off'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_off
                state: 'off'
              - condition: state
                entity_id: !input bypass_lights_stop
                state: 'off'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                not in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_on
                state: 'off'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_off
                state: 'off'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                not in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_stop
                state: 'off'
          sequence:
          - alias: Wait the number of minutes set in the by-pass time delay
            delay:
              minutes: !input bypass_time_delay
          - choose:
            - alias: If transition is selected
              conditions:
              - condition: template
                value_template: '{{ ''use_transition'' in include_light_control }}'
              sequence:
              - alias: Turn off the lights
                service: light.turn_off
                target:
                  entity_id: '{{ light_entities }}'
                data:
                  transition: '{{ light_transition_off }}'
              - alias: Turn off the scenes
                service: scene.turn_on
                data:
                  entity_id: '{{ end_scene_entities }}'
                  transition: '{{ light_transition_off }}'
            - alias: If transition is not selected
              conditions:
              - condition: template
                value_template: '{{ ''use_transition'' not in include_light_control
                  }}'
              sequence:
              - alias: Turn off the lights
                service: light.turn_off
                target:
                  entity_id: '{{ light_entities }}'
              - alias: Turn off the scenes
                service: scene.turn_on
                data:
                  entity_id: '{{ end_scene_entities }}'
          - alias: Turn off the switches
            service: switch.turn_off
            target:
              entity_id: '{{ switch_entities }}'
          - alias: Turn off the script
            service: script.turn_on
            data:
              entity_id: '{{ end_script_entities }}'
          - alias: Turn off the boolean for scenes and scripts
            service: input_boolean.turn_off
            data:
              entity_id: !input boolean_scenes_scripts
          - alias: Turn off the boolean for scenes and scripts
            service: input_boolean.turn_off
            data:
              entity_id: !input night_boolean_scenes_scripts
          - stop: Stop the automation
        - alias: Trigger is off and check if any by-passes are on
          conditions:
          - condition: or
            conditions:
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                }}'
              - condition: or
                conditions:
                - condition: state
                  entity_id: !input bypass_lights_on
                  match: any
                  state: 'on'
                - condition: state
                  entity_id: !input bypass_lights_off
                  match: any
                  state: 'on'
                - condition: state
                  entity_id: !input bypass_lights_stop
                  match: any
                  state: 'on'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                }}'
              - condition: or
                conditions:
                - condition: state
                  entity_id: !input bypass_lights_on
                  match: any
                  state: 'on'
                - condition: state
                  entity_id: !input bypass_lights_off
                  match: any
                  state: 'on'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                not in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                }}'
              - condition: or
                conditions:
                - condition: state
                  entity_id: !input bypass_lights_on
                  match: any
                  state: 'on'
                - condition: state
                  entity_id: !input bypass_lights_stop
                  match: any
                  state: 'on'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                }}'
              - condition: or
                conditions:
                - condition: state
                  entity_id: !input bypass_lights_off
                  match: any
                  state: 'on'
                - condition: state
                  entity_id: !input bypass_lights_stop
                  match: any
                  state: 'on'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                not in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_on
                match: any
                state: 'on'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_off
                match: any
                state: 'on'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                not in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_stop
                match: any
                state: 'on'
          sequence:
          - alias: Check by-pass settings and preform the correct action
            if:
            - alias: Check if the by-pass auto off is enabled
              condition: template
              value_template: '{{ (''bypass_auto_off_enabled_on'' in include_bypass_auto_off)
                or (''bypass_auto_off_enabled_off'' in include_bypass_auto_off) or
                (''bypass_auto_off_enabled_stop'' in include_bypass_auto_off) }}'
            then:
            - alias: Wait the number of minutes set in the by-pass auto off time delay
              delay:
                minutes: !input bypass_auto_off_delay
            - alias: Parallel Actions for the by-pass auto off
              parallel:
              - sequence:
                - choose:
                  - conditions:
                    - condition: template
                      value_template: '{{ (''bypass_enabled_turn_on'' in include_bypass)
                        and (''bypass_auto_off_enabled_on'' in include_bypass_auto_off)
                        }}'
                    sequence:
                    - alias: Turn off the by-pass
                      service: homeassistant.turn_off
                      entity_id: !input bypass_lights_on
              - sequence:
                - choose:
                  - conditions:
                    - condition: template
                      value_template: '{{ (''bypass_enabled_turn_off'' in include_bypass)
                        and (''bypass_auto_off_enabled_off'' in include_bypass_auto_off)
                        }}'
                    sequence:
                    - alias: Turn off the by-pass
                      service: homeassistant.turn_off
                      entity_id: !input bypass_lights_off
              - sequence:
                - choose:
                  - conditions:
                    - condition: template
                      value_template: '{{ (''bypass_enabled_stop'' in include_bypass)
                        and (''bypass_auto_off_enabled_stop'' in include_bypass_auto_off)
                        }}'
                    sequence:
                    - alias: Turn off the by-pass
                      service: homeassistant.turn_off
                      entity_id: !input bypass_lights_stop
          - stop: Stop the automation
    - alias: By-pass is turned off & check if the trigger is on
      conditions:
      - condition: and
        conditions:
        - condition: trigger
          id:
          - t9_on
          - t9_off
          - t9_stop
        - alias: Check if any triggers are ON
          condition: or
          conditions:
          - condition: or
            conditions:
            - '{{ (''entity_on'' in include_entity_state ) and (states[entity_input].state
              == ''on'') }}'
            - '{{ (''entity_off'' in include_entity_state ) and (states[entity_input].state
              == ''on'') }}'
          - condition: or
            conditions:
            - '{{ (''sun_falling'' in include_sun) and (is_state_attr(''sun.sun'',
              ''rising'', false)) and (state_attr(''sun.sun'',''elevation'') <= sun_elevation
              | float(90)) }}'
            - '{{ (''sun_rising'' in include_sun) and (is_state_attr(''sun.sun'',
              ''rising'', true)) and (state_attr(''sun.sun'',''elevation'') <= sun_elevation_rising
              | float(90)) }}'
          - condition: or
            conditions:
            - '{{ (''ambient_low'' in include_ambient) and (states[ambient_light_sensor].state
              | int < ambient_light_value | int) }}'
            - '{{ (''ambient_high'' in include_ambient) and (states[ambient_light_sensor].state
              | int < ambient_light_value_off | int) and (expand(light_switch.entity_id)
              | selectattr(''state'', ''=='', ''on'') | list | count > 0) }}'
          - condition: or
            conditions:
            - condition: and
              conditions:
              - condition: template
                value_template: '{{ (''time_on'' in include_time) and (''time_off''
                  in include_time) }}'
              - condition: time
                after: !input after_time
                before: !input before_time
      sequence:
      - choose:
        - alias: Check weekdays
          conditions:
          - condition: and
            conditions:
            - '{{ include_weekdays == ''weekday_enabled'' }}'
            - condition: not
              conditions:
              - condition: time
                weekday: !input weekday_options
          sequence:
          - alias: Wait the number of minutes set in the by-pass time delay
            delay:
              minutes: !input bypass_time_delay
          - choose:
            - alias: If transition is selected
              conditions:
              - condition: template
                value_template: '{{ ''use_transition'' in include_light_control }}'
              sequence:
              - alias: Turn off the lights
                service: light.turn_off
                target:
                  entity_id: '{{ light_entities }}'
                data:
                  transition: '{{ light_transition_off }}'
              - alias: Turn off the scenes
                service: scene.turn_on
                data:
                  entity_id: '{{ end_scene_entities }}'
                  transition: '{{ light_transition_off }}'
            - alias: If transition is not selected
              conditions:
              - condition: template
                value_template: '{{ ''use_transition'' not in include_light_control
                  }}'
              sequence:
              - alias: Turn off the lights
                service: light.turn_off
                target:
                  entity_id: '{{ light_entities }}'
              - alias: Turn off the scenes
                service: scene.turn_on
                data:
                  entity_id: '{{ end_scene_entities }}'
          - alias: Turn off the switches
            service: switch.turn_off
            target:
              entity_id: '{{ switch_entities }}'
          - alias: Turn off the script
            service: script.turn_on
            data:
              entity_id: '{{ end_script_entities }}'
          - alias: Turn off the boolean for scenes and scripts
            service: input_boolean.turn_off
            data:
              entity_id: !input boolean_scenes_scripts
          - stop: Stop the automation
        - alias: Check all by-pass are off and check conditions if enabled
          conditions:
          - condition: or
            conditions:
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_on
                state: 'off'
              - condition: state
                entity_id: !input bypass_lights_off
                state: 'off'
              - condition: state
                entity_id: !input bypass_lights_stop
                state: 'off'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_on
                state: 'off'
              - condition: state
                entity_id: !input bypass_lights_off
                state: 'off'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                not in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_on
                state: 'off'
              - condition: state
                entity_id: !input bypass_lights_stop
                state: 'off'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_off
                state: 'off'
              - condition: state
                entity_id: !input bypass_lights_stop
                state: 'off'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                not in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_on
                state: 'off'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_off
                state: 'off'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                not in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_stop
                state: 'off'
          - alias: Check if all triggers are OFF
            condition: and
            conditions:
            - condition: or
              conditions:
              - '{{ include_entity_state == [] }}'
              - '{{ (''entity_on'' not in include_entity_state ) }}'
              - '{{ (''entity_on'' in include_entity_state ) and (states[entity_input].state
                == ''off'') }}'
              - '{{ (''entity_off'' in include_entity_state ) and (states[entity_input].state
                == ''off'') }}'
            - condition: or
              conditions:
              - '{{ include_sun == [] }}'
              - condition: and
                conditions:
                - '{{ (''sun_falling'' not in include_sun) }}'
                - '{{ (''sun_rising'' in include_sun) and (is_state_attr(''sun.sun'',
                  ''rising'', true)) and (state_attr(''sun.sun'',''elevation'') >=
                  sun_elevation_rising | float(90)) }}'
              - condition: and
                conditions:
                - '{{ (''sun_falling'' in include_sun) and (is_state_attr(''sun.sun'',
                  ''rising'', false)) and (state_attr(''sun.sun'',''elevation'') >=
                  sun_elevation | float(90)) }}'
                - '{{ (''sun_rising'' in include_sun) and (is_state_attr(''sun.sun'',
                  ''rising'', true)) and (state_attr(''sun.sun'',''elevation'') >=
                  sun_elevation_rising | float(90)) }}'
            - condition: or
              conditions:
              - '{{ include_ambient == [] }}'
              - '{{ (''ambient_high'' in include_ambient) and (states[ambient_light_sensor].state
                | int > ambient_light_value_off | int) }}'
              - condition: and
                conditions:
                - '{{ (''ambient_low'' in include_ambient) and (states[ambient_light_sensor].state
                  | int > ambient_light_value | int) }}'
                - '{{ (''ambient_high'' not in include_ambient) }}'
            - condition: or
              conditions:
              - '{{ include_time == [] }}'
              - '{{ (''time_on'' not in include_time) and (''time_off'' in include_time)
                }}'
              - '{{ (''time_on'' in include_time) and (''time_off'' not in include_time)
                }}'
              - condition: and
                conditions:
                - condition: template
                  value_template: '{{ (''time_on'' in include_time) and (''time_off''
                    in include_time) }}'
                - condition: time
                  after: !input before_time
                  before: !input after_time
          sequence:
          - alias: Wait the number of minutes set in the by-pass time delay
            delay:
              minutes: !input bypass_time_delay
          - choose:
            - alias: If transition is selected
              conditions:
              - condition: template
                value_template: '{{ ''use_transition'' in include_light_control }}'
              sequence:
              - alias: Turn off the lights
                service: light.turn_off
                target:
                  entity_id: '{{ light_entities }}'
                data:
                  transition: '{{ light_transition_off }}'
              - alias: Turn off the scenes
                service: scene.turn_on
                data:
                  entity_id: '{{ end_scene_entities }}'
                  transition: '{{ light_transition_off }}'
            - alias: If transition is not selected
              conditions:
              - condition: template
                value_template: '{{ ''use_transition'' not in include_light_control
                  }}'
              sequence:
              - alias: Turn off the lights
                service: light.turn_off
                target:
                  entity_id: '{{ light_entities }}'
              - alias: Turn off the scenes
                service: scene.turn_on
                data:
                  entity_id: '{{ end_scene_entities }}'
          - alias: Turn off the switches
            service: switch.turn_off
            target:
              entity_id: '{{ switch_entities }}'
          - alias: Turn off the script
            service: script.turn_on
            data:
              entity_id: '{{ end_script_entities }}'
          - alias: Turn off the boolean for scenes and scripts
            service: input_boolean.turn_off
            data:
              entity_id: !input boolean_scenes_scripts
          - stop: Stop the automation
        - alias: Trigger is on and check if any by-passes are on
          conditions:
          - condition: or
            conditions:
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                }}'
              - condition: or
                conditions:
                - condition: state
                  entity_id: !input bypass_lights_on
                  match: any
                  state: 'on'
                - condition: state
                  entity_id: !input bypass_lights_off
                  match: any
                  state: 'on'
                - condition: state
                  entity_id: !input bypass_lights_stop
                  match: any
                  state: 'on'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                }}'
              - condition: or
                conditions:
                - condition: state
                  entity_id: !input bypass_lights_on
                  match: any
                  state: 'on'
                - condition: state
                  entity_id: !input bypass_lights_off
                  match: any
                  state: 'on'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                not in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                }}'
              - condition: or
                conditions:
                - condition: state
                  entity_id: !input bypass_lights_on
                  match: any
                  state: 'on'
                - condition: state
                  entity_id: !input bypass_lights_stop
                  match: any
                  state: 'on'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                }}'
              - condition: or
                conditions:
                - condition: state
                  entity_id: !input bypass_lights_off
                  match: any
                  state: 'on'
                - condition: state
                  entity_id: !input bypass_lights_stop
                  match: any
                  state: 'on'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                not in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_on
                match: any
                state: 'on'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_off
                match: any
                state: 'on'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                not in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_stop
                match: any
                state: 'on'
          sequence:
          - alias: Check by-pass settings and preform the correct action
            if:
            - alias: Check if the by-pass auto off is enabled
              condition: template
              value_template: '{{ (''bypass_auto_off_enabled_on'' in include_bypass_auto_off)
                or (''bypass_auto_off_enabled_off'' in include_bypass_auto_off) or
                (''bypass_auto_off_enabled_stop'' in include_bypass_auto_off) }}'
            then:
            - alias: Wait the number of minutes set in the by-pass auto off time delay
              delay:
                minutes: !input bypass_auto_off_delay
            - alias: Parallel Actions for the by-pass auto off
              parallel:
              - sequence:
                - choose:
                  - conditions:
                    - condition: template
                      value_template: '{{ (''bypass_enabled_turn_on'' in include_bypass)
                        and (''bypass_auto_off_enabled_on'' in include_bypass_auto_off)
                        }}'
                    sequence:
                    - alias: Turn off the by-pass
                      service: homeassistant.turn_off
                      entity_id: !input bypass_lights_on
              - sequence:
                - choose:
                  - conditions:
                    - condition: template
                      value_template: '{{ (''bypass_enabled_turn_off'' in include_bypass)
                        and (''bypass_auto_off_enabled_off'' in include_bypass_auto_off)
                        }}'
                    sequence:
                    - alias: Turn off the by-pass
                      service: homeassistant.turn_off
                      entity_id: !input bypass_lights_off
              - sequence:
                - choose:
                  - conditions:
                    - condition: template
                      value_template: '{{ (''bypass_enabled_stop'' in include_bypass)
                        and (''bypass_auto_off_enabled_stop'' in include_bypass_auto_off)
                        }}'
                    sequence:
                    - alias: Turn off the by-pass
                      service: homeassistant.turn_off
                      entity_id: !input bypass_lights_stop
          - stop: Stop the automation
  - choose:
    - alias: Turn off night lights when trigger by end night lights conditions
      conditions:
      - condition: trigger
        id:
        - t13
        - t14
        - t15
      sequence:
      - choose:
        - alias: If transition is selected
          conditions:
          - '{{ (expand(light_switch.entity_id) | selectattr(''state'', ''=='', ''on'')
            | list | count > 0) or (expand(night_lights.entity_id) | selectattr(''state'',
            ''=='', ''on'') | list | count > 0) or (is_state(night_boolean_scenes_scripts,
            ''on'')) }}'
          sequence:
          - choose:
            - alias: If transition is selected
              conditions:
              - condition: template
                value_template: '{{ ''use_transition'' in include_night_light_control
                  }}'
              sequence:
              - alias: Turn off the lights
                service: light.turn_off
                target:
                  entity_id: '{{ crossover_night_lights_light }}'
                data:
                  transition: '{{ night_light_transition_off }}'
            - alias: If transition is not selected
              conditions:
              - condition: template
                value_template: '{{ ''use_transition'' not in include_night_light_control
                  }}'
              sequence:
              - alias: Turn off the lights
                service: light.turn_off
                target:
                  entity_id: '{{ crossover_night_lights_light }}'
          - alias: Turn off the switches
            service: switch.turn_off
            target:
              entity_id: '{{ crossover_night_lights_switch }}'
          - alias: Turn off the script
            service: script.turn_on
            data:
              entity_id: '{{ end_script_entities }}'
          - choose:
            - alias: Adjust the lights settings when crossing over if lights are ON
                is selected in night light control
              conditions:
              - condition: template
                value_template: '{{ ''if_lights_are_on_adjust_when_crossing_over''
                  in include_night_light_control }}'
              sequence:
              - choose:
                - alias: If transition is selected
                  conditions:
                  - condition: template
                    value_template: '{{ ''use_transition'' in include_night_light_control
                      }}'
                  sequence:
                  - alias: Turn off the scenes
                    service: scene.turn_on
                    data:
                      entity_id: '{{ end_scene_entities }}'
                      transition: '{{ night_light_transition_off }}'
                - alias: If transition is not selected
                  conditions:
                  - condition: template
                    value_template: '{{ ''use_transition'' not in include_night_light_control
                      }}'
                  sequence:
                  - alias: Turn off the scenes
                    service: scene.turn_on
                    data:
                      entity_id: '{{ end_scene_entities }}'
              - alias: Turn off the input boolean night lights
                service: input_boolean.turn_off
                data:
                  entity_id: !input night_boolean_scenes_scripts
              - choose:
                - alias: Turn ON lights
                  conditions:
                  - condition: template
                    value_template: '{{ include_dynamic_lighting == ''disable_dynamic_lighting''
                      }}'
                  sequence:
                  - service: light.turn_on
                    target:
                      entity_id: '{{ crossover_lights_light_on }}'
                    data: '{{ light_data }}'
        - alias: If transition is selected
          conditions:
          - '{{ ''manage_scripts_crossing_over'' in include_night_light_control }}'
          - '{{ (expand(light_switch.entity_id) | selectattr(''state'', ''=='', ''off'')
            | list | count > 0) or (expand(night_lights.entity_id) | selectattr(''state'',
            ''=='', ''off'') | list | count > 0) or (is_state(night_boolean_scenes_scripts,
            ''off'')) }}'
          sequence:
          - alias: Turn off the script
            service: script.turn_on
            data:
              entity_id: '{{ end_script_entities }}'
          - stop: Stop the automation
    - alias: Safe Guard when HA restarts
      conditions:
      - condition: trigger
        id: t16
      sequence:
      - choose:
        - alias: Check all by-pass are off and check conditions if enabled
          conditions:
          - condition: or
            conditions:
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_on
                state: 'off'
              - condition: state
                entity_id: !input bypass_lights_off
                state: 'off'
              - condition: state
                entity_id: !input bypass_lights_stop
                state: 'off'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_on
                state: 'off'
              - condition: state
                entity_id: !input bypass_lights_off
                state: 'off'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                not in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_on
                state: 'off'
              - condition: state
                entity_id: !input bypass_lights_stop
                state: 'off'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_off
                state: 'off'
              - condition: state
                entity_id: !input bypass_lights_stop
                state: 'off'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                not in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_on
                state: 'off'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_off
                state: 'off'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                not in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_stop
                state: 'off'
          sequence:
          - choose:
            - alias: Check if any light are ON and all triggers are OFF
              conditions:
              - alias: Check if any lights are ON
                condition: or
                conditions:
                - '{{ (expand(light_switch.entity_id) | selectattr(''state'', ''=='',
                  ''on'') | list | count > 0) }}'
                - '{{ (include_night_lights == ''night_lights_enabled'') and (expand(night_lights.entity_id)
                  | selectattr(''state'', ''=='', ''on'') | list | count > 0) }}'
                - condition: template
                  value_template: "{% if boolean_scenes_scripts != [] %}\n  {{ is_state(boolean_scenes_scripts,
                    'on') }}\n{% endif %}"
                - condition: template
                  value_template: "{% if night_boolean_scenes_scripts != [] %}\n  {{
                    is_state(night_boolean_scenes_scripts, 'on') }}\n{% endif %}"
              - alias: Check if all triggers are OFF
                condition: and
                conditions:
                - condition: or
                  conditions:
                  - '{{ include_entity_state == [] }}'
                  - '{{ (''entity_on'' not in include_entity_state ) }}'
                  - '{{ (''entity_on'' in include_entity_state ) and (states[entity_input].state
                    == ''off'') }}'
                  - '{{ (''entity_off'' in include_entity_state ) and (states[entity_input].state
                    == ''off'') }}'
                - condition: or
                  conditions:
                  - '{{ include_sun == [] }}'
                  - '{{ (''sun_falling'' in include_sun) and (is_state_attr(''sun.sun'',
                    ''rising'', false)) and (state_attr(''sun.sun'',''elevation'')
                    >= sun_elevation | float(90)) }}'
                  - '{{ (''sun_rising'' in include_sun) and (is_state_attr(''sun.sun'',
                    ''rising'', true)) and (state_attr(''sun.sun'',''elevation'')
                    >= sun_elevation_rising | float(90)) }}'
                - condition: or
                  conditions:
                  - '{{ include_ambient == [] }}'
                  - '{{ (''ambient_high'' in include_ambient) and (states[ambient_light_sensor].state
                    | int > ambient_light_value_off | int) }}'
                  - condition: and
                    conditions:
                    - '{{ (''ambient_low'' in include_ambient) and (states[ambient_light_sensor].state
                      | int > ambient_light_value | int) }}'
                    - '{{ (''ambient_high'' not in include_ambient) }}'
                - condition: or
                  conditions:
                  - '{{ include_time == [] }}'
                  - '{{ (''time_on'' not in include_time) and (''time_off'' in include_time)
                    }}'
                  - '{{ (''time_on'' in include_time) and (''time_off'' not in include_time)
                    }}'
                  - condition: and
                    conditions:
                    - condition: template
                      value_template: '{{ (''time_on'' in include_time) and (''time_off''
                        in include_time) }}'
                    - condition: time
                      after: !input before_time
                      before: !input after_time
              sequence:
              - alias: Wait the number of minutes set in the by-pass time delay
                delay:
                  minutes: !input bypass_time_delay
              - choose:
                - alias: If transition is selected
                  conditions:
                  - condition: template
                    value_template: '{{ ''use_transition'' in include_light_control
                      }}'
                  sequence:
                  - alias: Turn off the normal lights
                    service: light.turn_off
                    target:
                      entity_id: '{{ light_entities }}'
                    data:
                      transition: '{{ light_transition_off }}'
                  - alias: Turn off the night lights
                    service: light.turn_off
                    target:
                      entity_id: '{{ night_light_entities }}'
                    data:
                      transition: '{{ light_transition_off }}'
                  - alias: Turn off the scenes
                    service: scene.turn_on
                    data:
                      entity_id: '{{ end_scene_entities }}'
                      transition: '{{ light_transition_off }}'
                - alias: If transition is not selected
                  conditions:
                  - condition: template
                    value_template: '{{ ''use_transition'' not in include_light_control
                      }}'
                  sequence:
                  - alias: Turn off the normal lights
                    service: light.turn_off
                    target:
                      entity_id: '{{ light_entities }}'
                  - alias: Turn off the night lights
                    service: light.turn_off
                    target:
                      entity_id: '{{ night_light_entities }}'
                  - alias: Turn off the scenes
                    service: scene.turn_on
                    data:
                      entity_id: '{{ end_scene_entities }}'
              - alias: Turn off the normal switches
                service: switch.turn_off
                target:
                  entity_id: '{{ switch_entities }}'
              - alias: Turn off the night switches
                service: switch.turn_off
                target:
                  entity_id: '{{ night_switch_entities }}'
              - alias: Turn off the script
                service: script.turn_on
                data:
                  entity_id: '{{ end_script_entities }}'
              - alias: Turn off the boolean for normal lights scenes and scripts
                service: input_boolean.turn_off
                data:
                  entity_id: !input boolean_scenes_scripts
              - alias: Turn off the boolean for night lights scenes and scripts
                service: input_boolean.turn_off
                data:
                  entity_id: !input night_boolean_scenes_scripts
              - stop: Stop the automation
        - alias: Check if any by-passes are on
          conditions:
          - condition: or
            conditions:
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                }}'
              - condition: or
                conditions:
                - condition: state
                  entity_id: !input bypass_lights_on
                  match: any
                  state: 'on'
                - condition: state
                  entity_id: !input bypass_lights_off
                  match: any
                  state: 'on'
                - condition: state
                  entity_id: !input bypass_lights_stop
                  match: any
                  state: 'on'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                }}'
              - condition: or
                conditions:
                - condition: state
                  entity_id: !input bypass_lights_on
                  match: any
                  state: 'on'
                - condition: state
                  entity_id: !input bypass_lights_off
                  match: any
                  state: 'on'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                not in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                }}'
              - condition: or
                conditions:
                - condition: state
                  entity_id: !input bypass_lights_on
                  match: any
                  state: 'on'
                - condition: state
                  entity_id: !input bypass_lights_stop
                  match: any
                  state: 'on'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                }}'
              - condition: or
                conditions:
                - condition: state
                  entity_id: !input bypass_lights_off
                  match: any
                  state: 'on'
                - condition: state
                  entity_id: !input bypass_lights_stop
                  match: any
                  state: 'on'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off''
                not in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_on
                match: any
                state: 'on'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                in include_bypass) and (''bypass_enabled_stop'' not in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_off
                match: any
                state: 'on'
            - condition: and
              conditions:
              - '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off''
                not in include_bypass) and (''bypass_enabled_stop'' in include_bypass)
                }}'
              - condition: state
                entity_id: !input bypass_lights_stop
                match: any
                state: 'on'
          sequence:
          - alias: Check by-pass auto off is enabled and preform the correct action
            if:
            - alias: Check if the by-pass auto off is enabled
              condition: template
              value_template: '{{ (''bypass_auto_off_enabled_on'' in include_bypass_auto_off)
                or (''bypass_auto_off_enabled_off'' in include_bypass_auto_off) or
                (''bypass_auto_off_enabled_stop'' in include_bypass_auto_off) }}'
            then:
            - alias: Wait the number of minutes set in the by-pass auto off time delay
              delay:
                minutes: !input bypass_auto_off_delay
            - alias: Parallel Actions for the by-pass auto off
              parallel:
              - sequence:
                - choose:
                  - conditions:
                    - condition: template
                      value_template: '{{ (''bypass_enabled_turn_on'' in include_bypass)
                        and (''bypass_auto_off_enabled_on'' in include_bypass_auto_off)
                        }}'
                    sequence:
                    - alias: Turn off the by-pass
                      service: homeassistant.turn_off
                      entity_id: !input bypass_lights_on
              - sequence:
                - choose:
                  - conditions:
                    - condition: template
                      value_template: '{{ (''bypass_enabled_turn_off'' in include_bypass)
                        and (''bypass_auto_off_enabled_off'' in include_bypass_auto_off)
                        }}'
                    sequence:
                    - alias: Turn off the by-pass
                      service: homeassistant.turn_off
                      entity_id: !input bypass_lights_off
              - sequence:
                - choose:
                  - conditions:
                    - condition: template
                      value_template: '{{ (''bypass_enabled_stop'' in include_bypass)
                        and (''bypass_auto_off_enabled_stop'' in include_bypass_auto_off)
                        }}'
                    sequence:
                    - alias: Turn off the by-pass
                      service: homeassistant.turn_off
                      entity_id: !input bypass_lights_stop
          - stop: Stop the automation
  - choose:
    - conditions:
      - condition: or
        conditions:
        - condition: trigger
          id:
          - t0
          - t2
          - t4
          - t6
          - t8_on
          - t13
          - t14
          - t15
          - t16
        - condition: and
          conditions:
          - condition: trigger
            id:
            - t9_on
            - t9_off
            - t9_stop
          - condition: or
            conditions:
            - '{{ (''entity_on'' in include_entity_state ) and (states[entity_input].state
              == ''on'') }}'
            - '{{ (''sun_falling'' in include_sun) and (is_state_attr(''sun.sun'',
              ''rising'', false)) and (state_attr(''sun.sun'',''elevation'') <= sun_elevation
              | float(90)) }}'
            - '{{ (''sun_rising'' in include_sun) and (is_state_attr(''sun.sun'',
              ''rising'', true)) and (state_attr(''sun.sun'',''elevation'') <= sun_elevation_rising
              | float(90)) }}'
            - '{{ (''ambient_low'' in include_ambient) and (states[ambient_light_sensor].state
              | int < ambient_light_value | int) }}'
            - '{{ (''ambient_high'' in include_ambient) and (states[ambient_light_sensor].state
              | int < ambient_light_value_off | int) and (expand(light_switch.entity_id)
              | selectattr(''state'', ''=='', ''on'') | list | count > 0) }}'
            - condition: and
              conditions:
              - condition: template
                value_template: '{{ (''time_on'' in include_time) and (''time_off''
                  in include_time) }}'
              - condition: time
                after: !input after_time
                before: !input before_time
      sequence:
      - alias: Parallel actions for dynamic lighting and normal lights
        parallel:
        - sequence:
          - alias: Check if the dynamic lighting is enabled
            condition: and
            conditions:
            - condition: template
              value_template: '{{ include_dynamic_lighting != ''disable_dynamic_lighting''
                }}'
          - choose:
            - alias: Dynamic Lighting - Input Boolean Helper
              conditions:
              - condition: template
                value_template: '{{ dynamic_lighting_boolean != [] }}'
              sequence:
              - alias: Turn on the boolean for dynamic lighting
                service: input_boolean.turn_on
                data:
                  entity_id: !input dynamic_lighting_boolean
          - choose:
            - alias: 1 - Dynamic Lighting - Lux Controlled Brightness
              conditions:
              - condition: template
                value_template: '{{ include_dynamic_lighting == ''enable_lux_controled_brightness''}}'
              sequence:
              - alias: Dynamic Lighting Control
                repeat:
                  until: '{{ ((dynamic_lighting_boolean == []) and (expand(light_entities)
                    | selectattr(''state'', ''=='', ''off'') | list | count > 0))
                    or ((dynamic_lighting_boolean != []) and (is_state(dynamic_lighting_boolean,
                    ''off''))) }}'
                  sequence:
                  - variables:
                      dynamic_brightness_pct: "{% set lux = states(dynamic_lighting_lux_sensor)
                        | float %} {% set slope = (dynamic_lighting_min_brightness
                        - dynamic_lighting_max_brightness) / (dynamic_lighting_max_lux
                        - dynamic_lighting_min_lux) %} {% set ak = (( slope * dynamic_lighting_min_lux)
                        * -1) + dynamic_lighting_max_brightness %} {% set le = light_entities
                        %} {% set lec = expand(le) | map(attribute='entity_id') |
                        list | length %} {% set lp = (expand(le) | map(attribute='attributes.brightness')
                        | reject('equalto', None) | sum | float(default=255) / 255
                        * 100 / lec) | round(0) %} {% if lux <= dynamic_lighting_min_lux
                        %}\n  {% set bv = dynamic_lighting_max_brightness %}\n{% elif
                        lux >= dynamic_lighting_max_lux %}\n  {% set bv = dynamic_lighting_min_brightness
                        %}\n{% else %}\n  {% set bv = ((slope * lux) + ak) | round(1)
                        %}\n{% endif %} {% if lp <= 0 %}\n  {% set bv = bv %}\n{%
                        elif (bv > lp) and (dynamic_lighting_max_brightness - lp)
                        <= dynamic_lighting_dead_zone %}\n  {% set bv = dynamic_lighting_max_brightness
                        %}\n{% elif (lp > bv) and (lp - dynamic_lighting_min_brightness)
                        <= dynamic_lighting_dead_zone %}\n  {% set bv = dynamic_lighting_min_brightness
                        %}\n{% elif (bv > lp) and (bv - lp) <= dynamic_lighting_dead_zone
                        %}\n  {% set bv = lp %}\n{% elif (lp > bv) and (lp - bv) <=
                        dynamic_lighting_dead_zone %}\n  {% set bv = lp %}\n{% elif
                        bv > (lp + dynamic_lighting_step_value) %}\n  {% set bv =
                        lp + dynamic_lighting_step_value %}\n{% elif bv < (lp - dynamic_lighting_step_value)
                        %}\n  {% set bv = lp - dynamic_lighting_step_value %}\n{%
                        endif %} {{ bv | round(0) }}\n"
                      dynamic_light_data: "{% set light = namespace(data={}) %} {%
                        set light.data = dict(light.data, **{ 'brightness_pct': dynamic_brightness_pct
                        }) %} {% if 'use_transition' in include_light_control %}\n
                        \ {% set light.data = dict(light.data, **{ 'transition': light_transition_on
                        }) %}\n{% endif %} {% if include_light_colour_control == 'use_colour_temperature'
                        %}\n  {% set light.data = dict(light.data, **{ 'color_temp_kelvin':
                        light_colour_temperature }) %}\n{% endif %} {% if include_light_colour_control
                        == 'use_rgb_colour' %}\n  {% set light.data = dict(light.data,
                        **{ 'rgb_color': light_rgb_colour }) %}\n{% endif %} {% if
                        include_light_colour_control == 'use_rgbw_colour' %}\n  {%
                        set light.data = dict(light.data, **{ 'rgbw_color': light_rgbw_colour
                        }) %}\n{% endif %} {% if include_light_colour_control == 'use_rgbww_colour'
                        %}\n  {% set light.data = dict(light.data, **{ 'rgbww_color':
                        light_rgbww_colour }) %}\n{% endif %} {{ light.data }}\n"
                      in_dead_zone: "{% set lux = states(dynamic_lighting_lux_sensor)
                        | float %} {% set slope = (dynamic_lighting_min_brightness
                        - dynamic_lighting_max_brightness) / (dynamic_lighting_max_lux
                        - dynamic_lighting_min_lux) %} {% set ak = (( slope * dynamic_lighting_min_lux)
                        * -1) + dynamic_lighting_max_brightness %} {% set le = light_entities
                        %} {% set lec = expand(le) | map(attribute='entity_id') |
                        list | length %} {% set lp = (expand(le) | map(attribute='attributes.brightness')
                        | reject('equalto', None) | sum | float(default=255) / 255
                        * 100 / lec) | round(0) %} {% if lux <= dynamic_lighting_min_lux
                        %}\n  {% set bv = dynamic_lighting_max_brightness %}\n{% elif
                        lux >= dynamic_lighting_max_lux %}\n  {% set bv = dynamic_lighting_min_brightness
                        %}\n{% else %}\n  {% set bv = ((slope * lux) + ak) | round(1)
                        %}\n{% endif %} {% if (bv > lp) and (dynamic_lighting_max_brightness
                        - lp) <= dynamic_lighting_dead_zone %}\n  false\n{% elif (lp
                        > bv) and (lp - dynamic_lighting_min_brightness) <= dynamic_lighting_dead_zone
                        %}\n  false\n{% elif (bv >= lp) and (bv - lp) <= dynamic_lighting_dead_zone
                        %}\n  true\n{% elif (lp >= bv) and (lp - bv) <= dynamic_lighting_dead_zone
                        %}\n  true\n{% else %}\n  false\n{% endif %}\n"
                  - choose:
                    - alias: Stop when crossing over
                      conditions:
                      - condition: template
                        value_template: '{{ ''if_lights_are_on_adjust_when_crossing_over''
                          not in include_night_light_control }}'
                      - condition: trigger
                        id:
                        - t13
                        - t14
                        - t15
                      sequence:
                      - stop: Stop the automation
                    - alias: Adjust the lights settings when crossing over if lights
                        are ON is selected in night light control
                      conditions:
                      - condition: template
                        value_template: '{{ ''if_lights_are_on_adjust_when_crossing_over''
                          in include_night_light_control }}'
                      - condition: trigger
                        id:
                        - t13
                        - t14
                        - t15
                      sequence:
                      - service: light.turn_on
                        target:
                          entity_id: '{{ light_entities }}'
                        data: '{{ dynamic_light_data }}'
                      - alias: Dynamic lighting heartbeat
                        delay:
                          minutes: !input dynamic_lighting_heartbeat
                    - alias: If dynamic lighting brightness is in the dead zone
                      conditions: '{{ in_dead_zone }}'
                      sequence:
                      - alias: Dynamic lighting heartbeat
                        delay:
                          minutes: !input dynamic_lighting_heartbeat
                    - alias: Set the dynamic lighting brightness for the normal lights
                      conditions:
                      - condition: template
                        value_template: '{{ include_dynamic_lighting == ''enable_lux_controled_brightness''
                          }}'
                      sequence:
                      - service: light.turn_on
                        target:
                          entity_id: '{{ light_entities }}'
                        data: '{{ dynamic_light_data }}'
                      - alias: Dynamic lighting heartbeat
                        delay:
                          minutes: !input dynamic_lighting_heartbeat
          - choose:
            - alias: 2 - Dynamic Lighting - Lux Controlled Brightness - Inverted
              conditions:
              - condition: template
                value_template: '{{ include_dynamic_lighting == ''enable_lux_controled_brightness_inv''}}'
              sequence:
              - alias: Dynamic Lighting Control
                repeat:
                  until: '{{ ((dynamic_lighting_boolean == []) and (expand(light_entities)
                    | selectattr(''state'', ''=='', ''off'') | list | count > 0))
                    or ((dynamic_lighting_boolean != []) and (is_state(dynamic_lighting_boolean,
                    ''off''))) }}'
                  sequence:
                  - variables:
                      dynamic_brightness_pct: "{% set lux = states(dynamic_lighting_lux_sensor)
                        | float %} {% set slope = (dynamic_lighting_min_brightness
                        - dynamic_lighting_max_brightness) / (dynamic_lighting_min_lux
                        - dynamic_lighting_max_lux) %} {% set ak = (( slope * dynamic_lighting_min_lux)
                        * -1) + dynamic_lighting_min_brightness %} {% set le = light_entities
                        %} {% set lec = expand(le) | map(attribute='entity_id') |
                        list | length %} {% set lp = (expand(le) | map(attribute='attributes.brightness')
                        | reject('equalto', None) | sum | float(default=255) / 255
                        * 100 / lec) | round(0) %} {% if lux <= dynamic_lighting_min_lux
                        %}\n  {% set bv = dynamic_lighting_min_brightness %}\n{% elif
                        lux >= dynamic_lighting_max_lux %}\n  {% set bv = dynamic_lighting_max_brightness
                        %}\n{% else %}\n  {% set bv = ((slope * lux) + ak) | round(1)
                        %}\n{% endif %} {% if lp <= 0 %}\n  {% set bv = bv %}\n{%
                        elif (bv > lp) and (dynamic_lighting_max_brightness - lp)
                        <= dynamic_lighting_dead_zone %}\n  {% set bv = dynamic_lighting_max_brightness
                        %}\n{% elif (lp > bv) and (lp - dynamic_lighting_min_brightness)
                        <= dynamic_lighting_dead_zone %}\n  {% set bv = dynamic_lighting_min_brightness
                        %}\n{% elif (bv > lp) and (bv - lp) <= dynamic_lighting_dead_zone
                        %}\n  {% set bv = lp %}\n{% elif (lp > bv) and  (lp - bv)
                        <= dynamic_lighting_dead_zone %}\n  {% set bv = lp %}\n{%
                        elif bv > (lp + dynamic_lighting_step_value) %}\n  {% set
                        bv = lp + dynamic_lighting_step_value %}\n{% elif bv < (lp
                        - dynamic_lighting_step_value) %}\n  {% set bv = lp - dynamic_lighting_step_value
                        %}\n{% endif %} {{ bv | round(0) }}\n"
                      dynamic_light_data: "{% set light = namespace(data={}) %} {%
                        set light.data = dict(light.data, **{ 'brightness_pct': dynamic_brightness_pct
                        }) %} {% if 'use_transition' in include_light_control %}\n
                        \ {% set light.data = dict(light.data, **{ 'transition': light_transition_on
                        }) %}\n{% endif %} {% if include_light_colour_control == 'use_colour_temperature'
                        %}\n  {% set light.data = dict(light.data, **{ 'color_temp_kelvin':
                        light_colour_temperature }) %}\n{% endif %} {% if include_light_colour_control
                        == 'use_rgb_colour' %}\n  {% set light.data = dict(light.data,
                        **{ 'rgb_color': light_rgb_colour }) %}\n{% endif %} {% if
                        include_light_colour_control == 'use_rgbw_colour' %}\n  {%
                        set light.data = dict(light.data, **{ 'rgbw_color': light_rgbw_colour
                        }) %}\n{% endif %} {% if include_light_colour_control == 'use_rgbww_colour'
                        %}\n  {% set light.data = dict(light.data, **{ 'rgbww_color':
                        light_rgbww_colour }) %}\n{% endif %} {{ light.data }}\n"
                      in_dead_zone: "{% set lux = states(dynamic_lighting_lux_sensor)
                        | float %} {% set slope = (dynamic_lighting_min_brightness
                        - dynamic_lighting_max_brightness) / (dynamic_lighting_min_lux
                        - dynamic_lighting_max_lux) %} {% set ak = (( slope * dynamic_lighting_min_lux)
                        * -1) + dynamic_lighting_min_brightness %} {% set le = light_entities
                        %} {% set lec = expand(le) | map(attribute='entity_id') |
                        list | length %} {% set lp = (expand(le) | map(attribute='attributes.brightness')
                        | reject('equalto', None) | sum | float(default=255) / 255
                        * 100 / lec) | round(0) %} {% if lux <= dynamic_lighting_min_lux
                        %}\n  {% set bv = dynamic_lighting_min_brightness %}\n{% elif
                        lux >= dynamic_lighting_max_lux %}\n  {% set bv = dynamic_lighting_max_brightness
                        %}\n{% else %}\n  {% set bv = ((slope * lux) + ak) | round(1)
                        %}\n{% endif %} {% if (bv > lp) and (dynamic_lighting_max_brightness
                        - lp) <= dynamic_lighting_dead_zone %}\n  true\n{% elif (lp
                        > bv) and (lp - dynamic_lighting_min_brightness) <= dynamic_lighting_dead_zone
                        %}\n  false\n{% elif (bv >= lp) and (bv - lp) <= dynamic_lighting_dead_zone
                        %}\n  true\n{% elif (lp >= bv) and (lp - bv) <= dynamic_lighting_dead_zone
                        %}\n  true\n{% else %}\n  false\n{% endif %}\n"
                  - choose:
                    - alias: Stop when crossing over
                      conditions:
                      - condition: template
                        value_template: '{{ ''if_lights_are_on_adjust_when_crossing_over''
                          not in include_night_light_control }}'
                      - condition: trigger
                        id:
                        - t13
                        - t14
                        - t15
                      sequence:
                      - stop: Stop the automation
                    - alias: Adjust the lights settings when crossing over if lights
                        are ON is selected in night light control
                      conditions:
                      - condition: template
                        value_template: '{{ ''if_lights_are_on_adjust_when_crossing_over''
                          in include_night_light_control }}'
                      - condition: trigger
                        id:
                        - t13
                        - t14
                        - t15
                      sequence:
                      - service: light.turn_on
                        target:
                          entity_id: '{{ light_entities }}'
                        data: '{{ dynamic_light_data }}'
                      - alias: Dynamic lighting heartbeat
                        delay:
                          minutes: !input dynamic_lighting_heartbeat
                    - alias: If dynamic lighting brightness is in the dead zone
                      conditions: '{{ in_dead_zone }}'
                      sequence:
                      - alias: Dynamic lighting heartbeat
                        delay:
                          minutes: !input dynamic_lighting_heartbeat
                    - alias: Set dynamic lighting brightness inverted for the normal
                        lights
                      conditions:
                      - condition: template
                        value_template: '{{ include_dynamic_lighting == ''enable_lux_controled_brightness_inv''
                          }}'
                      sequence:
                      - service: light.turn_on
                        target:
                          entity_id: '{{ light_entities }}'
                        data: '{{ dynamic_light_data }}'
                      - alias: Dynamic lighting heartbeat
                        delay:
                          minutes: !input dynamic_lighting_heartbeat
          - choose:
            - alias: 3 - Dynamic Lighting - Sun Elevation Lighting - Colour Temp
              conditions:
              - condition: template
                value_template: '{{ include_dynamic_lighting == ''enable_sun_elevation_colour''
                  }}'
              sequence:
              - alias: Dynamic Lighting Control
                repeat:
                  until: '{{ ((dynamic_lighting_boolean == []) and (expand(light_entities)
                    | selectattr(''state'', ''=='', ''off'') | list | count > 0))
                    or ((dynamic_lighting_boolean != []) and (is_state(dynamic_lighting_boolean,
                    ''off''))) }}'
                  sequence:
                  - variables:
                      dynamic_kelvin: "{% set elevation = state_attr('sun.sun', 'elevation')
                        | float %} {% set start_slope = (dynamic_lighting_min_colour_temp
                        - dynamic_lighting_max_colour_temp) / (dynamic_lighting_sun_elevation_start_rising
                        - dynamic_lighting_sun_elevation_end_rising) %} {% set start_ak
                        = (( start_slope * dynamic_lighting_sun_elevation_end_rising)
                        * -1) + dynamic_lighting_max_colour_temp %} {% set end_slope
                        = (dynamic_lighting_min_colour_temp - dynamic_lighting_max_colour_temp)
                        / (dynamic_lighting_sun_elevation_end_falling - dynamic_lighting_sun_elevation_start_falling)
                        %} {% set end_ak = (( end_slope * dynamic_lighting_sun_elevation_end_falling)
                        * -1) + dynamic_lighting_min_colour_temp %} {% if elevation
                        >= -10 %}\n  {% if elevation >= dynamic_lighting_sun_elevation_start_rising
                        and elevation <= dynamic_lighting_sun_elevation_end_rising
                        and is_state_attr('sun.sun', 'rising', true) %}\n    {% set
                        colour_temp_value = ((start_slope * elevation) + start_ak)
                        | round(1) %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_falling
                        and elevation >= dynamic_lighting_sun_elevation_end_falling
                        and is_state_attr('sun.sun', 'rising', false) %}\n    {% set
                        colour_temp_value = ((end_slope * elevation) + end_ak) | round(1)
                        %}\n  {% elif elevation >= dynamic_lighting_sun_elevation_end_rising
                        and elevation >= dynamic_lighting_sun_elevation_start_falling
                        \ %}\n    {% set colour_temp_value = dynamic_lighting_max_colour_temp
                        %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_rising
                        and is_state_attr('sun.sun', 'rising', true) %}\n    {% set
                        colour_temp_value = dynamic_lighting_min_colour_temp %}\n
                        \ {% elif elevation <= dynamic_lighting_sun_elevation_end_falling
                        and is_state_attr('sun.sun', 'rising', false) %}\n    {% set
                        colour_temp_value = dynamic_lighting_min_colour_temp %}\n
                        \ {% else %}\n    {% set colour_temp_value = dynamic_lighting_max_colour_temp
                        %}\n  {% endif %}\n{% else %}\n  {% set colour_temp_value
                        = dynamic_lighting_min_colour_temp %}\n{% endif %} {{ colour_temp_value
                        | round(0) }}\n"
                      dynamic_light_data: "{% set light = namespace(data={}) %} {%
                        set light.data = dict(light.data, **{ 'color_temp_kelvin':
                        dynamic_kelvin }) %} {% if 'use_transition' in include_light_control
                        %}\n  {% set light.data = dict(light.data, **{ 'transition':
                        light_transition_on }) %}\n{% endif %} {% if 'use_brightness'
                        in include_light_control %}\n  {% set light.data = dict(light.data,
                        **{ 'brightness_pct': light_brightness }) %}\n{% endif %}
                        {{ light.data }}\n"
                      should_wait: "{% set elevation = state_attr('sun.sun', 'elevation')
                        | float %} {% if expand(light_entities) | selectattr('state',
                        '==', 'on') | list | count > 0 %}\n  {% if elevation >= (dynamic_lighting_sun_elevation_start_rising
                        - 2) and elevation <= (dynamic_lighting_sun_elevation_end_rising
                        + 2) and is_state_attr('sun.sun', 'rising', true) %}\n    false\n
                        \ {% elif elevation <= (dynamic_lighting_sun_elevation_start_falling
                        + 2) and elevation >= (dynamic_lighting_sun_elevation_end_falling
                        - 2) and is_state_attr('sun.sun', 'rising', false) %}\n    false\n
                        \ {% elif elevation >= (dynamic_lighting_sun_elevation_end_rising
                        + 2) and elevation >= (dynamic_lighting_sun_elevation_start_falling
                        - 2)  %}\n    true\n  {% elif elevation <= (dynamic_lighting_sun_elevation_start_rising
                        - 2) and is_state_attr('sun.sun', 'rising', true) %}\n    true\n
                        \ {% elif elevation <= (dynamic_lighting_sun_elevation_end_falling
                        - 2) and is_state_attr('sun.sun', 'rising', false) %}\n    true\n
                        \ {% else %}\n    true\n  {% endif %}\n{% else %}\n  false\n{%
                        endif %}\n"
                  - choose:
                    - alias: Stop when crossing over
                      conditions:
                      - condition: template
                        value_template: '{{ ''if_lights_are_on_adjust_when_crossing_over''
                          not in include_night_light_control }}'
                      - condition: trigger
                        id:
                        - t13
                        - t14
                        - t15
                      sequence:
                      - stop: Stop the automation
                    - alias: Adjust the lights settings when crossing over if lights
                        are ON is selected in night light control
                      conditions:
                      - condition: template
                        value_template: '{{ ''if_lights_are_on_adjust_when_crossing_over''
                          in include_night_light_control }}'
                      - condition: trigger
                        id:
                        - t13
                        - t14
                        - t15
                      sequence:
                      - service: light.turn_on
                        target:
                          entity_id: '{{ light_entities }}'
                        data: '{{ dynamic_light_data }}'
                      - alias: Wait for sun elevation to change
                        wait_for_trigger:
                        - platform: state
                          entity_id: sun.sun
                          attribute: elevation
                    - alias: If sun elevation is outside the adjustment zone and the
                        lights are ON
                      conditions: '{{ should_wait }}'
                      sequence:
                      - alias: Wait for sun elevation to change
                        wait_for_trigger:
                        - platform: state
                          entity_id: sun.sun
                          attribute: elevation
                    - alias: Set dynamic sun elevation colour temperature for the
                        normal lights
                      conditions:
                      - condition: template
                        value_template: '{{ include_dynamic_lighting == ''enable_sun_elevation_colour''
                          }}'
                      sequence:
                      - service: light.turn_on
                        target:
                          entity_id: '{{ light_entities }}'
                        data: '{{ dynamic_light_data }}'
                      - alias: Wait for sun elevation to change
                        wait_for_trigger:
                        - platform: state
                          entity_id: sun.sun
                          attribute: elevation
          - choose:
            - alias: 4 - Dynamic Lighting - Sun Elevation Lighting - Brightness
              conditions:
              - condition: template
                value_template: '{{ include_dynamic_lighting == ''enable_sun_elevation_brightness''
                  }}'
              sequence:
              - alias: Dynamic Lighting Control
                repeat:
                  until: '{{ ((dynamic_lighting_boolean == []) and (expand(light_entities)
                    | selectattr(''state'', ''=='', ''off'') | list | count > 0))
                    or ((dynamic_lighting_boolean != []) and (is_state(dynamic_lighting_boolean,
                    ''off''))) }}'
                  sequence:
                  - variables:
                      dynamic_brightness_pct: "{% set elevation = state_attr('sun.sun',
                        'elevation') | float %} {% set start_slope = (dynamic_lighting_min_brightness
                        - dynamic_lighting_max_brightness) / (dynamic_lighting_sun_elevation_start_rising
                        - dynamic_lighting_sun_elevation_end_rising) %} {% set start_ak
                        = (( start_slope * dynamic_lighting_sun_elevation_end_rising)
                        * -1) + dynamic_lighting_max_brightness %} {% set end_slope
                        = (dynamic_lighting_min_brightness - dynamic_lighting_max_brightness)
                        / (dynamic_lighting_sun_elevation_end_falling - dynamic_lighting_sun_elevation_start_falling)
                        %} {% set end_ak = (( end_slope * dynamic_lighting_sun_elevation_end_falling)
                        * -1) + dynamic_lighting_min_brightness %} {% if elevation
                        >= -10 %}\n  {% if elevation >= dynamic_lighting_sun_elevation_start_rising
                        and elevation <= dynamic_lighting_sun_elevation_end_rising
                        and is_state_attr('sun.sun', 'rising', true) %}\n    {% set
                        brightness_value = ((start_slope * elevation) + start_ak)
                        | round(1) %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_falling
                        and elevation >= dynamic_lighting_sun_elevation_end_falling
                        and is_state_attr('sun.sun', 'rising', false) %}\n    {% set
                        brightness_value = ((end_slope * elevation) + end_ak) | round(1)
                        %}\n  {% elif elevation >= dynamic_lighting_sun_elevation_end_rising
                        and elevation >= dynamic_lighting_sun_elevation_start_falling
                        \ %}\n    {% set brightness_value = dynamic_lighting_max_brightness
                        %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_rising
                        and is_state_attr('sun.sun', 'rising', true) %}\n    {% set
                        brightness_value = dynamic_lighting_min_brightness %}\n  {%
                        elif elevation <= dynamic_lighting_sun_elevation_end_falling
                        and is_state_attr('sun.sun', 'rising', false) %}\n    {% set
                        brightness_value = dynamic_lighting_min_brightness %}\n  {%
                        else %}\n    {% set brightness_value = dynamic_lighting_max_brightness
                        %}\n  {% endif %}\n{% else %}\n  {% set brightness_value =
                        dynamic_lighting_min_brightness %}\n{% endif %} {{ brightness_value
                        | round(0) }}\n"
                      dynamic_light_data: "{% set light = namespace(data={}) %} {%
                        set light.data = dict(light.data, **{ 'brightness_pct': dynamic_brightness_pct
                        }) %} {% if 'use_transition' in include_light_control %}\n
                        \ {% set light.data = dict(light.data, **{ 'transition': light_transition_on
                        }) %}\n{% endif %} {% if include_light_colour_control == 'use_colour_temperature'
                        %}\n  {% set light.data = dict(light.data, **{ 'color_temp_kelvin':
                        light_colour_temperature }) %}\n{% endif %} {% if include_light_colour_control
                        == 'use_rgb_colour' %}\n  {% set light.data = dict(light.data,
                        **{ 'rgb_color': light_rgb_colour }) %}\n{% endif %} {% if
                        include_light_colour_control == 'use_rgbw_colour' %}\n  {%
                        set light.data = dict(light.data, **{ 'rgbw_color': light_rgbw_colour
                        }) %}\n{% endif %} {% if include_light_colour_control == 'use_rgbww_colour'
                        %}\n  {% set light.data = dict(light.data, **{ 'rgbww_color':
                        light_rgbww_colour }) %}\n{% endif %} {{ light.data }}\n"
                      should_wait: "{% set le = light_entities %} {% set lec = expand(le)
                        | map(attribute='entity_id') | list | length %} {% set lp
                        = (expand(le) | map(attribute='attributes.brightness') | reject('equalto',
                        None) | sum | float(default=255) / 255 * 100 / lec) | round(0)
                        %} {% set elevation = state_attr('sun.sun', 'elevation') |
                        float %} {% set start_slope = (dynamic_lighting_min_brightness
                        - dynamic_lighting_max_brightness) / (dynamic_lighting_sun_elevation_start_rising
                        - dynamic_lighting_sun_elevation_end_rising) %} {% set start_ak
                        = (( start_slope * dynamic_lighting_sun_elevation_end_rising)
                        * -1) + dynamic_lighting_max_brightness %} {% set end_slope
                        = (dynamic_lighting_min_brightness - dynamic_lighting_max_brightness)
                        / (dynamic_lighting_sun_elevation_end_falling - dynamic_lighting_sun_elevation_start_falling)
                        %} {% set end_ak = (( end_slope * dynamic_lighting_sun_elevation_end_falling)
                        * -1) + dynamic_lighting_min_brightness %} {% if elevation
                        >= -10 %}\n  {% if elevation >= dynamic_lighting_sun_elevation_start_rising
                        and elevation <= dynamic_lighting_sun_elevation_end_rising
                        and is_state_attr('sun.sun', 'rising', true) %}\n    {% set
                        brightness_value = ((start_slope * elevation) + start_ak)
                        | round(1) %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_falling
                        and elevation >= dynamic_lighting_sun_elevation_end_falling
                        and is_state_attr('sun.sun', 'rising', false) %}\n    {% set
                        brightness_value = ((end_slope * elevation) + end_ak) | round(1)
                        %}\n  {% elif elevation >= dynamic_lighting_sun_elevation_end_rising
                        and elevation >= dynamic_lighting_sun_elevation_start_falling
                        \ %}\n    {% set brightness_value = dynamic_lighting_max_brightness
                        %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_rising
                        and is_state_attr('sun.sun', 'rising', true) %}\n    {% set
                        brightness_value = dynamic_lighting_min_brightness %}\n  {%
                        elif elevation <= dynamic_lighting_sun_elevation_end_falling
                        and is_state_attr('sun.sun', 'rising', false) %}\n    {% set
                        brightness_value = dynamic_lighting_min_brightness %}\n  {%
                        else %}\n    {% set brightness_value = dynamic_lighting_max_brightness
                        %}\n  {% endif %}\n{% else %}\n  {% set brightness_value =
                        dynamic_lighting_min_brightness %}\n{% endif %} {% if expand(light_entities)
                        | selectattr('state', '==', 'on') | list | count > 0 %}\n
                        \ {% if (brightness_value >= (lp * 0.99) and brightness_value
                        <= (lp * 1.01)) %}\n    true\n  {% else %}\n    false\n  {%
                        endif %}\n{% else %}\n  false\n{% endif %}\n"
                  - choose:
                    - alias: Stop when crossing over
                      conditions:
                      - condition: template
                        value_template: '{{ ''if_lights_are_on_adjust_when_crossing_over''
                          not in include_night_light_control }}'
                      - condition: trigger
                        id:
                        - t13
                        - t14
                        - t15
                      sequence:
                      - stop: Stop the automation
                    - alias: Adjust the lights settings when crossing over if lights
                        are ON is selected in night light control
                      conditions:
                      - condition: template
                        value_template: '{{ ''if_lights_are_on_adjust_when_crossing_over''
                          in include_night_light_control }}'
                      - condition: trigger
                        id:
                        - t13
                        - t14
                        - t15
                      sequence:
                      - service: light.turn_on
                        target:
                          entity_id: '{{ light_entities }}'
                        data: '{{ dynamic_light_data }}'
                      - alias: Wait for sun elevation to change
                        wait_for_trigger:
                        - platform: state
                          entity_id: sun.sun
                          attribute: elevation
                    - alias: If lights are ON and the lights are within 1% of the
                        actual brightness
                      conditions: '{{ should_wait }}'
                      sequence:
                      - alias: Wait for sun elevation to change
                        wait_for_trigger:
                        - platform: state
                          entity_id: sun.sun
                          attribute: elevation
                    - alias: Set dynamic sun elevation lighting brightness for the
                        normal lights
                      conditions:
                      - condition: template
                        value_template: '{{ include_dynamic_lighting == ''enable_sun_elevation_brightness''
                          }}'
                      sequence:
                      - service: light.turn_on
                        target:
                          entity_id: '{{ light_entities }}'
                        data: '{{ dynamic_light_data }}'
                      - alias: Wait for sun elevation to change
                        wait_for_trigger:
                        - platform: state
                          entity_id: sun.sun
                          attribute: elevation
          - choose:
            - alias: 5 - Dynamic Lighting - Sun Elevation Lighting - Brightness Inverted
              conditions:
              - condition: template
                value_template: '{{ include_dynamic_lighting == ''enable_sun_elevation_brightness_inv''
                  }}'
              sequence:
              - alias: Dynamic Lighting Control
                repeat:
                  until: '{{ ((dynamic_lighting_boolean == []) and (expand(light_entities)
                    | selectattr(''state'', ''=='', ''off'') | list | count > 0))
                    or ((dynamic_lighting_boolean != []) and (is_state(dynamic_lighting_boolean,
                    ''off''))) }}'
                  sequence:
                  - variables:
                      dynamic_brightness_pct: "{% set elevation = state_attr('sun.sun',
                        'elevation') | float %} {% set start_slope = (dynamic_lighting_max_brightness
                        - dynamic_lighting_min_brightness) / (dynamic_lighting_sun_elevation_start_rising
                        - dynamic_lighting_sun_elevation_end_rising) %} {% set start_ak
                        = (( start_slope * dynamic_lighting_sun_elevation_end_rising)
                        * -1) + dynamic_lighting_min_brightness %} {% set end_slope
                        = (dynamic_lighting_max_brightness - dynamic_lighting_min_brightness)
                        / (dynamic_lighting_sun_elevation_end_falling - dynamic_lighting_sun_elevation_start_falling)
                        %} {% set end_ak = (( end_slope * dynamic_lighting_sun_elevation_end_falling)
                        * -1) + dynamic_lighting_max_brightness %} {% if elevation
                        > -10 %}\n  {% if elevation >= dynamic_lighting_sun_elevation_start_rising
                        and elevation <= dynamic_lighting_sun_elevation_end_rising
                        and is_state_attr('sun.sun', 'rising', true) %}\n    {% set
                        brightness_value = ((start_slope * elevation) + start_ak)
                        | round(1) %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_falling
                        and elevation >= dynamic_lighting_sun_elevation_end_falling
                        and is_state_attr('sun.sun', 'rising', false) %}\n    {% set
                        brightness_value = ((end_slope * elevation) + end_ak) | round(1)
                        %}\n  {% elif elevation >= dynamic_lighting_sun_elevation_end_rising
                        and elevation >= dynamic_lighting_sun_elevation_start_falling
                        \ %}\n    {% set brightness_value = dynamic_lighting_min_brightness
                        %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_rising
                        and is_state_attr('sun.sun', 'rising', true) %}\n    {% set
                        brightness_value = dynamic_lighting_max_brightness %}\n  {%
                        elif elevation <= dynamic_lighting_sun_elevation_end_falling
                        and is_state_attr('sun.sun', 'rising', false) %}\n    {% set
                        brightness_value = dynamic_lighting_max_brightness %}\n  {%
                        else %}\n    {% set brightness_value = dynamic_lighting_min_brightness
                        %}\n  {% endif %}\n{% else %}\n  {% set brightness_value =
                        dynamic_lighting_max_brightness %}\n{% endif %} {{ brightness_value
                        | round(0) }}\n"
                      dynamic_light_data: "{% set light = namespace(data={}) %} {%
                        set light.data = dict(light.data, **{ 'brightness_pct': dynamic_brightness_pct
                        }) %} {% if 'use_transition' in include_light_control %}\n
                        \ {% set light.data = dict(light.data, **{ 'transition': light_transition_on
                        }) %}\n{% endif %} {% if include_light_colour_control == 'use_colour_temperature'
                        %}\n  {% set light.data = dict(light.data, **{ 'color_temp_kelvin':
                        light_colour_temperature }) %}\n{% endif %} {% if include_light_colour_control
                        == 'use_rgb_colour' %}\n  {% set light.data = dict(light.data,
                        **{ 'rgb_color': light_rgb_colour }) %}\n{% endif %} {% if
                        include_light_colour_control == 'use_rgbw_colour' %}\n  {%
                        set light.data = dict(light.data, **{ 'rgbw_color': light_rgbw_colour
                        }) %}\n{% endif %} {% if include_light_colour_control == 'use_rgbww_colour'
                        %}\n  {% set light.data = dict(light.data, **{ 'rgbww_color':
                        light_rgbww_colour }) %}\n{% endif %} {{ light.data }}\n"
                      should_wait: "{% set le = light_entities %} {% set lec = expand(le)
                        | map(attribute='entity_id') | list | length %} {% set lp
                        = (expand(le) | map(attribute='attributes.brightness') | reject('equalto',
                        None) | sum | float(default=255) / 255 * 100 / lec) | round(0)
                        %} {% set elevation = state_attr('sun.sun', 'elevation') |
                        float %} {% set start_slope = (dynamic_lighting_max_brightness
                        - dynamic_lighting_min_brightness) / (dynamic_lighting_sun_elevation_start_rising
                        - dynamic_lighting_sun_elevation_end_rising) %} {% set start_ak
                        = (( start_slope * dynamic_lighting_sun_elevation_end_rising)
                        * -1) + dynamic_lighting_min_brightness %} {% set end_slope
                        = (dynamic_lighting_max_brightness - dynamic_lighting_min_brightness)
                        / (dynamic_lighting_sun_elevation_end_falling - dynamic_lighting_sun_elevation_start_falling)
                        %} {% set end_ak = (( end_slope * dynamic_lighting_sun_elevation_end_falling)
                        * -1) + dynamic_lighting_max_brightness %} {% if elevation
                        > -10 %}\n  {% if elevation >= dynamic_lighting_sun_elevation_start_rising
                        and elevation <= dynamic_lighting_sun_elevation_end_rising
                        and is_state_attr('sun.sun', 'rising', true) %}\n    {% set
                        brightness_value = ((start_slope * elevation) + start_ak)
                        | round(1) %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_falling
                        and elevation >= dynamic_lighting_sun_elevation_end_falling
                        and is_state_attr('sun.sun', 'rising', false) %}\n    {% set
                        brightness_value = ((end_slope * elevation) + end_ak) | round(1)
                        %}\n  {% elif elevation >= dynamic_lighting_sun_elevation_end_rising
                        and elevation >= dynamic_lighting_sun_elevation_start_falling
                        \ %}\n    {% set brightness_value = dynamic_lighting_min_brightness
                        %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_rising
                        and is_state_attr('sun.sun', 'rising', true) %}\n    {% set
                        brightness_value = dynamic_lighting_max_brightness %}\n  {%
                        elif elevation <= dynamic_lighting_sun_elevation_end_falling
                        and is_state_attr('sun.sun', 'rising', false) %}\n    {% set
                        brightness_value = dynamic_lighting_max_brightness %}\n  {%
                        else %}\n    {% set brightness_value = dynamic_lighting_min_brightness
                        %}\n  {% endif %}\n{% else %}\n  {% set brightness_value =
                        dynamic_lighting_max_brightness %}\n{% endif %} {% if expand(light_entities)
                        | selectattr('state', '==', 'on') | list | count > 0 %}\n
                        \ {% if (brightness_value >= (lp * 0.99) and brightness_value
                        <= (lp * 1.01)) %}\n    true\n  {% else %}\n    false\n  {%
                        endif %}\n{% else %}\n  false\n{% endif %}\n"
                  - choose:
                    - alias: Stop when crossing over
                      conditions:
                      - condition: template
                        value_template: '{{ ''if_lights_are_on_adjust_when_crossing_over''
                          not in include_night_light_control }}'
                      - condition: trigger
                        id:
                        - t13
                        - t14
                        - t15
                      sequence:
                      - stop: Stop the automation
                    - alias: Adjust the lights settings when crossing over if lights
                        are ON is selected in night light control
                      conditions:
                      - condition: template
                        value_template: '{{ ''if_lights_are_on_adjust_when_crossing_over''
                          in include_night_light_control }}'
                      - condition: trigger
                        id:
                        - t13
                        - t14
                        - t15
                      sequence:
                      - service: light.turn_on
                        target:
                          entity_id: '{{ light_entities }}'
                        data: '{{ dynamic_light_data }}'
                      - alias: Wait for sun elevation to change
                        wait_for_trigger:
                        - platform: state
                          entity_id: sun.sun
                          attribute: elevation
                    - alias: If lights are ON and the lights are within 1% of the
                        actual brightness
                      conditions: '{{ should_wait }}'
                      sequence:
                      - alias: Wait for sun elevation to change
                        wait_for_trigger:
                        - platform: state
                          entity_id: sun.sun
                          attribute: elevation
                    - alias: Set dynamic sun elevation lighting brightness inverted
                        for the normal lights
                      conditions:
                      - condition: template
                        value_template: '{{ include_dynamic_lighting == ''enable_sun_elevation_brightness_inv''
                          }}'
                      sequence:
                      - service: light.turn_on
                        target:
                          entity_id: '{{ light_entities }}'
                        data: '{{ dynamic_light_data }}'
                      - alias: Wait for sun elevation to change
                        wait_for_trigger:
                        - platform: state
                          entity_id: sun.sun
                          attribute: elevation
          - choose:
            - alias: 6 - Dynamic Lighting - Sun Elevation Lighting - Colour Temp +
                Brightness
              conditions:
              - condition: template
                value_template: '{{ include_dynamic_lighting == ''enable_sun_elevation_colour_brightness''
                  }}'
              sequence:
              - alias: Dynamic Lighting Control
                repeat:
                  until: '{{ ((dynamic_lighting_boolean == []) and (expand(light_entities)
                    | selectattr(''state'', ''=='', ''off'') | list | count > 0))
                    or ((dynamic_lighting_boolean != []) and (is_state(dynamic_lighting_boolean,
                    ''off''))) }}'
                  sequence:
                  - variables:
                      dynamic_kelvin: "{% set elevation = state_attr('sun.sun', 'elevation')
                        | float %} {% set start_slope = (dynamic_lighting_min_colour_temp
                        - dynamic_lighting_max_colour_temp) / (dynamic_lighting_sun_elevation_start_rising
                        - dynamic_lighting_sun_elevation_end_rising) %} {% set start_ak
                        = (( start_slope * dynamic_lighting_sun_elevation_end_rising)
                        * -1) + dynamic_lighting_max_colour_temp %} {% set end_slope
                        = (dynamic_lighting_min_colour_temp - dynamic_lighting_max_colour_temp)
                        / (dynamic_lighting_sun_elevation_end_falling - dynamic_lighting_sun_elevation_start_falling)
                        %} {% set end_ak = (( end_slope * dynamic_lighting_sun_elevation_end_falling)
                        * -1) + dynamic_lighting_min_colour_temp %} {% if elevation
                        >= -10 %}\n  {% if elevation >= dynamic_lighting_sun_elevation_start_rising
                        and elevation <= dynamic_lighting_sun_elevation_end_rising
                        and is_state_attr('sun.sun', 'rising', true) %}\n    {% set
                        colour_temp_value = ((start_slope * elevation) + start_ak)
                        | round(1) %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_falling
                        and elevation >= dynamic_lighting_sun_elevation_end_falling
                        and is_state_attr('sun.sun', 'rising', false) %}\n    {% set
                        colour_temp_value = ((end_slope * elevation) + end_ak) | round(1)
                        %}\n  {% elif elevation >= dynamic_lighting_sun_elevation_end_rising
                        and elevation >= dynamic_lighting_sun_elevation_start_falling
                        \ %}\n    {% set colour_temp_value = dynamic_lighting_max_colour_temp
                        %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_rising
                        and is_state_attr('sun.sun', 'rising', true) %}\n    {% set
                        colour_temp_value = dynamic_lighting_min_colour_temp %}\n
                        \ {% elif elevation <= dynamic_lighting_sun_elevation_end_falling
                        and is_state_attr('sun.sun', 'rising', false) %}\n    {% set
                        colour_temp_value = dynamic_lighting_min_colour_temp %}\n
                        \ {% else %}\n    {% set colour_temp_value = dynamic_lighting_max_colour_temp
                        %}\n  {% endif %}\n{% else %}\n  {% set colour_temp_value
                        = dynamic_lighting_min_colour_temp %}\n{% endif %} {{ colour_temp_value
                        | round(0) }}\n"
                      dynamic_brightness_pct: "{% set elevation = state_attr('sun.sun',
                        'elevation') | float %} {% set start_slope = (dynamic_lighting_min_brightness
                        - dynamic_lighting_max_brightness) / (dynamic_lighting_sun_elevation_start_rising
                        - dynamic_lighting_sun_elevation_end_rising) %} {% set start_ak
                        = (( start_slope * dynamic_lighting_sun_elevation_end_rising)
                        * -1) + dynamic_lighting_max_brightness %} {% set end_slope
                        = (dynamic_lighting_min_brightness - dynamic_lighting_max_brightness)
                        / (dynamic_lighting_sun_elevation_end_falling - dynamic_lighting_sun_elevation_start_falling)
                        %} {% set end_ak = (( end_slope * dynamic_lighting_sun_elevation_end_falling)
                        * -1) + dynamic_lighting_min_brightness %} {% if elevation
                        >= -10 %}\n  {% if elevation >= dynamic_lighting_sun_elevation_start_rising
                        and elevation <= dynamic_lighting_sun_elevation_end_rising
                        and is_state_attr('sun.sun', 'rising', true) %}\n    {% set
                        brightness_value = ((start_slope * elevation) + start_ak)
                        | round(1) %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_falling
                        and elevation >= dynamic_lighting_sun_elevation_end_falling
                        and is_state_attr('sun.sun', 'rising', false) %}\n    {% set
                        brightness_value = ((end_slope * elevation) + end_ak) | round(1)
                        %}\n  {% elif elevation >= dynamic_lighting_sun_elevation_end_rising
                        and elevation >= dynamic_lighting_sun_elevation_start_falling
                        \ %}\n    {% set brightness_value = dynamic_lighting_max_brightness
                        %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_rising
                        and is_state_attr('sun.sun', 'rising', true) %}\n    {% set
                        brightness_value = dynamic_lighting_min_brightness %}\n  {%
                        elif elevation <= dynamic_lighting_sun_elevation_end_falling
                        and is_state_attr('sun.sun', 'rising', false) %}\n    {% set
                        brightness_value = dynamic_lighting_min_brightness %}\n  {%
                        else %}\n    {% set brightness_value = dynamic_lighting_max_brightness
                        %}\n  {% endif %}\n{% else %}\n  {% set brightness_value =
                        dynamic_lighting_min_brightness %}\n{% endif %} {{ brightness_value
                        | round(0) }}\n"
                      dynamic_light_data: "{% set light = namespace(data={}) %} {%
                        set light.data = dict(light.data, **{ 'color_temp_kelvin':
                        dynamic_kelvin }) %} {% set light.data = dict(light.data,
                        **{ 'brightness_pct': dynamic_brightness_pct }) %} {% if 'use_transition'
                        in include_light_control %}\n  {% set light.data = dict(light.data,
                        **{ 'transition': light_transition_on }) %}\n{% endif %} {{
                        light.data }}\n"
                      should_wait: "{% set le = light_entities %} {% set lec = expand(le)
                        | map(attribute='entity_id') | list | length %} {% set lp
                        = (expand(le) | map(attribute='attributes.brightness') | reject('equalto',
                        None) | sum | float(default=255) / 255 * 100 / lec) | round(0)
                        %} {% set elevation = state_attr('sun.sun', 'elevation') |
                        float %} {% set start_slope = (dynamic_lighting_min_brightness
                        - dynamic_lighting_max_brightness) / (dynamic_lighting_sun_elevation_start_rising
                        - dynamic_lighting_sun_elevation_end_rising) %} {% set start_ak
                        = (( start_slope * dynamic_lighting_sun_elevation_end_rising)
                        * -1) + dynamic_lighting_max_brightness %} {% set end_slope
                        = (dynamic_lighting_min_brightness - dynamic_lighting_max_brightness)
                        / (dynamic_lighting_sun_elevation_end_falling - dynamic_lighting_sun_elevation_start_falling)
                        %} {% set end_ak = (( end_slope * dynamic_lighting_sun_elevation_end_falling)
                        * -1) + dynamic_lighting_min_brightness %} {% if elevation
                        >= -10 %}\n  {% if elevation >= dynamic_lighting_sun_elevation_start_rising
                        and elevation <= dynamic_lighting_sun_elevation_end_rising
                        and is_state_attr('sun.sun', 'rising', true) %}\n    {% set
                        brightness_value = ((start_slope * elevation) + start_ak)
                        | round(1) %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_falling
                        and elevation >= dynamic_lighting_sun_elevation_end_falling
                        and is_state_attr('sun.sun', 'rising', false) %}\n    {% set
                        brightness_value = ((end_slope * elevation) + end_ak) | round(1)
                        %}\n  {% elif elevation >= dynamic_lighting_sun_elevation_end_rising
                        and elevation >= dynamic_lighting_sun_elevation_start_falling
                        \ %}\n    {% set brightness_value = dynamic_lighting_max_brightness
                        %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_rising
                        and is_state_attr('sun.sun', 'rising', true) %}\n    {% set
                        brightness_value = dynamic_lighting_min_brightness %}\n  {%
                        elif elevation <= dynamic_lighting_sun_elevation_end_falling
                        and is_state_attr('sun.sun', 'rising', false) %}\n    {% set
                        brightness_value = dynamic_lighting_min_brightness %}\n  {%
                        else %}\n    {% set brightness_value = dynamic_lighting_max_brightness
                        %}\n  {% endif %}\n{% else %}\n  {% set brightness_value =
                        dynamic_lighting_min_brightness %}\n{% endif %} {% if expand(light_entities)
                        | selectattr('state', '==', 'on') | list | count > 0 %}\n
                        \ {% if (brightness_value >= (lp * 0.99) and brightness_value
                        <= (lp * 1.01)) %}\n    true\n  {% else %}\n    false\n  {%
                        endif %}\n{% else %}\n  false\n{% endif %}\n"
                  - choose:
                    - alias: Stop when crossing over
                      conditions:
                      - condition: template
                        value_template: '{{ ''if_lights_are_on_adjust_when_crossing_over''
                          not in include_night_light_control }}'
                      - condition: trigger
                        id:
                        - t13
                        - t14
                        - t15
                      sequence:
                      - stop: Stop the automation
                    - alias: Adjust the lights settings when crossing over if lights
                        are ON is selected in night light control
                      conditions:
                      - condition: template
                        value_template: '{{ ''if_lights_are_on_adjust_when_crossing_over''
                          in include_night_light_control }}'
                      - condition: trigger
                        id:
                        - t13
                        - t14
                        - t15
                      sequence:
                      - service: light.turn_on
                        target:
                          entity_id: '{{ light_entities }}'
                        data: '{{ dynamic_light_data }}'
                      - alias: Wait for sun elevation to change
                        wait_for_trigger:
                        - platform: state
                          entity_id: sun.sun
                          attribute: elevation
                    - alias: If lights are ON and the lights are within 1% of the
                        actual brightness
                      conditions: '{{ should_wait }}'
                      sequence:
                      - alias: Wait for sun elevation to change
                        wait_for_trigger:
                        - platform: state
                          entity_id: sun.sun
                          attribute: elevation
                    - alias: Set dynamic sun elevation lighting brightness and dynamic
                        sun elevation colour temperature for the normal lights
                      conditions:
                      - condition: template
                        value_template: '{{ include_dynamic_lighting == ''enable_sun_elevation_colour_brightness''
                          }}'
                      sequence:
                      - service: light.turn_on
                        target:
                          entity_id: '{{ light_entities }}'
                        data: '{{ dynamic_light_data }}'
                      - alias: Wait for sun elevation to change
                        wait_for_trigger:
                        - platform: state
                          entity_id: sun.sun
                          attribute: elevation
          - choose:
            - alias: 7 - Dynamic Lighting - Sun Elevation Lighting - Colour Temp +
                Brightness Inverted
              conditions:
              - condition: template
                value_template: '{{ include_dynamic_lighting == ''enable_sun_elevation_colour_brightness_inv''
                  }}'
              sequence:
              - alias: Dynamic Lighting Control
                repeat:
                  until: '{{ ((dynamic_lighting_boolean == []) and (expand(light_entities)
                    | selectattr(''state'', ''=='', ''off'') | list | count > 0))
                    or ((dynamic_lighting_boolean != []) and (is_state(dynamic_lighting_boolean,
                    ''off''))) }}'
                  sequence:
                  - variables:
                      dynamic_kelvin: "{% set elevation = state_attr('sun.sun', 'elevation')
                        | float %} {% set start_slope = (dynamic_lighting_min_colour_temp
                        - dynamic_lighting_max_colour_temp) / (dynamic_lighting_sun_elevation_start_rising
                        - dynamic_lighting_sun_elevation_end_rising) %} {% set start_ak
                        = (( start_slope * dynamic_lighting_sun_elevation_end_rising)
                        * -1) + dynamic_lighting_max_colour_temp %} {% set end_slope
                        = (dynamic_lighting_min_colour_temp - dynamic_lighting_max_colour_temp)
                        / (dynamic_lighting_sun_elevation_end_falling - dynamic_lighting_sun_elevation_start_falling)
                        %} {% set end_ak = (( end_slope * dynamic_lighting_sun_elevation_end_falling)
                        * -1) + dynamic_lighting_min_colour_temp %} {% if elevation
                        >= -10 %}\n  {% if elevation >= dynamic_lighting_sun_elevation_start_rising
                        and elevation <= dynamic_lighting_sun_elevation_end_rising
                        and is_state_attr('sun.sun', 'rising', true) %}\n    {% set
                        colour_temp_value = ((start_slope * elevation) + start_ak)
                        | round(1) %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_falling
                        and elevation >= dynamic_lighting_sun_elevation_end_falling
                        and is_state_attr('sun.sun', 'rising', false) %}\n    {% set
                        colour_temp_value = ((end_slope * elevation) + end_ak) | round(1)
                        %}\n  {% elif elevation >= dynamic_lighting_sun_elevation_end_rising
                        and elevation >= dynamic_lighting_sun_elevation_start_falling
                        \ %}\n    {% set colour_temp_value = dynamic_lighting_max_colour_temp
                        %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_rising
                        and is_state_attr('sun.sun', 'rising', true) %}\n    {% set
                        colour_temp_value = dynamic_lighting_min_colour_temp %}\n
                        \ {% elif elevation <= dynamic_lighting_sun_elevation_end_falling
                        and is_state_attr('sun.sun', 'rising', false) %}\n    {% set
                        colour_temp_value = dynamic_lighting_min_colour_temp %}\n
                        \ {% else %}\n    {% set colour_temp_value = dynamic_lighting_max_colour_temp
                        %}\n  {% endif %}\n{% else %}\n  {% set colour_temp_value
                        = dynamic_lighting_min_colour_temp %}\n{% endif %} {{ colour_temp_value
                        | round(0) }}\n"
                      dynamic_brightness_pct: "{% set elevation = state_attr('sun.sun',
                        'elevation') | float %} {% set start_slope = (dynamic_lighting_max_brightness
                        - dynamic_lighting_min_brightness) / (dynamic_lighting_sun_elevation_start_rising
                        - dynamic_lighting_sun_elevation_end_rising) %} {% set start_ak
                        = (( start_slope * dynamic_lighting_sun_elevation_end_rising)
                        * -1) + dynamic_lighting_min_brightness %} {% set end_slope
                        = (dynamic_lighting_max_brightness - dynamic_lighting_min_brightness)
                        / (dynamic_lighting_sun_elevation_end_falling - dynamic_lighting_sun_elevation_start_falling)
                        %} {% set end_ak = (( end_slope * dynamic_lighting_sun_elevation_end_falling)
                        * -1) + dynamic_lighting_max_brightness %} {% if elevation
                        > -10 %}\n  {% if elevation >= dynamic_lighting_sun_elevation_start_rising
                        and elevation <= dynamic_lighting_sun_elevation_end_rising
                        and is_state_attr('sun.sun', 'rising', true) %}\n    {% set
                        brightness_value = ((start_slope * elevation) + start_ak)
                        | round(1) %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_falling
                        and elevation >= dynamic_lighting_sun_elevation_end_falling
                        and is_state_attr('sun.sun', 'rising', false) %}\n    {% set
                        brightness_value = ((end_slope * elevation) + end_ak) | round(1)
                        %}\n  {% elif elevation >= dynamic_lighting_sun_elevation_end_rising
                        and elevation >= dynamic_lighting_sun_elevation_start_falling
                        \ %}\n    {% set brightness_value = dynamic_lighting_min_brightness
                        %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_rising
                        and is_state_attr('sun.sun', 'rising', true) %}\n    {% set
                        brightness_value = dynamic_lighting_max_brightness %}\n  {%
                        elif elevation <= dynamic_lighting_sun_elevation_end_falling
                        and is_state_attr('sun.sun', 'rising', false) %}\n    {% set
                        brightness_value = dynamic_lighting_max_brightness %}\n  {%
                        else %}\n    {% set brightness_value = dynamic_lighting_min_brightness
                        %}\n  {% endif %}\n{% else %}\n  {% set brightness_value =
                        dynamic_lighting_max_brightness %}\n{% endif %} {{ brightness_value
                        | round(0) }}\n"
                      dynamic_light_data: "{% set light = namespace(data={}) %} {%
                        set light.data = dict(light.data, **{ 'color_temp_kelvin':
                        dynamic_kelvin }) %} {% set light.data = dict(light.data,
                        **{ 'brightness_pct': dynamic_brightness_pct }) %} {% if 'use_transition'
                        in include_light_control %}\n  {% set light.data = dict(light.data,
                        **{ 'transition': light_transition_on }) %}\n{% endif %} {{
                        light.data }}\n"
                      should_wait: "{% set le = light_entities %} {% set lec = expand(le)
                        | map(attribute='entity_id') | list | length %} {% set lp
                        = (expand(le) | map(attribute='attributes.brightness') | reject('equalto',
                        None) | sum | float(default=255) / 255 * 100 / lec) | round(0)
                        %} {% set elevation = state_attr('sun.sun', 'elevation') |
                        float %} {% set start_slope = (dynamic_lighting_max_brightness
                        - dynamic_lighting_min_brightness) / (dynamic_lighting_sun_elevation_start_rising
                        - dynamic_lighting_sun_elevation_end_rising) %} {% set start_ak
                        = (( start_slope * dynamic_lighting_sun_elevation_end_rising)
                        * -1) + dynamic_lighting_min_brightness %} {% set end_slope
                        = (dynamic_lighting_max_brightness - dynamic_lighting_min_brightness)
                        / (dynamic_lighting_sun_elevation_end_falling - dynamic_lighting_sun_elevation_start_falling)
                        %} {% set end_ak = (( end_slope * dynamic_lighting_sun_elevation_end_falling)
                        * -1) + dynamic_lighting_max_brightness %} {% if elevation
                        > -10 %}\n  {% if elevation >= dynamic_lighting_sun_elevation_start_rising
                        and elevation <= dynamic_lighting_sun_elevation_end_rising
                        and is_state_attr('sun.sun', 'rising', true) %}\n    {% set
                        brightness_value = ((start_slope * elevation) + start_ak)
                        | round(1) %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_falling
                        and elevation >= dynamic_lighting_sun_elevation_end_falling
                        and is_state_attr('sun.sun', 'rising', false) %}\n    {% set
                        brightness_value = ((end_slope * elevation) + end_ak) | round(1)
                        %}\n  {% elif elevation >= dynamic_lighting_sun_elevation_end_rising
                        and elevation >= dynamic_lighting_sun_elevation_start_falling
                        \ %}\n    {% set brightness_value = dynamic_lighting_min_brightness
                        %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_rising
                        and is_state_attr('sun.sun', 'rising', true) %}\n    {% set
                        brightness_value = dynamic_lighting_max_brightness %}\n  {%
                        elif elevation <= dynamic_lighting_sun_elevation_end_falling
                        and is_state_attr('sun.sun', 'rising', false) %}\n    {% set
                        brightness_value = dynamic_lighting_max_brightness %}\n  {%
                        else %}\n    {% set brightness_value = dynamic_lighting_min_brightness
                        %}\n  {% endif %}\n{% else %}\n  {% set brightness_value =
                        dynamic_lighting_max_brightness %}\n{% endif %} {% if expand(light_entities)
                        | selectattr('state', '==', 'on') | list | count > 0 %}\n
                        \ {% if (brightness_value >= (lp * 0.99) and brightness_value
                        <= (lp * 1.01)) %}\n    true\n  {% else %}\n    false\n  {%
                        endif %}\n{% else %}\n  false\n{% endif %}\n"
                  - choose:
                    - alias: Stop when crossing over
                      conditions:
                      - condition: template
                        value_template: '{{ ''if_lights_are_on_adjust_when_crossing_over''
                          not in include_night_light_control }}'
                      - condition: trigger
                        id:
                        - t13
                        - t14
                        - t15
                      sequence:
                      - stop: Stop the automation
                    - alias: Adjust the lights settings when crossing over if lights
                        are ON is selected in night light control
                      conditions:
                      - condition: template
                        value_template: '{{ ''if_lights_are_on_adjust_when_crossing_over''
                          in include_night_light_control }}'
                      - condition: trigger
                        id:
                        - t13
                        - t14
                        - t15
                      sequence:
                      - service: light.turn_on
                        target:
                          entity_id: '{{ light_entities }}'
                        data: '{{ dynamic_light_data }}'
                      - alias: Wait for sun elevation to change
                        wait_for_trigger:
                        - platform: state
                          entity_id: sun.sun
                          attribute: elevation
                    - alias: If lights are ON and the lights are within 1% of the
                        actual brightness
                      conditions: '{{ should_wait }}'
                      sequence:
                      - alias: Wait for sun elevation to change
                        wait_for_trigger:
                        - platform: state
                          entity_id: sun.sun
                          attribute: elevation
                    - alias: Set dynamic sun elevation lighting brightness and dynamic
                        sun elevation colour temperature for the normal lights
                      conditions:
                      - condition: template
                        value_template: '{{ include_dynamic_lighting == ''enable_sun_elevation_colour_brightness_inv''
                          }}'
                      sequence:
                      - service: light.turn_on
                        target:
                          entity_id: '{{ light_entities }}'
                        data: '{{ dynamic_light_data }}'
                      - alias: Wait for sun elevation to change
                        wait_for_trigger:
                        - platform: state
                          entity_id: sun.sun
                          attribute: elevation
          - choose:
            - alias: 8 - Dynamic Lighting - Sun Elevation Lighting - Colour Temp +
                Lux Controlled Brightness
              conditions:
              - condition: template
                value_template: '{{ include_dynamic_lighting == ''enable_sun_elevation_colour_lux_brightness''
                  }}'
              sequence:
              - alias: Parallel actions for dynamic lighting
                parallel:
                - sequence:
                  - alias: Dynamic Lighting Control
                    repeat:
                      until: '{{ ((dynamic_lighting_boolean == []) and (expand(light_entities)
                        | selectattr(''state'', ''=='', ''off'') | list | count >
                        0)) or ((dynamic_lighting_boolean != []) and (is_state(dynamic_lighting_boolean,
                        ''off''))) }}'
                      sequence:
                      - variables:
                          dynamic_brightness_pct: "{% set lux = states(dynamic_lighting_lux_sensor)
                            | float %} {% set slope = (dynamic_lighting_min_brightness
                            - dynamic_lighting_max_brightness) / (dynamic_lighting_max_lux
                            - dynamic_lighting_min_lux) %} {% set ak = (( slope *
                            dynamic_lighting_min_lux) * -1) + dynamic_lighting_max_brightness
                            %} {% set le = light_entities %} {% set lec = expand(le)
                            | map(attribute='entity_id') | list | length %} {% set
                            lp = (expand(le) | map(attribute='attributes.brightness')
                            | reject('equalto', None) | sum | float(default=255) /
                            255 * 100 / lec) | round(0) %} {% if lux <= dynamic_lighting_min_lux
                            %}\n  {% set bv = dynamic_lighting_max_brightness %}\n{%
                            elif lux >= dynamic_lighting_max_lux %}\n  {% set bv =
                            dynamic_lighting_min_brightness %}\n{% else %}\n  {% set
                            bv = ((slope * lux) + ak) | round(1) %}\n{% endif %} {%
                            if lp <= 0 %}\n  {% set bv = bv %}\n{% elif (bv > lp)
                            and (dynamic_lighting_max_brightness - lp) <= dynamic_lighting_dead_zone
                            %}\n  {% set bv = dynamic_lighting_max_brightness %}\n{%
                            elif (lp > bv) and (lp - dynamic_lighting_min_brightness)
                            <= dynamic_lighting_dead_zone %}\n  {% set bv = dynamic_lighting_min_brightness
                            %}\n{% elif (bv > lp) and (bv - lp) <= dynamic_lighting_dead_zone
                            %}\n  {% set bv = lp %}\n{% elif (lp > bv) and (lp - bv)
                            <= dynamic_lighting_dead_zone %}\n  {% set bv = lp %}\n{%
                            elif bv > (lp + dynamic_lighting_step_value) %}\n  {%
                            set bv = lp + dynamic_lighting_step_value %}\n{% elif
                            bv < (lp - dynamic_lighting_step_value) %}\n  {% set bv
                            = lp - dynamic_lighting_step_value %}\n{% endif %} {{
                            bv | round(0) }}\n"
                          dynamic_kelvin: "{% if expand(light_entities) | selectattr('state',
                            '==', 'off') | list | count > 0 %}\n  {% set elevation
                            = state_attr('sun.sun', 'elevation') | float %}\n  {%
                            set start_slope = (dynamic_lighting_min_colour_temp -
                            dynamic_lighting_max_colour_temp) / (dynamic_lighting_sun_elevation_start_rising
                            - dynamic_lighting_sun_elevation_end_rising) %}\n  {%
                            set start_ak = (( start_slope * dynamic_lighting_sun_elevation_end_rising)
                            * -1) + dynamic_lighting_max_colour_temp %}\n  {% set
                            end_slope = (dynamic_lighting_min_colour_temp - dynamic_lighting_max_colour_temp)
                            / (dynamic_lighting_sun_elevation_end_falling - dynamic_lighting_sun_elevation_start_falling)
                            %}\n  {% set end_ak = (( end_slope * dynamic_lighting_sun_elevation_end_falling)
                            * -1) + dynamic_lighting_min_colour_temp %}\n  {% if elevation
                            >= -10 %}\n    {% if elevation >= dynamic_lighting_sun_elevation_start_rising
                            and elevation <= dynamic_lighting_sun_elevation_end_rising
                            and is_state_attr('sun.sun', 'rising', true) %}\n      {%
                            set colour_temp_value = ((start_slope * elevation) + start_ak)
                            | round(1) %}\n    {% elif elevation <= dynamic_lighting_sun_elevation_start_falling
                            and elevation >= dynamic_lighting_sun_elevation_end_falling
                            and is_state_attr('sun.sun', 'rising', false) %}\n      {%
                            set colour_temp_value = ((end_slope * elevation) + end_ak)
                            | round(1) %}\n    {% elif elevation >= dynamic_lighting_sun_elevation_end_rising
                            and elevation >= dynamic_lighting_sun_elevation_start_falling
                            \ %}\n      {% set colour_temp_value = dynamic_lighting_max_colour_temp
                            %}\n    {% elif elevation <= dynamic_lighting_sun_elevation_start_rising
                            and is_state_attr('sun.sun', 'rising', true) %}\n      {%
                            set colour_temp_value = dynamic_lighting_min_colour_temp
                            %}\n    {% elif elevation <= dynamic_lighting_sun_elevation_end_falling
                            and is_state_attr('sun.sun', 'rising', false) %}\n      {%
                            set colour_temp_value = dynamic_lighting_min_colour_temp
                            %}\n    {% else %}\n      {% set colour_temp_value = dynamic_lighting_max_colour_temp
                            %}\n    {% endif %}\n  {% else %}\n    {% set colour_temp_value
                            = dynamic_lighting_min_colour_temp %}\n  {% endif %}\n
                            \ {{ colour_temp_value | round(0) }}\n{% endif %}\n"
                          dynamic_light_off_data: "{% set light = namespace(data={})
                            %} {% set light.data = dict(light.data, **{ 'brightness_pct':
                            dynamic_brightness_pct }) %} {% set light.data = dict(light.data,
                            **{ 'color_temp_kelvin': dynamic_kelvin }) %} {% if 'use_transition'
                            in include_light_control %}\n  {% set light.data = dict(light.data,
                            **{ 'transition': light_transition_on }) %}\n{% endif
                            %} {{ light.data }}\n"
                          dynamic_light_data: "{% set light = namespace(data={}) %}
                            {% set light.data = dict(light.data, **{ 'brightness_pct':
                            dynamic_brightness_pct }) %} {% if 'use_transition' in
                            include_light_control %}\n  {% set light.data = dict(light.data,
                            **{ 'transition': light_transition_on }) %}\n{% endif
                            %} {{ light.data }}\n"
                          in_dead_zone: "{% set lux = states(dynamic_lighting_lux_sensor)
                            | float %} {% set slope = (dynamic_lighting_min_brightness
                            - dynamic_lighting_max_brightness) / (dynamic_lighting_max_lux
                            - dynamic_lighting_min_lux) %} {% set ak = (( slope *
                            dynamic_lighting_min_lux) * -1) + dynamic_lighting_max_brightness
                            %} {% set le = light_entities %} {% set lec = expand(le)
                            | map(attribute='entity_id') | list | length %} {% set
                            lp = (expand(le) | map(attribute='attributes.brightness')
                            | reject('equalto', None) | sum | float(default=255) /
                            255 * 100 / lec) | round(0) %} {% if lux <= dynamic_lighting_min_lux
                            %}\n  {% set bv = dynamic_lighting_max_brightness %}\n{%
                            elif lux >= dynamic_lighting_max_lux %}\n  {% set bv =
                            dynamic_lighting_min_brightness %}\n{% else %}\n  {% set
                            bv = ((slope * lux) + ak) | round(1) %}\n{% endif %} {%
                            if (bv > lp) and (dynamic_lighting_max_brightness - lp)
                            <= dynamic_lighting_dead_zone %}\n  false\n{% elif (lp
                            > bv) and (lp - dynamic_lighting_min_brightness) <= dynamic_lighting_dead_zone
                            %}\n  false\n{% elif (bv >= lp) and (bv - lp) <= dynamic_lighting_dead_zone
                            %}\n  true\n{% elif (lp >= bv) and (lp - bv) <= dynamic_lighting_dead_zone
                            %}\n  true\n{% else %}\n  false\n{% endif %}\n"
                      - choose:
                        - alias: Check if the light is off
                          conditions: '{{ expand(light_entities) | selectattr(''state'',
                            ''=='', ''off'') | list | count > 0 }}'
                          sequence:
                          - alias: Delay for parallel actions needed for when the
                              light is off
                            delay:
                              milliseconds: 100
                      - choose:
                        - alias: Stop when crossing over
                          conditions:
                          - condition: template
                            value_template: '{{ ''if_lights_are_on_adjust_when_crossing_over''
                              not in include_night_light_control }}'
                          - condition: trigger
                            id:
                            - t13
                            - t14
                            - t15
                          sequence:
                          - stop: Stop the automation
                        - alias: Adjust the lights settings when crossing over if
                            lights are ON is selected in night light control
                          conditions:
                          - condition: template
                            value_template: '{{ ''if_lights_are_on_adjust_when_crossing_over''
                              in include_night_light_control }}'
                          - condition: trigger
                            id:
                            - t13
                            - t14
                            - t15
                          sequence:
                          - alias: Delay for parallel actions needed for when the
                              light is on
                            delay:
                              milliseconds: 100
                          - service: light.turn_on
                            target:
                              entity_id: '{{ light_entities }}'
                            data: '{{ dynamic_light_data }}'
                          - alias: Dynamic lighting heartbeat
                            delay:
                              minutes: !input dynamic_lighting_heartbeat
                        - alias: If dynamic lighting brightness is in the dead zone
                          conditions: '{{ in_dead_zone }}'
                          sequence:
                          - alias: Dynamic lighting heartbeat
                            delay:
                              minutes: !input dynamic_lighting_heartbeat
                        - alias: Set dynamic lighting lux brightness and dynamic sun
                            elevation colour temperature for the normal lights
                          conditions:
                          - condition: template
                            value_template: '{{ include_dynamic_lighting == ''enable_sun_elevation_colour_lux_brightness''
                              }}'
                          - '{{ expand(light_entities) | selectattr(''state'', ''=='',
                            ''off'') | list | count > 0 }}'
                          sequence:
                          - service: light.turn_on
                            target:
                              entity_id: '{{ light_entities }}'
                            data: '{{ dynamic_light_off_data }}'
                          - alias: Dynamic lighting heartbeat
                            delay:
                              minutes: !input dynamic_lighting_heartbeat
                        - alias: Set dynamic lighting lux brightness for the normal
                            lights
                          conditions:
                          - condition: template
                            value_template: '{{ include_dynamic_lighting == ''enable_sun_elevation_colour_lux_brightness''
                              }}'
                          sequence:
                          - service: light.turn_on
                            target:
                              entity_id: '{{ light_entities }}'
                            data: '{{ dynamic_light_data }}'
                          - alias: Dynamic lighting heartbeat
                            delay:
                              minutes: !input dynamic_lighting_heartbeat
                - sequence:
                  - alias: Dynamic Lighting Control
                    repeat:
                      until: '{{ ((dynamic_lighting_boolean == []) and (expand(light_entities)
                        | selectattr(''state'', ''=='', ''off'') | list | count >
                        0)) or ((dynamic_lighting_boolean != []) and (is_state(dynamic_lighting_boolean,
                        ''off''))) }}'
                      sequence:
                      - variables:
                          dynamic_kelvin: "{% set elevation = state_attr('sun.sun',
                            'elevation') | float %} {% set start_slope = (dynamic_lighting_min_colour_temp
                            - dynamic_lighting_max_colour_temp) / (dynamic_lighting_sun_elevation_start_rising
                            - dynamic_lighting_sun_elevation_end_rising) %} {% set
                            start_ak = (( start_slope * dynamic_lighting_sun_elevation_end_rising)
                            * -1) + dynamic_lighting_max_colour_temp %} {% set end_slope
                            = (dynamic_lighting_min_colour_temp - dynamic_lighting_max_colour_temp)
                            / (dynamic_lighting_sun_elevation_end_falling - dynamic_lighting_sun_elevation_start_falling)
                            %} {% set end_ak = (( end_slope * dynamic_lighting_sun_elevation_end_falling)
                            * -1) + dynamic_lighting_min_colour_temp %} {% if elevation
                            >= -10 %}\n  {% if elevation >= dynamic_lighting_sun_elevation_start_rising
                            and elevation <= dynamic_lighting_sun_elevation_end_rising
                            and is_state_attr('sun.sun', 'rising', true) %}\n    {%
                            set colour_temp_value = ((start_slope * elevation) + start_ak)
                            | round(1) %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_falling
                            and elevation >= dynamic_lighting_sun_elevation_end_falling
                            and is_state_attr('sun.sun', 'rising', false) %}\n    {%
                            set colour_temp_value = ((end_slope * elevation) + end_ak)
                            | round(1) %}\n  {% elif elevation >= dynamic_lighting_sun_elevation_end_rising
                            and elevation >= dynamic_lighting_sun_elevation_start_falling
                            \ %}\n    {% set colour_temp_value = dynamic_lighting_max_colour_temp
                            %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_rising
                            and is_state_attr('sun.sun', 'rising', true) %}\n    {%
                            set colour_temp_value = dynamic_lighting_min_colour_temp
                            %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_end_falling
                            and is_state_attr('sun.sun', 'rising', false) %}\n    {%
                            set colour_temp_value = dynamic_lighting_min_colour_temp
                            %}\n  {% else %}\n    {% set colour_temp_value = dynamic_lighting_max_colour_temp
                            %}\n  {% endif %}\n{% else %}\n  {% set colour_temp_value
                            = dynamic_lighting_min_colour_temp %}\n{% endif %} {{
                            colour_temp_value | round(0) }}\n"
                          dynamic_light_data: "{% set light = namespace(data={}) %}
                            {% set light.data = dict(light.data, **{ 'color_temp_kelvin':
                            dynamic_kelvin }) %} {% if 'use_transition' in include_light_control
                            %}\n  {% set light.data = dict(light.data, **{ 'transition':
                            light_transition_on }) %}\n{% endif %} {{ light.data }}\n"
                          should_wait: "{% set elevation = state_attr('sun.sun', 'elevation')
                            | float %} {% if expand(light_entities) | selectattr('state',
                            '==', 'on') | list | count > 0 %}\n  {% if elevation >=
                            (dynamic_lighting_sun_elevation_start_rising - 2) and
                            elevation <= (dynamic_lighting_sun_elevation_end_rising
                            + 2) and is_state_attr('sun.sun', 'rising', true) %}\n
                            \   false\n  {% elif elevation <= (dynamic_lighting_sun_elevation_start_falling
                            + 2) and elevation >= (dynamic_lighting_sun_elevation_end_falling
                            - 2) and is_state_attr('sun.sun', 'rising', false) %}\n
                            \   false\n  {% elif elevation >= (dynamic_lighting_sun_elevation_end_rising
                            + 2) and elevation >= (dynamic_lighting_sun_elevation_start_falling
                            - 2)  %}\n    true\n  {% elif elevation <= (dynamic_lighting_sun_elevation_start_rising
                            - 2) and is_state_attr('sun.sun', 'rising', true) %}\n
                            \   true\n  {% elif elevation <= (dynamic_lighting_sun_elevation_end_falling
                            - 2) and is_state_attr('sun.sun', 'rising', false) %}\n
                            \   true\n  {% else %}\n    true\n  {% endif %}\n{% else
                            %}\n  false\n{% endif %}\n"
                      - choose:
                        - alias: Stop when crossing over
                          conditions:
                          - condition: template
                            value_template: '{{ ''if_lights_are_on_adjust_when_crossing_over''
                              not in include_night_light_control }}'
                          - condition: trigger
                            id:
                            - t13
                            - t14
                            - t15
                          sequence:
                          - stop: Stop the automation
                        - alias: Adjust the lights settings when crossing over if
                            lights are ON is selected in night light control
                          conditions:
                          - condition: template
                            value_template: '{{ ''if_lights_are_on_adjust_when_crossing_over''
                              in include_night_light_control }}'
                          - condition: trigger
                            id:
                            - t13
                            - t14
                            - t15
                          sequence:
                          - service: light.turn_on
                            target:
                              entity_id: '{{ light_entities }}'
                            data: '{{ dynamic_light_data }}'
                          - alias: Wait for sun elevation to change
                            wait_for_trigger:
                            - platform: state
                              entity_id: sun.sun
                              attribute: elevation
                        - alias: If sun elevation is outside the adjustment zone and
                            the lights are ON
                          conditions: '{{ should_wait }}'
                          sequence:
                          - alias: Wait for sun elevation to change
                            wait_for_trigger:
                            - platform: state
                              entity_id: sun.sun
                              attribute: elevation
                        - alias: If the lights are OFF
                          conditions: '{{ expand(light_entities) | selectattr(''state'',
                            ''=='', ''off'') | list | count > 0 }}'
                          sequence:
                          - alias: Wait for sun elevation to change
                            wait_for_trigger:
                            - platform: state
                              entity_id: sun.sun
                              attribute: elevation
                        - alias: Set sun elevation colour temperature for the normal
                            lights
                          conditions:
                          - condition: template
                            value_template: '{{ include_dynamic_lighting == ''enable_sun_elevation_colour_lux_brightness''
                              }}'
                          sequence:
                          - service: light.turn_on
                            target:
                              entity_id: '{{ light_entities }}'
                            data: '{{ dynamic_light_data }}'
                          - alias: Wait for sun elevation to change
                            wait_for_trigger:
                            - platform: state
                              entity_id: sun.sun
                              attribute: elevation
          - choose:
            - alias: 9 - Dynamic Lighting - Sun Elevation Lighting - Colour Temp +
                Lux Controlled Brightness Inverted
              conditions:
              - condition: template
                value_template: '{{ include_dynamic_lighting == ''enable_sun_elevation_colour_lux_brightness_inv''
                  }}'
              sequence:
              - alias: Parallel actions for dynamic lighting
                parallel:
                - sequence:
                  - alias: Dynamic Lighting Control
                    repeat:
                      until: '{{ ((dynamic_lighting_boolean == []) and (expand(light_entities)
                        | selectattr(''state'', ''=='', ''off'') | list | count >
                        0)) or ((dynamic_lighting_boolean != []) and (is_state(dynamic_lighting_boolean,
                        ''off''))) }}'
                      sequence:
                      - variables:
                          dynamic_brightness_pct: "{% set lux = states(dynamic_lighting_lux_sensor)
                            | float %} {% set slope = (dynamic_lighting_min_brightness
                            - dynamic_lighting_max_brightness) / (dynamic_lighting_min_lux
                            - dynamic_lighting_max_lux) %} {% set ak = (( slope *
                            dynamic_lighting_min_lux) * -1) + dynamic_lighting_min_brightness
                            %} {% set le = light_entities %} {% set lec = expand(le)
                            | map(attribute='entity_id') | list | length %} {% set
                            lp = (expand(le) | map(attribute='attributes.brightness')
                            | reject('equalto', None) | sum | float(default=255) /
                            255 * 100 / lec) | round(0) %} {% if lux <= dynamic_lighting_min_lux
                            %}\n  {% set bv = dynamic_lighting_min_brightness %}\n{%
                            elif lux >= dynamic_lighting_max_lux %}\n  {% set bv =
                            dynamic_lighting_max_brightness %}\n{% else %}\n  {% set
                            bv = ((slope * lux) + ak) | round(1) %}\n{% endif %} {%
                            if lp <= 0 %}\n  {% set bv = bv %}\n{% elif (bv > lp)
                            and (dynamic_lighting_max_brightness - lp) <= dynamic_lighting_dead_zone
                            %}\n  {% set bv = dynamic_lighting_max_brightness %}\n{%
                            elif (lp > bv) and (lp - dynamic_lighting_min_brightness)
                            <= dynamic_lighting_dead_zone %}\n  {% set bv = dynamic_lighting_min_brightness
                            %}\n{% elif (bv > lp) and (bv - lp) <= dynamic_lighting_dead_zone
                            %}\n  {% set bv = lp %}\n{% elif (lp > bv) and  (lp -
                            bv) <= dynamic_lighting_dead_zone %}\n  {% set bv = lp
                            %}\n{% elif bv > (lp + dynamic_lighting_step_value) %}\n
                            \ {% set bv = lp + dynamic_lighting_step_value %}\n{%
                            elif bv < (lp - dynamic_lighting_step_value) %}\n  {%
                            set bv = lp - dynamic_lighting_step_value %}\n{% endif
                            %} {{ bv | round(0) }}\n"
                          dynamic_kelvin: "{% if expand(light_entities) | selectattr('state',
                            '==', 'off') | list | count > 0 %}\n  {% set elevation
                            = state_attr('sun.sun', 'elevation') | float %}\n  {%
                            set start_slope = (dynamic_lighting_min_colour_temp -
                            dynamic_lighting_max_colour_temp) / (dynamic_lighting_sun_elevation_start_rising
                            - dynamic_lighting_sun_elevation_end_rising) %}\n  {%
                            set start_ak = (( start_slope * dynamic_lighting_sun_elevation_end_rising)
                            * -1) + dynamic_lighting_max_colour_temp %}\n  {% set
                            end_slope = (dynamic_lighting_min_colour_temp - dynamic_lighting_max_colour_temp)
                            / (dynamic_lighting_sun_elevation_end_falling - dynamic_lighting_sun_elevation_start_falling)
                            %}\n  {% set end_ak = (( end_slope * dynamic_lighting_sun_elevation_end_falling)
                            * -1) + dynamic_lighting_min_colour_temp %}\n  {% if elevation
                            >= -10 %}\n    {% if elevation >= dynamic_lighting_sun_elevation_start_rising
                            and elevation <= dynamic_lighting_sun_elevation_end_rising
                            and is_state_attr('sun.sun', 'rising', true) %}\n      {%
                            set colour_temp_value = ((start_slope * elevation) + start_ak)
                            | round(1) %}\n    {% elif elevation <= dynamic_lighting_sun_elevation_start_falling
                            and elevation >= dynamic_lighting_sun_elevation_end_falling
                            and is_state_attr('sun.sun', 'rising', false) %}\n      {%
                            set colour_temp_value = ((end_slope * elevation) + end_ak)
                            | round(1) %}\n    {% elif elevation >= dynamic_lighting_sun_elevation_end_rising
                            and elevation >= dynamic_lighting_sun_elevation_start_falling
                            \ %}\n      {% set colour_temp_value = dynamic_lighting_max_colour_temp
                            %}\n    {% elif elevation <= dynamic_lighting_sun_elevation_start_rising
                            and is_state_attr('sun.sun', 'rising', true) %}\n      {%
                            set colour_temp_value = dynamic_lighting_min_colour_temp
                            %}\n    {% elif elevation <= dynamic_lighting_sun_elevation_end_falling
                            and is_state_attr('sun.sun', 'rising', false) %}\n      {%
                            set colour_temp_value = dynamic_lighting_min_colour_temp
                            %}\n    {% else %}\n      {% set colour_temp_value = dynamic_lighting_max_colour_temp
                            %}\n    {% endif %}\n  {% else %}\n    {% set colour_temp_value
                            = dynamic_lighting_min_colour_temp %}\n  {% endif %}\n
                            \ {{ colour_temp_value | round(0) }}\n{% endif %}\n"
                          dynamic_light_off_data: "{% set light = namespace(data={})
                            %} {% set light.data = dict(light.data, **{ 'brightness_pct':
                            dynamic_brightness_pct }) %} {% set light.data = dict(light.data,
                            **{ 'color_temp_kelvin': dynamic_kelvin }) %} {% if 'use_transition'
                            in include_light_control %}\n  {% set light.data = dict(light.data,
                            **{ 'transition': light_transition_on }) %}\n{% endif
                            %} {{ light.data }}\n"
                          dynamic_light_data: "{% set light = namespace(data={}) %}
                            {% set light.data = dict(light.data, **{ 'brightness_pct':
                            dynamic_brightness_pct }) %} {% if 'use_transition' in
                            include_light_control %}\n  {% set light.data = dict(light.data,
                            **{ 'transition': light_transition_on }) %}\n{% endif
                            %} {{ light.data }}\n"
                          in_dead_zone: "{% set lux = states(dynamic_lighting_lux_sensor)
                            | float %} {% set slope = (dynamic_lighting_min_brightness
                            - dynamic_lighting_max_brightness) / (dynamic_lighting_min_lux
                            - dynamic_lighting_max_lux) %} {% set ak = (( slope *
                            dynamic_lighting_min_lux) * -1) + dynamic_lighting_min_brightness
                            %} {% set le = light_entities %} {% set lec = expand(le)
                            | map(attribute='entity_id') | list | length %} {% set
                            lp = (expand(le) | map(attribute='attributes.brightness')
                            | reject('equalto', None) | sum | float(default=255) /
                            255 * 100 / lec) | round(0) %} {% if lux <= dynamic_lighting_min_lux
                            %}\n  {% set bv = dynamic_lighting_min_brightness %}\n{%
                            elif lux >= dynamic_lighting_max_lux %}\n  {% set bv =
                            dynamic_lighting_max_brightness %}\n{% else %}\n  {% set
                            bv = ((slope * lux) + ak) | round(1) %}\n{% endif %} {%
                            if (bv > lp) and (dynamic_lighting_max_brightness - lp)
                            <= dynamic_lighting_dead_zone %}\n  true\n{% elif (lp
                            > bv) and (lp - dynamic_lighting_min_brightness) <= dynamic_lighting_dead_zone
                            %}\n  false\n{% elif (bv >= lp) and (bv - lp) <= dynamic_lighting_dead_zone
                            %}\n  true\n{% elif (lp >= bv) and (lp - bv) <= dynamic_lighting_dead_zone
                            %}\n  true\n{% else %}\n  false\n{% endif %}\n"
                      - choose:
                        - alias: Check if the light is off
                          conditions: '{{ expand(light_entities) | selectattr(''state'',
                            ''=='', ''off'') | list | count > 0 }}'
                          sequence:
                          - alias: Delay for parallel actions needed for when the
                              light is off
                            delay:
                              milliseconds: 100
                      - choose:
                        - alias: Stop when crossing over
                          conditions:
                          - condition: template
                            value_template: '{{ ''if_lights_are_on_adjust_when_crossing_over''
                              not in include_night_light_control }}'
                          - condition: trigger
                            id:
                            - t13
                            - t14
                            - t15
                          sequence:
                          - stop: Stop the automation
                        - alias: Adjust the lights settings when crossing over if
                            lights are ON is selected in night light control
                          conditions:
                          - condition: template
                            value_template: '{{ ''if_lights_are_on_adjust_when_crossing_over''
                              in include_night_light_control }}'
                          - condition: trigger
                            id:
                            - t13
                            - t14
                            - t15
                          sequence:
                          - alias: Delay for parallel actions needed for when the
                              light is on
                            delay:
                              milliseconds: 100
                          - service: light.turn_on
                            target:
                              entity_id: '{{ light_entities }}'
                            data: '{{ dynamic_light_data }}'
                          - alias: Dynamic lighting heartbeat
                            delay:
                              minutes: !input dynamic_lighting_heartbeat
                        - alias: If dynamic lighting brightness is in the dead zone
                          conditions: '{{ in_dead_zone }}'
                          sequence:
                          - alias: Dynamic lighting heartbeat
                            delay:
                              minutes: !input dynamic_lighting_heartbeat
                        - alias: Set dynamic lighting lux brightness and dynamic sun
                            elevation colour temperature for the normal lights
                          conditions:
                          - condition: template
                            value_template: '{{ include_dynamic_lighting == ''enable_sun_elevation_colour_lux_brightness_inv''
                              }}'
                          - '{{ expand(light_entities) | selectattr(''state'', ''=='',
                            ''off'') | list | count > 0 }}'
                          sequence:
                          - service: light.turn_on
                            target:
                              entity_id: '{{ light_entities }}'
                            data: '{{ dynamic_light_off_data }}'
                          - alias: Dynamic lighting heartbeat
                            delay:
                              minutes: !input dynamic_lighting_heartbeat
                        - alias: Set dynamic lighting lux brightness for the normal
                            lights
                          conditions:
                          - condition: template
                            value_template: '{{ include_dynamic_lighting == ''enable_sun_elevation_colour_lux_brightness_inv''
                              }}'
                          sequence:
                          - service: light.turn_on
                            target:
                              entity_id: '{{ light_entities }}'
                            data: '{{ dynamic_light_data }}'
                          - alias: Dynamic lighting heartbeat
                            delay:
                              minutes: !input dynamic_lighting_heartbeat
                - sequence:
                  - alias: Dynamic Lighting Control
                    repeat:
                      until: '{{ ((dynamic_lighting_boolean == []) and (expand(light_entities)
                        | selectattr(''state'', ''=='', ''off'') | list | count >
                        0)) or ((dynamic_lighting_boolean != []) and (is_state(dynamic_lighting_boolean,
                        ''off''))) }}'
                      sequence:
                      - variables:
                          dynamic_kelvin: "{% set elevation = state_attr('sun.sun',
                            'elevation') | float %} {% set start_slope = (dynamic_lighting_min_colour_temp
                            - dynamic_lighting_max_colour_temp) / (dynamic_lighting_sun_elevation_start_rising
                            - dynamic_lighting_sun_elevation_end_rising) %} {% set
                            start_ak = (( start_slope * dynamic_lighting_sun_elevation_end_rising)
                            * -1) + dynamic_lighting_max_colour_temp %} {% set end_slope
                            = (dynamic_lighting_min_colour_temp - dynamic_lighting_max_colour_temp)
                            / (dynamic_lighting_sun_elevation_end_falling - dynamic_lighting_sun_elevation_start_falling)
                            %} {% set end_ak = (( end_slope * dynamic_lighting_sun_elevation_end_falling)
                            * -1) + dynamic_lighting_min_colour_temp %} {% if elevation
                            >= -10 %}\n  {% if elevation >= dynamic_lighting_sun_elevation_start_rising
                            and elevation <= dynamic_lighting_sun_elevation_end_rising
                            and is_state_attr('sun.sun', 'rising', true) %}\n    {%
                            set colour_temp_value = ((start_slope * elevation) + start_ak)
                            | round(1) %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_falling
                            and elevation >= dynamic_lighting_sun_elevation_end_falling
                            and is_state_attr('sun.sun', 'rising', false) %}\n    {%
                            set colour_temp_value = ((end_slope * elevation) + end_ak)
                            | round(1) %}\n  {% elif elevation >= dynamic_lighting_sun_elevation_end_rising
                            and elevation >= dynamic_lighting_sun_elevation_start_falling
                            \ %}\n    {% set colour_temp_value = dynamic_lighting_max_colour_temp
                            %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_start_rising
                            and is_state_attr('sun.sun', 'rising', true) %}\n    {%
                            set colour_temp_value = dynamic_lighting_min_colour_temp
                            %}\n  {% elif elevation <= dynamic_lighting_sun_elevation_end_falling
                            and is_state_attr('sun.sun', 'rising', false) %}\n    {%
                            set colour_temp_value = dynamic_lighting_min_colour_temp
                            %}\n  {% else %}\n    {% set colour_temp_value = dynamic_lighting_max_colour_temp
                            %}\n  {% endif %}\n{% else %}\n  {% set colour_temp_value
                            = dynamic_lighting_min_colour_temp %}\n{% endif %} {{
                            colour_temp_value | round(0) }}\n"
                          dynamic_light_data: "{% set light = namespace(data={}) %}
                            {% set light.data = dict(light.data, **{ 'color_temp_kelvin':
                            dynamic_kelvin }) %} {% if 'use_transition' in include_light_control
                            %}\n  {% set light.data = dict(light.data, **{ 'transition':
                            light_transition_on }) %}\n{% endif %} {{ light.data }}\n"
                          should_wait: "{% set elevation = state_attr('sun.sun', 'elevation')
                            | float %} {% if expand(light_entities) | selectattr('state',
                            '==', 'on') | list | count > 0 %}\n  {% if elevation >=
                            (dynamic_lighting_sun_elevation_start_rising - 2) and
                            elevation <= (dynamic_lighting_sun_elevation_end_rising
                            + 2) and is_state_attr('sun.sun', 'rising', true) %}\n
                            \   false\n  {% elif elevation <= (dynamic_lighting_sun_elevation_start_falling
                            + 2) and elevation >= (dynamic_lighting_sun_elevation_end_falling
                            - 2) and is_state_attr('sun.sun', 'rising', false) %}\n
                            \   false\n  {% elif elevation >= (dynamic_lighting_sun_elevation_end_rising
                            + 2) and elevation >= (dynamic_lighting_sun_elevation_start_falling
                            - 2)  %}\n    true\n  {% elif elevation <= (dynamic_lighting_sun_elevation_start_rising
                            - 2) and is_state_attr('sun.sun', 'rising', true) %}\n
                            \   true\n  {% elif elevation <= (dynamic_lighting_sun_elevation_end_falling
                            - 2) and is_state_attr('sun.sun', 'rising', false) %}\n
                            \   true\n  {% else %}\n    true\n  {% endif %}\n{% else
                            %}\n  false\n{% endif %}\n"
                      - choose:
                        - alias: Stop when crossing over
                          conditions:
                          - condition: template
                            value_template: '{{ ''if_lights_are_on_adjust_when_crossing_over''
                              not in include_night_light_control }}'
                          - condition: trigger
                            id:
                            - t13
                            - t14
                            - t15
                          sequence:
                          - stop: Stop the automation
                        - alias: Adjust the lights settings when crossing over if
                            lights are ON is selected in night light control
                          conditions:
                          - condition: template
                            value_template: '{{ ''if_lights_are_on_adjust_when_crossing_over''
                              in include_night_light_control }}'
                          - condition: trigger
                            id:
                            - t13
                            - t14
                            - t15
                          sequence:
                          - service: light.turn_on
                            target:
                              entity_id: '{{ light_entities }}'
                            data: '{{ dynamic_light_data }}'
                          - alias: Wait for sun elevation to change
                            wait_for_trigger:
                            - platform: state
                              entity_id: sun.sun
                              attribute: elevation
                        - alias: If sun elevation is outside the adjustment zone and
                            the lights are ON
                          conditions: '{{ should_wait }}'
                          sequence:
                          - alias: Wait for sun elevation to change
                            wait_for_trigger:
                            - platform: state
                              entity_id: sun.sun
                              attribute: elevation
                        - alias: If the lights are OFF
                          conditions: '{{ expand(light_entities) | selectattr(''state'',
                            ''=='', ''off'') | list | count > 0 }}'
                          sequence:
                          - alias: Wait for sun elevation to change
                            wait_for_trigger:
                            - platform: state
                              entity_id: sun.sun
                              attribute: elevation
                        - alias: Set sun elevation colour temperature for the normal
                            lights
                          conditions:
                          - condition: template
                            value_template: '{{ include_dynamic_lighting == ''enable_sun_elevation_colour_lux_brightness_inv''
                              }}'
                          sequence:
                          - service: light.turn_on
                            target:
                              entity_id: '{{ light_entities }}'
                            data: '{{ dynamic_light_data }}'
                          - alias: Wait for sun elevation to change
                            wait_for_trigger:
                            - platform: state
                              entity_id: sun.sun
                              attribute: elevation
          - stop: Stop the automation
        - sequence:
          - choose:
            - alias: Turn ON lights
              conditions:
              - condition: template
                value_template: '{{ include_dynamic_lighting == ''disable_dynamic_lighting''
                  }}'
              sequence:
              - service: light.turn_on
                target:
                  entity_id: '{{ light_entities_off }}'
                data: '{{ light_data }}'
          - choose:
            - alias: If transition is selected
              conditions:
              - condition: template
                value_template: '{{ ''use_transition'' in include_light_control }}'
              sequence:
              - alias: Turn on the scenes
                service: scene.turn_on
                target:
                  entity_id: '{{ scene_entities }}'
                data:
                  transition: '{{ light_transition_on }}'
              - alias: Turn on the boolean for scenes and scripts
                service: input_boolean.turn_on
                data:
                  entity_id: '{{ boolean_scenes_scripts_helper }}'
            - alias: If transition is not selected
              conditions:
              - condition: template
                value_template: '{{ ''use_transition'' not in include_light_control
                  }}'
              sequence:
              - alias: Turn on the scenes
                service: scene.turn_on
                target:
                  entity_id: '{{ scene_entities }}'
              - alias: Turn on the boolean for scenes and scripts
                service: input_boolean.turn_on
                data:
                  entity_id: '{{ boolean_scenes_scripts_helper }}'
          - alias: Turn on the switches
            service: switch.turn_on
            target:
              entity_id: '{{ switch_entities_off }}'
          - alias: Turn on the scripts
            service: script.turn_on
            target:
              entity_id: '{{ script_entities }}'
          - choose:
            - alias: By-pass is enabled & check by-pass option - Turn lights on
              conditions:
              - condition: trigger
                id: t8_on
              sequence:
              - alias: Check by-pass settings and preform the correct action
                if:
                - alias: Check if the by-pass auto off is enabled
                  condition: template
                  value_template: '{{ (''bypass_auto_off_enabled_on'' in include_bypass_auto_off)
                    or (''bypass_auto_off_enabled_off'' in include_bypass_auto_off)
                    or (''bypass_auto_off_enabled_stop'' in include_bypass_auto_off)
                    }}'
                then:
                - alias: Wait the number of minutes set in the by-pass auto off time
                    delay
                  delay:
                    minutes: !input bypass_auto_off_delay
                - alias: Parallel Actions for the by-pass auto off
                  parallel:
                  - sequence:
                    - choose:
                      - conditions:
                        - condition: template
                          value_template: '{{ (''bypass_enabled_turn_on'' in include_bypass)
                            and (''bypass_auto_off_enabled_on'' in include_bypass_auto_off)
                            }}'
                        sequence:
                        - alias: Turn off the by-pass
                          service: homeassistant.turn_off
                          entity_id: !input bypass_lights_on
                  - sequence:
                    - choose:
                      - conditions:
                        - condition: template
                          value_template: '{{ (''bypass_enabled_turn_off'' in include_bypass)
                            and (''bypass_auto_off_enabled_off'' in include_bypass_auto_off)
                            }}'
                        sequence:
                        - alias: Turn off the by-pass
                          service: homeassistant.turn_off
                          entity_id: !input bypass_lights_off
                  - sequence:
                    - choose:
                      - conditions:
                        - condition: template
                          value_template: '{{ (''bypass_enabled_stop'' in include_bypass)
                            and (''bypass_auto_off_enabled_stop'' in include_bypass_auto_off)
                            }}'
                        sequence:
                        - alias: Turn off the by-pass
                          service: homeassistant.turn_off
                          entity_id: !input bypass_lights_stop
                - stop: Stop the automation
                else:
                - stop: Stop the automation
    - conditions:
      - condition: trigger
        id:
        - t1
        - t3
        - t5
        - t7
      sequence:
      - choose:
        - alias: Dynamic Lighting - Input Boolean Helper
          conditions:
          - condition: template
            value_template: '{{ dynamic_lighting_boolean != [] }}'
          sequence:
          - alias: Turn off the boolean for dynamic lighting
            service: input_boolean.turn_off
            data:
              entity_id: !input dynamic_lighting_boolean
      - choose:
        - alias: If transition is selected
          conditions:
          - condition: template
            value_template: '{{ ''use_transition'' in include_light_control }}'
          sequence:
          - alias: Turn off the lights
            service: light.turn_off
            target:
              entity_id: '{{ light_entities }}'
            data:
              transition: '{{ light_transition_off }}'
          - alias: Turn off the scenes
            service: scene.turn_on
            data:
              entity_id: '{{ end_scene_entities }}'
              transition: '{{ light_transition_off }}'
        - alias: If transition is not selected
          conditions:
          - condition: template
            value_template: '{{ ''use_transition'' not in include_light_control }}'
          sequence:
          - alias: Turn off the lights
            service: light.turn_off
            target:
              entity_id: '{{ light_entities }}'
          - alias: Turn off the scenes
            service: scene.turn_on
            data:
              entity_id: '{{ end_scene_entities }}'
      - alias: Turn off the switches
        service: switch.turn_off
        target:
          entity_id: '{{ switch_entities }}'
      - alias: Turn off the script
        service: script.turn_on
        data:
          entity_id: '{{ end_script_entities }}'
      - alias: Turn off the boolean for scenes and scripts
        service: input_boolean.turn_off
        data:
          entity_id: !input boolean_scenes_scripts
