blueprint: name: Smart Light description: > # 🔆 Smart Light **Version: 3.3** Smart Lighting: Your Lights, Your Way - Take Control and Customize it to Perfection!💡✨ **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) 🙂
The Automation Process: 👈 - **Trigger Options:** Activate lights, switches, scenes, and scripts when the automation is triggered. - **Entity State:** - Turn lights ON when an entity changes from OFF to ON. - Turn lights OFF when an entity changes from ON to OFF. - **Press Button:** - Turn lights ON when you press a button. - Turn lights OFF when you press a button. - **Sun Elevation:** - Turn lights ON when the sun's elevation falls below a set value. - Turn lights OFF when the sun's elevation rises above a set value. - **Ambient Light:** - Turn lights ON when ambient light falls below a set LUX value. - Turn lights OFF when ambient light rises above a set LUX value. - **Time-Based Option:** - Define start and end times to turn lights ON and OFF. - **Light Control Options:** - Utilize "Light Control" to adjust brightness, colour temperature, colour, and transition times. - **Dynamic Lighting Options:** - Opt for 'Dynamic Lighting' to automatically adjust brightness based on lux values, and/or adjust brightness and colour temperature according to the sun's position or the time of day. - Opt to use the 'State Control Option,' allowing you to toggle between dynamic lighting and normal lighting based on the entity's activation state. - **Night Lights Mode:** - Enable 'Night Lights' for softer illumination during night time activities, automatically enabled based on conditions. - **Manual Override:** - Use "Bypass Options" for manual bypassing of trigger sensors, providing manual control and additional customization. - **Weekdays Condition Option:** - Specify the weekday selections to define when the automation can run.
Need help? - FAQ: [Click Here](https://community.home-assistant.io/t/527354/2) - Community Support Including Updates: [Click Here](https://community.home-assistant.io/t/527354) Required = * 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. 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) If you would like to use a motion sensor, please consider using my 💡Sensor Light Blueprint [Click Here](https://community.home-assistant.io/t/481048) default: [] selector: select: multiple: true options: - label: ON State value: "entity_on" - label: OFF State value: "entity_off" entity_input: name: Input Entity description: > Please select an entity with an ON/OFF state. default: [] selector: entity: trigger_button: name: "Trigger - Push Button" icon: mdi:gesture-tap-button collapsed: true input: include_button: name: Use The Push Button Option (Optional) description: > Adds triggers that activate when the selected button is pressed. Each time you press the button, choose whether to trigger the lights ON, OFF, or both. default: [] selector: select: multiple: true options: - label: Push Button ON value: "button_on" - label: Push Button OFF value: "button_off" button_input: name: Input Button Entity description: > Choose the physical or virtual button entity that will trigger this automation. 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" 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 max: 5 step: 0.5 unit_of_measurement: degrees 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 max: 5 step: 0.5 unit_of_measurement: degrees 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" ambient_light_sensor: name: Ambient Light Sensor description: > Select the ambient light sensor. default: [] selector: entity: filter: domain: sensor device_class: illuminance 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 max: 500 step: 10 unit_of_measurement: lux 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 max: 1000 step: 10 unit_of_measurement: lux 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" 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 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" light_brightness: name: Brightness description: > The brightness setting for the lights when they are turned ON. default: 100 selector: number: min: 1 max: 100 mode: slider step: 1 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 max: 5 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 max: 30 mode: slider step: 1 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" 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 max: 8000 mode: slider step: 100 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 makes continual adjustments to your normal lighting setup by modulating brightness based on floating lux values, or adapting both colour temperature and brightness according to the sun's changing elevation or the time of day. Choose from thirteen 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 10 - Time Controlled - Colour Temp 11 - Time Controlled - Brightness 12 - Time Controlled - Brightness Inverted 13 - Time Controlled - Colour Temp + Brightness 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, 9, 10 or 13" 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" - label: 10 - Time Controlled - Colour Temp value: "enable_time_controled_colour" - label: 11 - Time Controlled - Brightness value: "enable_time_controled_brightness" - label: 12 - Time Controlled - Brightness Inverted value: "enable_time_controled_brightness_inv" - label: 13 - Time Controlled - Colour Temp + Brightness value: "enable_time_controled_colour_brightness" 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 your selected Dynamic Lighting option. default: [] selector: entity: filter: domain: sensor device_class: illuminance 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 max: 900 step: 10 unit_of_measurement: lux 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 max: 600 step: 10 unit_of_measurement: lux dynamic_lighting_max_brightness: name: Dynamic Lighting - Max Brightness Value description: > **Used in options 1, 2, 4, 5, 6, 7, 8, 9, 11, 12 or 13** - Define the maximum brightness value, determines the peak brightness level for your lights. default: 100 selector: number: min: 10 max: 100 step: 1 unit_of_measurement: '%' dynamic_lighting_min_brightness: name: Dynamic Lighting - Min Brightness Value description: > **Used in options 1, 2, 4, 5, 6, 7, 8, 9, 11, 12 or 13** - 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 max: 100 step: 1 unit_of_measurement: '%' dynamic_lighting_boolean: name: Dynamic Lighting - Toggle Helper (Optional) description: > **Used in options 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12 or 13** - 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 dynamic_lighting_max_colour_temp: name: Dynamic Lighting - Max Colour Temperature description: > **Used in options 3, 6, 7, 8, 9, 10 or 13** - Specify the highest colour temperature value, determining the coolest colour setting for your lights. default: 5000 selector: number: min: 2500 max: 8000 mode: slider step: 100 unit_of_measurement: 'kelvin' dynamic_lighting_min_colour_temp: name: Dynamic Lighting - Min Colour Temperature description: > **Used in options 3, 6, 7, 8, 9, 10 or 13** - Set the lowest colour temperature value, defining the warmest colour setting for your lights. default: 3000 selector: number: min: 2000 max: 7500 mode: slider step: 100 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 your selected Dynamic Lighting option. default: -1.5 selector: number: min: -10 max: 30 step: 0.5 unit_of_measurement: degrees 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, based on your selected Dynamic Lighting option. default: 15 selector: number: min: 0 max: 90 step: 0.5 unit_of_measurement: degrees 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 your selected Dynamic Lighting option. default: 15 selector: number: min: 0 max: 90 step: 0.5 unit_of_measurement: degrees 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, based on your selected Dynamic Lighting option. default: -4.0 selector: number: min: -10 max: 30 step: 0.5 unit_of_measurement: degrees dynamic_lighting_time_start_morning: name: Dynamic Lighting - Time Morning - Start Point description: > **Used in options 10, 11, 12 or 13** - When the time passes over the start 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 your selected Dynamic Lighting option. default: "06:00:00" selector: time: dynamic_lighting_time_end_morning: name: Dynamic Lighting - Time Morning - End Point description: > **Used in options 10, 11, 12 or 13** - When the time passes over the end point, the maximum colour temperature and maximum brightness value will be established, based on your selected Dynamic Lighting option. default: "09:00:00" selector: time: dynamic_lighting_time_start_evening: name: Dynamic Lighting - Time Evening - Start Point description: > **Used in options 10, 11, 12 or 13** - When the time passes over the start 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 your selected Dynamic Lighting option. default: "17:00:00" selector: time: dynamic_lighting_time_end_evening: name: Dynamic Lighting - Time Evening - End Point description: > **Used in options 10, 11, 12 or 13** - When the time passes over the end point, the minimum colour temperature and minimum brightness value will be established, based on your selected Dynamic Lighting option. default: "19:00:00" selector: time: dynamic_lighting_heartbeat: name: Dynamic Lighting - Heartbeat description: > **Used in options 1, 2, 8, 9, 10, 11, 12 or 13** - Define the heartbeat rate to set the operational speed. During each heartbeat, it may evaluate the lux value, light brightness, colour temperature, target colour temperature, and target brightness, adjusting the colour temperature or brightness based on your selected Dynamic Lighting option. **Note** - When using a **Time Controlled** option (10, 11, 12, or 13), the minimum heartbeat should be set to no lower than 1 minute, with adjustments made in 1-minute increments (e.g., 1, 2, 3, 4, 5, and so on), as setting it lower will not provide any benefit and may slow down your system's performance. Depending on the duration between the start and end points of the light transition, adjusting this value will determine the size of the step value. A longer heartbeat generally improves performance, but it may also result in larger step values that could be bothersome to the eye. Take the time to determine the correct heartbeat value for your needs. The heartbeat is only active between the start and end points. default: 1 selector: number: min: 0.25 max: 10 step: 0.25 unit_of_measurement: minutes 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 targeted brightness. If the targeted brightness exceeds the predefined step value, the system applies the set step value to gradually moderate the rate of change, ensuring a smoother transition in light brightness. default: 4 selector: number: min: 1 max: 100 step: 1 unit_of_measurement: '%' 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 max: 15 step: 1 unit_of_measurement: '%' dynamic_lighting_state_control: name: Dynamic Lighting - State Control Option (Optional) description: > Enable or disable dynamic lighting based on the state of a specified entity. When the entity is in the selected activation state below, dynamic lighting will function as configured. When the entity is not in the activation state below, dynamic lighting will be disabled. This allows you to toggle between normal lighting and dynamic lighting based on the entity's state. default: disable_state_control selector: select: options: - label: Enable State Control Option value: "enable_state_control" - label: Disable State Control Option value: "disable_state_control" dynamic_lighting_state_control_activation_state: name: Dynamic Lighting - State Control Activation State description: > Select the state the entity must be in to activate dynamic lighting. When the entity is in the selected state (ON or OFF), dynamic lighting will be enabled. This option defines the activation condition for dynamic lighting. default: "on" selector: select: options: - label: ON State value: "on" - label: OFF State value: "off" dynamic_lighting_state_control_entity: name: Dynamic Lighting - State Control Entity description: > If the state control option above is enabled, select the entity that will toggle dynamic lighting based on its activation state above. default: [] selector: entity: 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 determines how your lights will behave when the bypass switch is turned ON: 1 - Turns the lights ON 2 - Turns the lights OFF 3 - Keeps the lights current state If you enable an option, make sure to enter the corresponding bypass switch in the input below. default: [] selector: select: options: - label: 1 - Enable the Bypass - Turn the Lights ON value: "bypass_enabled_turn_on" - label: 2 - Enable the Bypass - Turn the Lights OFF value: "bypass_enabled_turn_off" - label: 3 - Enable the Bypass - Keep the Lights Current State value: "bypass_enabled_stop" multiple: true bypass_lights_on: name: Bypass Switch - Turn the 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 the 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 specific bypass scenarios when your lights are ON: 1. When you have selected option 2 above to "Enable the Bypass - Turn the Lights OFF" and you turn the bypass ON. 2. When the bypass is turned OFF, the trigger sensor is OFF, and your lights are still ON. In both cases, the automation will turn your lights OFF after the set time delay. default: 0 selector: number: min: 0 max: 10 step: 0.25 unit_of_measurement: minutes include_bypass_auto_off: name: Use The Bypass Auto OFF Option (Optional) description: > Enable this option if you want the bypass to automatically turn OFF after a set time delay. You can choose which bypass option the auto OFF will apply to: 1 - Turns the lights ON 2 - Turns the lights OFF 3 - Keeps the lights current state Each option corresponds to one of the bypass options above. default: [] selector: select: options: - label: A - Enable Auto OFF for Bypass Option 1 - Turn the Lights ON value: "bypass_auto_off_enabled_on" - label: B - Enable Auto OFF for Bypass Option 2 - Turn the Lights OFF value: "bypass_auto_off_enabled_off" - label: C - Enable Auto OFF for Bypass Option 3 - Keep the Lights Current State value: "bypass_auto_off_enabled_stop" multiple: true 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 max: 240 step: 1 unit_of_measurement: minutes 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" 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" 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" 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" 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 max: 5 step: 0.5 unit_of_measurement: degrees 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 max: 5 step: 0.5 unit_of_measurement: degrees 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 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. Selecting **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. Selecting **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. Selecting **Use cross over time delay from night lights to normal lights** applies to the night lights conditions. This delay is especially useful when using the night lights state condition with a motion sensor, as it adds a buffer period after the motion sensor clears before switching to normal lighting. 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" - label: Use cross over time delay from night lights to normal lights value: "use_delay" 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 max: 100 mode: slider step: 1 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 max: 5 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 max: 30 mode: slider step: 1 unit_of_measurement: seconds cross_over_time_delay: name: Cross Over - Time Delay description: > The time delay sets the duration the night lights stay active after the night light condition is deactivated, before transitioning to normal lighting. default: 5 selector: number: min: 0 max: 30 step: 0.5 unit_of_measurement: minutes 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" 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 max: 8000 mode: slider step: 100 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: ha_restart: name: "HA Restart" icon: mdi:restart collapsed: true input: include_ha_restart: name: Use The HA Restart Option (Optional) description: > Because this automation supports many scenarios, the HA Restart safeguard option may not always behave as expected. In most cases it works fine, so it’s enabled by default. However, if you find it causes issues in your setup, you can disable this option. In most cases, when HA restarts, the automation will not land on an ON or OFF state, so disabling this option gives you a higher chance that nothing goes wrong. default: enable_ha_restart selector: select: options: - label: Enable the HA Restart option value: "enable_ha_restart" - label: Disable the HA Restart value: "disable_ha_restart" mode: restart max_exceeded: silent variables: include_entity_state: !input include_entity_state entity_input: !input entity_input include_button: !input include_button button_input: !input button_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_time_start_morning: !input dynamic_lighting_time_start_morning dynamic_lighting_time_end_morning: !input dynamic_lighting_time_end_morning dynamic_lighting_time_start_evening: !input dynamic_lighting_time_start_evening dynamic_lighting_time_end_evening: !input dynamic_lighting_time_end_evening 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 dynamic_lighting_state_control: !input dynamic_lighting_state_control dynamic_lighting_state_control_activation_state: !input dynamic_lighting_state_control_activation_state dynamic_lighting_state_control_entity: !input dynamic_lighting_state_control_entity 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 cross_over_time_delay: !input cross_over_time_delay 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 include_ha_restart: !input include_ha_restart # Split domains for light switch targets and check the entities are OFF - exclude scenes and scripts as they have no off state 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 }}" # For light control - Light data light_data: >- {% set light = namespace(data={}) %} {% if 'use_transition' in include_light_control %} {% set light.data = dict(light.data, **{ 'transition': light_transition_on }) %} {% endif %} {% if 'use_brightness' in include_light_control %} {% set light.data = dict(light.data, **{ 'brightness_pct': light_brightness }) %} {% endif %} {% if include_light_colour_control == 'use_colour_temperature' %} {% set light.data = dict(light.data, **{ 'color_temp_kelvin': light_colour_temperature }) %} {% endif %} {% if include_light_colour_control == 'use_rgb_colour' %} {% set light.data = dict(light.data, **{ 'rgb_color': light_rgb_colour }) %} {% endif %} {% if include_light_colour_control == 'use_rgbw_colour' %} {% set light.data = dict(light.data, **{ 'rgbw_color': light_rgbw_colour }) %} {% endif %} {% if include_light_colour_control == 'use_rgbww_colour' %} {% set light.data = dict(light.data, **{ 'rgbww_color': light_rgbww_colour }) %} {% endif %} {{ light.data }} # Split domains for light switch targets 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 == [] %} {{ expand(a) | selectattr('domain', 'eq', 'scene') | map(attribute='entity_id') | list }} {% elif is_state(boolean_scenes_scripts, 'off') %} {{ expand(a) | selectattr('domain', 'eq', 'scene') | map(attribute='entity_id') | list }} {% else %} [] {% endif %} script_entities: >- {% set a = light_switch.entity_id %} {% if boolean_scenes_scripts == [] %} {{ expand(a) | selectattr('domain', 'eq', 'script') | map(attribute='entity_id') | list }} {% elif is_state(boolean_scenes_scripts, 'off') %} {{ expand(a) | selectattr('domain', 'eq', 'script') | map(attribute='entity_id') | list }} {% else %} [] {% endif %} boolean_scenes_scripts_helper: >- {% if boolean_scenes_scripts | length > 0 and states(boolean_scenes_scripts) == 'off' %} {{ boolean_scenes_scripts }} {% else %} [] {% endif %} # Split domains for end scenes and scripts end_scene_entities: "{{ end_scenes | select('match', '^scene\\..*') | list }}" end_script_entities: "{{ end_scenes | select('match', '^script\\..*') | list }}" # Split domains for night lights target and check the entities are OFF - Exclude scenes and scripts as they have no off state night_light_entities_off: >- {% set b = night_lights and night_lights.entity_id %} {% if b %} {{ expand(b) | selectattr('domain', 'eq', 'light') | selectattr('state', 'eq', 'off') | map(attribute='entity_id') | list }} {% else %} [] {% endif %} night_switch_entities_off: >- {% set b = night_lights and night_lights.entity_id %} {% if b %} {{ expand(b) | selectattr('domain', 'eq', 'switch') | selectattr('state', 'eq', 'off') | map(attribute='entity_id') | list }} {% else %} [] {% endif %} # For night light control - Light data night_light_data: >- {% set light = namespace(data={}) %} {% if 'use_transition' in include_night_light_control %} {% set light.data = dict(light.data, **{ 'transition': night_light_transition_on }) %} {% endif %} {% if 'use_brightness' in include_night_light_control %} {% set light.data = dict(light.data, **{ 'brightness_pct': night_light_brightness }) %} {% endif %} {% if include_night_light_colour_control == 'use_colour_temperature' %} {% set light.data = dict(light.data, **{ 'color_temp_kelvin': night_light_colour_temperature }) %} {% endif %} {% if include_night_light_colour_control == 'use_rgb_colour' %} {% set light.data = dict(light.data, **{ 'rgb_color': night_light_rgb_colour }) %} {% endif %} {% if include_night_light_colour_control == 'use_rgbw_colour' %} {% set light.data = dict(light.data, **{ 'rgbw_color': night_light_rgbw_colour }) %} {% endif %} {% if include_night_light_colour_control == 'use_rgbww_colour' %} {% set light.data = dict(light.data, **{ 'rgbww_color': night_light_rgbww_colour }) %} {% endif %} {{ light.data }} # Split domains for night lights target night_light_entities: >- {% set b = night_lights and night_lights.entity_id %} {% if b %} {{ expand(b) | selectattr('domain', 'eq', 'light') | map(attribute='entity_id') | list }} {% else %} [] {% endif %} night_switch_entities: >- {% set b = night_lights and night_lights.entity_id %} {% if b %} {{ expand(b) | selectattr('domain', 'eq', 'switch') | map(attribute='entity_id') | list }} {% else %} [] {% endif %} night_scene_entities: >- {% set b = night_lights and night_lights.entity_id %} {% if night_boolean_scenes_scripts == [] %} {{ expand(b) | selectattr('domain', 'eq', 'scene') | map(attribute='entity_id') | list }} {% elif is_state(night_boolean_scenes_scripts, 'off') %} {{ expand(b) | selectattr('domain', 'eq', 'scene') | map(attribute='entity_id') | list }} {% else %} [] {% endif %} night_script_entities: >- {% set b = night_lights and night_lights.entity_id %} {% if night_boolean_scenes_scripts == [] %} {{ expand(b) | selectattr('domain', 'eq', 'script') | map(attribute='entity_id') | list }} {% elif is_state(night_boolean_scenes_scripts, 'off') %} {{ expand(b) | selectattr('domain', 'eq', 'script') | map(attribute='entity_id') | list }} {% else %} [] {% endif %} night_boolean_scenes_scripts_helper: >- {% if night_boolean_scenes_scripts | length > 0 and states(night_boolean_scenes_scripts) == 'off' %} {{ night_boolean_scenes_scripts }} {% else %} [] {% endif %} # Set up crossover lights for t10, t11 & t12 trigger. Also used in bypass t9 on, off & stop. crossover_lights_light: >- {% set a = light_switch.entity_id %} {% set b = night_lights and night_lights.entity_id %} {% if a and b %} {{ expand(a) | reject('in', expand(b)) | selectattr('domain', 'eq', 'light') | selectattr('state', 'eq', 'on') | map(attribute='entity_id') | list }} {% else %} [] {% endif %} crossover_lights_switch: >- {% set a = light_switch.entity_id %} {% set b = night_lights and night_lights.entity_id %} {% if a and b %} {{ expand(a) | reject('in', expand(b)) | selectattr('domain', 'eq', 'switch') | selectattr('state', 'eq', 'on') | map(attribute='entity_id') | list }} {% else %} [] {% endif %} crossover_night_lights_light_on: >- {% set b = night_lights and night_lights.entity_id %} {% if b %} {{ expand(b) | selectattr('domain', 'eq', 'light') | selectattr('state', 'eq', 'on') | map(attribute='entity_id') | list }} {% else %} [] {% endif %} # Set up crossover lights for t13, t14 & t15 trigger. Also used in bypass t9 on, off & stop. crossover_night_lights_light: >- {% set a = light_switch.entity_id %} {% set b = night_lights and night_lights.entity_id %} {% if a and b %} {{ expand(b) | reject('in', expand(a)) | selectattr('domain', 'eq', 'light') | selectattr('state', 'eq', 'on') | map(attribute='entity_id') | list }} {% else %} [] {% endif %} crossover_night_lights_switch: >- {% set a = light_switch.entity_id %} {% set b = night_lights and night_lights.entity_id %} {% if a and b %} {{ expand(b) | reject('in', expand(a)) | selectattr('domain', 'eq', 'switch') | selectattr('state', 'eq', 'on') | map(attribute='entity_id') | list }} {% else %} [] {% endif %} crossover_lights_light_on: >- {% set a = light_switch.entity_id %} {% if a %} {{ expand(a) | selectattr('domain', 'eq', 'light') | selectattr('state', 'eq', 'on') | map(attribute='entity_id') | list }} {% else %} [] {% endif %} # Set up conditions for the bypass and HA restart trigger_options_on: > {% set result = true %} {% if 'entity_on' in include_entity_state %} {% set result = result and (states[entity_input].state == 'on') %} {% endif %} {% if 'entity_off' in include_entity_state %} {% set result = result and (states[entity_input].state == 'on') %} {% endif %} {% if 'sun_falling' in include_sun and 'sun_rising' in include_sun %} {% set sun_falling_condition = (is_state_attr('sun.sun', 'rising', false)) and (state_attr('sun.sun', 'elevation') <= sun_elevation | float(90)) %} {% set sun_rising_condition = (is_state_attr('sun.sun', 'rising', true)) and (state_attr('sun.sun', 'elevation') <= sun_elevation_rising | float(90)) %} {% set result = result and (sun_falling_condition or sun_rising_condition) %} {% endif %} {% if 'sun_falling' in include_sun and is_state_attr('sun.sun', 'rising', false) and not 'sun_rising' in include_sun and not 'time_off' in include_time %} {% set sun_falling_condition = (state_attr('sun.sun', 'elevation') <= sun_elevation | float(90)) %} {% set result = result and sun_falling_condition %} {% endif %} {% if 'sun_rising' in include_sun and is_state_attr('sun.sun', 'rising', true) and not 'sun_falling' in include_sun %} {% set sun_rising_condition = (state_attr('sun.sun', 'elevation') <= sun_elevation_rising | float(90)) %} {% set result = result and sun_rising_condition %} {% endif %} {% if 'sun_falling' in include_sun and 'time_off' in include_time and not 'sun_rising' in include_sun and not 'time_on' in include_time %} {% set sun_falling_condition = (is_state_attr('sun.sun', 'rising', false)) and (state_attr('sun.sun', 'elevation') <= sun_elevation | float(90)) %} {% set time_off_condition = result and (now().time() <= strptime(before_time, '%H:%M:%S').time()) %} {% if sun_falling_condition and time_off_condition %} {% set result = true %} {% else %} {% set result = false %} {% endif %} {% endif %} {% if 'ambient_high' in include_ambient and 'ambient_low' in include_ambient %} {% set result = result and (states[ambient_light_sensor].state | float < ambient_light_value_off | float) %} {% endif %} {% if 'ambient_low' in include_ambient and not 'ambient_high' in include_ambient %} {% set result = result and (states[ambient_light_sensor].state | float < ambient_light_value | float(90)) %} {% endif %} {% if 'ambient_high' in include_ambient and not 'ambient_low' in include_ambient%} {% set result = result and (states[ambient_light_sensor].state | float < ambient_light_value_off | float) %} {% endif %} {% if 'time_on' in include_time and 'time_off' in include_time %} {% set time_condition = (strptime(after_time, '%H:%M:%S').time() <= now().time() <= strptime(before_time, '%H:%M:%S').time()) %} {% set result = result and time_condition %} {% endif %} {% if 'time_on' in include_time and not 'time_off' in include_time %} {% set result = result and (now().time() >= strptime(after_time, '%H:%M:%S').time()) %} {% endif %} {% if 'time_off' in include_time and not 'time_on' in include_time and not 'sun_falling' in include_sun %} {% set result = result and (now().time() <= strptime(before_time, '%H:%M:%S').time()) %} {% endif %} {{ result }} trigger_options_off: > {% set result = true %} {% if 'entity_on' in include_entity_state %} {% set result = result and (states[entity_input].state == 'on') %} {% endif %} {% if 'entity_off' in include_entity_state %} {% set result = result and (states[entity_input].state == 'on') %} {% endif %} {% if 'sun_falling' in include_sun and 'sun_rising' in include_sun %} {% set sun_falling_condition = (is_state_attr('sun.sun', 'rising', false)) and (state_attr('sun.sun', 'elevation') <= sun_elevation | float(90)) %} {% set sun_rising_condition = (is_state_attr('sun.sun', 'rising', true)) and (state_attr('sun.sun', 'elevation') <= sun_elevation_rising | float(90)) %} {% set result = result and (sun_falling_condition or sun_rising_condition) %} {% endif %} {% if 'sun_falling' in include_sun and is_state_attr('sun.sun', 'rising', false) and not 'sun_rising' in include_sun and not 'time_off' in include_time %} {% set sun_falling_condition = (state_attr('sun.sun', 'elevation') <= sun_elevation | float(90)) %} {% set result = result and sun_falling_condition %} {% endif %} {% if 'sun_rising' in include_sun and is_state_attr('sun.sun', 'rising', true) and not 'sun_falling' in include_sun %} {% set sun_rising_condition = (state_attr('sun.sun', 'elevation') <= sun_elevation_rising | float(90)) %} {% set result = result and sun_rising_condition %} {% endif %} {% if 'sun_falling' in include_sun and 'time_off' in include_time and not 'sun_rising' in include_sun and not 'time_on' in include_time %} {% set sun_falling_condition = (is_state_attr('sun.sun', 'rising', false)) and (state_attr('sun.sun', 'elevation') <= sun_elevation | float(90)) %} {% set time_off_condition = result and (now().time() <= strptime(before_time, '%H:%M:%S').time()) %} {% if sun_falling_condition and time_off_condition %} {% set result = true %} {% else %} {% set result = false %} {% endif %} {% endif %} {% if 'ambient_high' in include_ambient and 'ambient_low' in include_ambient %} {% set result = result and (states[ambient_light_sensor].state | float < ambient_light_value_off | float) %} {% endif %} {% if 'ambient_low' in include_ambient and not 'ambient_high' in include_ambient %} {% set result = result and (states[ambient_light_sensor].state | float < ambient_light_value | float(90)) %} {% endif %} {% if 'ambient_high' in include_ambient and not 'ambient_low' in include_ambient%} {% set result = result and (states[ambient_light_sensor].state | float < ambient_light_value_off | float) %} {% endif %} {% if 'time_on' in include_time and 'time_off' in include_time %} {% set time_condition = (strptime(after_time, '%H:%M:%S').time() <= now().time() <= strptime(before_time, '%H:%M:%S').time()) %} {% set result = result and time_condition %} {% endif %} {% if 'time_on' in include_time and not 'time_off' in include_time %} {% set result = result and (now().time() >= strptime(after_time, '%H:%M:%S').time()) %} {% endif %} {% if 'time_off' in include_time and not 'time_on' in include_time and not 'sun_falling' in include_sun %} {% set result = result and (now().time() <= strptime(before_time, '%H:%M:%S').time()) %} {% endif %} {{ not result }} # For dynamic lighting state control option dynamic_lighting_state_control_activation_state_inv: > {% if dynamic_lighting_state_control_activation_state == 'on' %} off {% else %} on {% endif %} triggers: - trigger: state id: "t0" entity_id: !input entity_input from: "off" to: "on" - trigger: state id: "t1" entity_id: !input entity_input from: "on" to: "off" - trigger: numeric_state id: "t2" entity_id: sun.sun attribute: elevation below: !input sun_elevation - trigger: numeric_state id: "t3" entity_id: sun.sun attribute: elevation above: !input sun_elevation_rising - trigger: numeric_state id: "t4" entity_id: !input ambient_light_sensor below: !input ambient_light_value - trigger: numeric_state id: "t5" entity_id: !input ambient_light_sensor above: !input ambient_light_value_off - trigger: time id: "t6" at: !input after_time - trigger: time id: "t7" at: !input before_time - trigger: state id: "t8_on" entity_id: !input bypass_lights_on from: "off" to: "on" - trigger: state id: "t8_off" entity_id: !input bypass_lights_off from: "off" to: "on" - trigger: state id: "t8_stop" entity_id: !input bypass_lights_stop from: "off" to: "on" - trigger: state id: "t9_on" entity_id: !input bypass_lights_on from: "on" to: "off" - trigger: state id: "t9_off" entity_id: !input bypass_lights_off from: "on" to: "off" - trigger: state id: "t9_stop" entity_id: !input bypass_lights_stop from: "on" to: "off" - trigger: state id: "t10" entity_id: !input night_lights_entity_state from: "off" to: "on" - trigger: time id: "t11" at: !input night_lights_after_time - trigger: numeric_state id: "t12" entity_id: sun.sun attribute: elevation below: !input night_lights_sun_elevation - trigger: state id: "t13" entity_id: !input night_lights_entity_state from: "on" to: "off" - trigger: time id: "t14" at: !input night_lights_before_time - trigger: numeric_state id: "t15" entity_id: sun.sun attribute: elevation above: !input night_lights_sun_elevation_rising - trigger: state id: "t16" entity_id: !input dynamic_lighting_state_control_entity to: !input dynamic_lighting_state_control_activation_state - trigger: state id: "t17" entity_id: !input dynamic_lighting_state_control_entity from: !input dynamic_lighting_state_control_activation_state - trigger: state id: "t18" entity_id: !input button_input - trigger: state id: "t19" entity_id: !input button_input - trigger: homeassistant id: "t20" event: start # All Conditions condition: #Trigger conditions - condition: or conditions: - condition: and # trigger by entity on state conditions: - "{{ 'entity_on' in include_entity_state }}" - condition: trigger id: 't0' - condition: state entity_id: !input entity_input match: any state: 'on' - condition: and # trigger by entity off state conditions: - "{{ 'entity_off' in include_entity_state }}" - condition: trigger id: 't1' - condition: state entity_id: !input entity_input match: any state: 'off' - condition: and # trigger by sun falling conditions: - "{{ 'sun_falling' in include_sun }}" - condition: trigger id: 't2' - condition: and # trigger by sun rising conditions: - "{{ 'sun_rising' in include_sun }}" - condition: trigger id: 't3' - condition: and # trigger by ambient low LUX - ON conditions: - "{{ 'ambient_low' in include_ambient }}" - condition: trigger id: 't4' - condition: and # trigger by ambient high LUX - OFF conditions: - "{{ 'ambient_high' in include_ambient }}" - condition: trigger id: 't5' - condition: and # trigger by time ON conditions: - "{{ 'time_on' in include_time }}" - condition: trigger id: 't6' - condition: and # trigger by time OFF conditions: - "{{ 'time_off' in include_time }}" - condition: trigger id: 't7' - condition: and # trigger by by-pass turning on conditions: - condition: trigger id: 't8_on' - "{{ 'bypass_enabled_turn_on' in include_bypass }}" - condition: and # trigger by by-pass turning off conditions: - condition: trigger id: 't8_off' - "{{ 'bypass_enabled_turn_off' in include_bypass }}" - condition: and # trigger by by-pass stop conditions: - condition: trigger id: 't8_stop' - "{{ 'bypass_enabled_stop' in include_bypass }}" - condition: and # trigger by by-pass turning on conditions: - condition: trigger id: 't9_on' - "{{ 'bypass_enabled_turn_on' in include_bypass }}" - condition: and # trigger by by-pass turning off conditions: - condition: trigger id: 't9_off' - "{{ 'bypass_enabled_turn_off' in include_bypass }}" - condition: and # trigger by by-pass stop conditions: - condition: trigger id: 't9_stop' - "{{ 'bypass_enabled_stop' in include_bypass }}" - condition: and # trigger by the start of night light entity state & check if any lights are on 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 != [] %} {{ is_state(boolean_scenes_scripts, 'on') }} {% endif %} - condition: template value_template: >- {% if night_boolean_scenes_scripts != [] %} {{ is_state(night_boolean_scenes_scripts, 'on') }} {% endif %} - condition: template value_template: >- {% if dynamic_lighting_boolean != [] %} {{ is_state(dynamic_lighting_boolean, 'on') }} {% endif %} - condition: and # trigger by the start of night lights time & check if any lights are on 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 != [] %} {{ is_state(boolean_scenes_scripts, 'on') }} {% endif %} - condition: template value_template: >- {% if night_boolean_scenes_scripts != [] %} {{ is_state(night_boolean_scenes_scripts, 'on') }} {% endif %} - condition: template value_template: >- {% if dynamic_lighting_boolean != [] %} {{ is_state(dynamic_lighting_boolean, 'on') }} {% endif %} - condition: and # trigger by the start of night lights sun elevation & check if any lights are on 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 != [] %} {{ is_state(boolean_scenes_scripts, 'on') }} {% endif %} - condition: template value_template: >- {% if night_boolean_scenes_scripts != [] %} {{ is_state(night_boolean_scenes_scripts, 'on') }} {% endif %} - condition: template value_template: >- {% if dynamic_lighting_boolean != [] %} {{ is_state(dynamic_lighting_boolean, 'on') }} {% endif %} - condition: and # trigger by the end of night lights entity state & check if any lights are on 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 != [] %} {{ is_state(boolean_scenes_scripts, 'on') }} {% endif %} - condition: template value_template: >- {% if night_boolean_scenes_scripts != [] %} {{ is_state(night_boolean_scenes_scripts, 'on') }} {% endif %} - condition: template value_template: >- {% if dynamic_lighting_boolean != [] %} {{ is_state(dynamic_lighting_boolean, 'on') }} {% endif %} - condition: and # trigger by the end of night lights time & check if any lights are on 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 != [] %} {{ is_state(boolean_scenes_scripts, 'on') }} {% endif %} - condition: template value_template: >- {% if night_boolean_scenes_scripts != [] %} {{ is_state(night_boolean_scenes_scripts, 'on') }} {% endif %} - condition: template value_template: >- {% if dynamic_lighting_boolean != [] %} {{ is_state(dynamic_lighting_boolean, 'on') }} {% endif %} - condition: and # trigger by the end of night lights sun elevation & check if any lights are on 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 != [] %} {{ is_state(boolean_scenes_scripts, 'on') }} {% endif %} - condition: template value_template: >- {% if night_boolean_scenes_scripts != [] %} {{ is_state(night_boolean_scenes_scripts, 'on') }} {% endif %} - condition: template value_template: >- {% if dynamic_lighting_boolean != [] %} {{ is_state(dynamic_lighting_boolean, 'on') }} {% endif %} - condition: and # trigger by dynamic lighting state control and check in any normal lights are on conditions: - condition: trigger id: - 't16' - 't17' - condition: template value_template: "{{ include_dynamic_lighting != 'disable_dynamic_lighting' }}" - condition: template value_template: "{{ dynamic_lighting_state_control == 'enable_state_control' }}" - condition: or conditions: - "{{ (expand(light_switch.entity_id) | selectattr('state', '==', 'on') | list | count > 0) }}" - condition: template value_template: >- {% if dynamic_lighting_boolean != [] %} {{ is_state(dynamic_lighting_boolean, 'on') }} {% endif %} - condition: and # trigger by push button conditions: - condition: template value_template: "{{ 'button_on' in include_button }}" - condition: trigger id: 't18' - condition: or conditions: - condition: and # Normal Lights conditions: - condition: template value_template: > {% if (expand(light_switch.entity_id) | selectattr('domain', 'in', ['light','switch']) | list | count > 0) %} {{ expand(light_switch.entity_id) | selectattr('state', '==', 'on') | list | count == 0 }} {% else %} true {% endif %} - condition: template value_template: >- {% if boolean_scenes_scripts != [] %} {{ is_state(boolean_scenes_scripts, 'off') }} {% else %} true {% endif %} - condition: template value_template: > {% set entity_ok = ('entity_state_enabled' in night_lights_conditions) and (expand(night_lights_entity_state) | selectattr('state','equalto','on') | list | count > 0) %} {% set time_ok = ('time_enabled' in night_lights_conditions) and (now().strftime('%H:%M:%S') >= night_lights_after_time and now().strftime('%H:%M:%S') <= night_lights_before_time) %} {% set sun_ok = ('sun_enabled' in night_lights_conditions) and ( (not is_state_attr('sun.sun','rising', true) 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)) ) %} {% if include_night_lights == 'night_lights_enabled' %} {{ not (entity_ok or time_ok or sun_ok) }} {% else %} true {% endif %} - condition: and # Dynamic Lighting conditions: - condition: template value_template: "{{ include_dynamic_lighting != 'disable_dynamic_lighting' }}" - condition: template value_template: >- {% if dynamic_lighting_boolean != [] %} {{ is_state(dynamic_lighting_boolean, 'off') }} {% else %} true {% endif %} - condition: and # Night Lights conditions: - alias: "Check if night lights is enabled" condition: template value_template: "{{ include_night_lights == 'night_lights_enabled' }}" - condition: template value_template: > {% if (expand(night_lights.entity_id) | selectattr('domain', 'in', ['light','switch']) | list | count > 0) %} {{ expand(night_lights.entity_id) | selectattr('state', '==', 'on') | list | count == 0 }} {% else %} true {% endif %} - condition: template value_template: >- {% if night_boolean_scenes_scripts != [] %} {{ is_state(night_boolean_scenes_scripts, 'off') }} {% else %} true {% endif %} - condition: template value_template: > {% set entity_ok = ('entity_state_enabled' in night_lights_conditions) and (expand(night_lights_entity_state) | selectattr('state','equalto','on') | list | count > 0) %} {% set time_ok = ('time_enabled' in night_lights_conditions) and (now().strftime('%H:%M:%S') >= night_lights_after_time and now().strftime('%H:%M:%S') <= night_lights_before_time) %} {% set sun_ok = ('sun_enabled' in night_lights_conditions) and ( (not is_state_attr('sun.sun','rising', true) 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)) ) %} {% if include_night_lights == 'night_lights_enabled' %} {{ (entity_ok or time_ok or sun_ok) }} {% else %} false {% endif %} - condition: and # trigger by push button conditions: - condition: template value_template: "{{ 'button_off' in include_button }}" - condition: trigger id: 't19' - condition: or conditions: - condition: and # Normal Lights conditions: - condition: template value_template: > {% if (expand(light_switch.entity_id) | selectattr('domain', 'in', ['light','switch']) | list | count > 0) %} {{ expand(light_switch.entity_id) | selectattr('state', '==', 'on') | list | count > 0 }} {% else %} true {% endif %} - condition: template value_template: >- {% if boolean_scenes_scripts != [] %} {{ is_state(boolean_scenes_scripts, 'on') }} {% else %} true {% endif %} - condition: template value_template: > {% set entity_ok = ('entity_state_enabled' in night_lights_conditions) and (expand(night_lights_entity_state) | selectattr('state','equalto','on') | list | count > 0) %} {% set time_ok = ('time_enabled' in night_lights_conditions) and (now().strftime('%H:%M:%S') >= night_lights_after_time and now().strftime('%H:%M:%S') <= night_lights_before_time) %} {% set sun_ok = ('sun_enabled' in night_lights_conditions) and ( (not is_state_attr('sun.sun','rising', true) 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)) ) %} {% if include_night_lights == 'night_lights_enabled' %} {{ not (entity_ok or time_ok or sun_ok) }} {% else %} true {% endif %} - condition: and # Dynamic Lighting conditions: - condition: template value_template: "{{ include_dynamic_lighting != 'disable_dynamic_lighting' }}" - condition: template value_template: >- {% if dynamic_lighting_boolean != [] %} {{ is_state(dynamic_lighting_boolean, 'on') }} {% else %} true {% endif %} - condition: and # Night Lights conditions: - alias: "Check if night lights is enabled" condition: template value_template: "{{ include_night_lights == 'night_lights_enabled' }}" - condition: template value_template: > {% if (expand(night_lights.entity_id) | selectattr('domain', 'in', ['light','switch']) | list | count > 0) %} {{ expand(night_lights.entity_id) | selectattr('state', '==', 'on') | list | count > 0 }} {% else %} true {% endif %} - condition: template value_template: >- {% if night_boolean_scenes_scripts != [] %} {{ is_state(night_boolean_scenes_scripts, 'on') }} {% else %} true {% endif %} - condition: template value_template: > {% set entity_ok = ('entity_state_enabled' in night_lights_conditions) and (expand(night_lights_entity_state) | selectattr('state','equalto','on') | list | count > 0) %} {% set time_ok = ('time_enabled' in night_lights_conditions) and (now().strftime('%H:%M:%S') >= night_lights_after_time and now().strftime('%H:%M:%S') <= night_lights_before_time) %} {% set sun_ok = ('sun_enabled' in night_lights_conditions) and ( (not is_state_attr('sun.sun','rising', true) 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)) ) %} {% if include_night_lights == 'night_lights_enabled' %} {{ (entity_ok or time_ok or sun_ok) }} {% else %} false {% endif %} - condition: and # trigger by HA Restart & check if any triggers are on conditions: - condition: trigger id: 't20' - condition: template value_template: "{{ include_ha_restart == 'enable_ha_restart' }}" - condition: template value_template: "{{ trigger_options_on }}" - condition: and # trigger by HA Restart & check if any lights are on conditions: - condition: trigger id: 't20' - condition: template value_template: "{{ include_ha_restart == 'enable_ha_restart' }}" - 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 != [] %} {{ is_state(boolean_scenes_scripts, 'on') }} {% endif %} - condition: template value_template: >- {% if night_boolean_scenes_scripts != [] %} {{ is_state(night_boolean_scenes_scripts, 'on') }} {% endif %} - condition: template value_template: >- {% if dynamic_lighting_boolean != [] %} {{ is_state(dynamic_lighting_boolean, 'on') }} {% endif %} - condition: and # trigger by HA Restart & check if by-pass auto off is enabled and any by-passes are on 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: 't20' - condition: template value_template: "{{ include_ha_restart == 'enable_ha_restart' }}" - 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' # Check Motion Sensor Manual By-pass - 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' - 't20' # Check The Weekday Option - condition: or conditions: - "{{ include_weekdays == 'weekday_disabled' }}" - 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: template value_template: "{{ include_night_lights == 'night_lights_enabled' }}" - 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: "Dynamic Lighting - Check if Input Boolean Helper is ON" conditions: - condition: template value_template: "{{ include_dynamic_lighting != 'disable_dynamic_lighting' }}" - condition: template value_template: >- {% if dynamic_lighting_boolean != [] %} {{ is_state(dynamic_lighting_boolean, 'on') }} {% endif %} sequence: - alias: "Turn off the boolean for dynamic lighting" action: input_boolean.turn_off data: entity_id: !input dynamic_lighting_boolean - 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" action: light.turn_off target: entity_id: "{{ night_light_entities }}" data: transition: "{{ night_light_transition_off }}" - alias: "Turn off the scenes" action: 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" action: light.turn_off target: entity_id: "{{ night_light_entities }}" - alias: "Turn off the scenes" action: scene.turn_on data: entity_id: "{{ end_scene_entities }}" - alias: "Turn off the switches" action: switch.turn_off target: entity_id: "{{ night_switch_entities }}" - alias: "Turn off the script" action: script.turn_on data: entity_id: "{{ end_script_entities }}" - alias: "Turn off the boolean for scenes and scripts" action: input_boolean.turn_off data: entity_id: !input boolean_scenes_scripts - alias: "Turn off the boolean for scenes and scripts" action: 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" action: 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" action: 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" action: 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" action: 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" action: 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" action: 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: template value_template: "{{ trigger_options_off }}" 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" action: light.turn_off target: entity_id: "{{ night_light_entities }}" data: transition: "{{ night_light_transition_off }}" - alias: "Turn off the scenes" action: 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" action: light.turn_off target: entity_id: "{{ night_light_entities }}" - alias: "Turn off the scenes" action: scene.turn_on data: entity_id: "{{ end_scene_entities }}" - alias: "Turn off the switches" action: switch.turn_off target: entity_id: "{{ night_switch_entities }}" - alias: "Turn off the script" action: script.turn_on data: entity_id: "{{ end_script_entities }}" - alias: "Turn off the boolean for scenes and scripts" action: input_boolean.turn_off data: entity_id: !input boolean_scenes_scripts - alias: "Turn off the boolean for scenes and scripts" action: 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" action: 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" action: 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" action: 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: template value_template: "{{ trigger_options_on }}" 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" action: light.turn_off target: entity_id: "{{ night_light_entities }}" data: transition: "{{ night_light_transition_off }}" - alias: "Turn off the scenes" action: 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" action: light.turn_off target: entity_id: "{{ night_light_entities }}" - alias: "Turn off the scenes" action: scene.turn_on data: entity_id: "{{ end_scene_entities }}" - alias: "Turn off the switches" action: switch.turn_off target: entity_id: "{{ night_switch_entities }}" - alias: "Turn off the script" action: script.turn_on data: entity_id: "{{ end_script_entities }}" - alias: "Turn off the boolean for scenes and scripts" action: 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: template value_template: "{{ trigger_options_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" action: light.turn_off target: entity_id: "{{ night_light_entities }}" data: transition: "{{ night_light_transition_off }}" - alias: "Turn off the scenes" action: 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" action: light.turn_off target: entity_id: "{{ night_light_entities }}" - alias: "Turn off the scenes" action: scene.turn_on data: entity_id: "{{ end_scene_entities }}" - alias: "Turn off the switches" action: switch.turn_off target: entity_id: "{{ night_switch_entities }}" - alias: "Turn off the script" action: script.turn_on data: entity_id: "{{ end_script_entities }}" - alias: "Turn off the boolean for scenes and scripts" action: 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" action: 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" action: 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" action: homeassistant.turn_off entity_id: !input bypass_lights_stop - stop: "Stop the automation" - alias: "By-pass is turned off & reset lights to the site conditions" conditions: - condition: trigger id: - 't9_on' - 't9_off' - 't9_stop' sequence: - choose: - alias: "If transition is selected" conditions: - condition: template value_template: "{{ 'use_transition' in include_light_control }}" sequence: - alias: "Turn off the lights" action: 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" action: light.turn_off target: entity_id: "{{ crossover_lights_light }}" - alias: "Turn off the switches" action: switch.turn_off target: entity_id: "{{ crossover_lights_switch }}" - choose: - alias: "Check if normal lights Scenes & Scripts - Toggle Helper is on" conditions: - condition: template value_template: >- {% if boolean_scenes_scripts != [] %} {{ is_state(boolean_scenes_scripts, 'on') }} {% endif %} sequence: - choose: - alias: "If transition is selected" conditions: - condition: template value_template: "{{ 'use_transition' in include_light_control }}" sequence: - alias: "Turn off the scenes" action: 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" action: scene.turn_on data: entity_id: "{{ end_scene_entities }}" - alias: "Turn off the script" action: script.turn_on data: entity_id: "{{ end_script_entities }}" - alias: "Turn off the input boolean normal lights" action: input_boolean.turn_off data: entity_id: !input boolean_scenes_scripts - alias: "Turn ON lights" action: light.turn_on target: entity_id: "{{ crossover_night_lights_light_on }}" data: "{{ night_light_data }}" - 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: - 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 != [] %} {{ is_state(boolean_scenes_scripts, 'on') }} {% endif %} sequence: - choose: - alias: "If transition is selected" conditions: - condition: template value_template: "{{ 'use_transition' in include_light_control }}" sequence: - alias: "Turn off the lights" action: 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" action: light.turn_off target: entity_id: "{{ crossover_lights_light }}" - alias: "Turn off the switches" action: switch.turn_off target: entity_id: "{{ crossover_lights_switch }}" - alias: "Turn off the script" action: 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" action: 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" action: scene.turn_on data: entity_id: "{{ end_scene_entities }}" - alias: "Turn off the input boolean normal lights" action: input_boolean.turn_off data: entity_id: !input boolean_scenes_scripts - alias: "Turn ON lights" action: 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" action: script.turn_on data: entity_id: "{{ end_script_entities }}" - stop: "Stop the automation" - alias: "Safe Guard when HA restarts" conditions: - condition: trigger id: 't20' 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 != [] %} {{ is_state(boolean_scenes_scripts, 'on') }} {% endif %} - condition: template value_template: >- {% if night_boolean_scenes_scripts != [] %} {{ is_state(night_boolean_scenes_scripts, 'on') }} {% endif %} - alias: "Check if all triggers are OFF" condition: template value_template: "{{ trigger_options_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 normal lights" action: light.turn_off target: entity_id: "{{ light_entities }}" data: transition: "{{ night_light_transition_off }}" - alias: "Turn off the night lights" action: light.turn_off target: entity_id: "{{ night_light_entities }}" data: transition: "{{ night_light_transition_off }}" - alias: "Turn off the scenes" action: 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" action: light.turn_off target: entity_id: "{{ light_entities }}" - alias: "Turn off the night lights" action: light.turn_off target: entity_id: "{{ night_light_entities }}" - alias: "Turn off the scenes" action: scene.turn_on data: entity_id: "{{ end_scene_entities }}" - alias: "Turn off the normal switches" action: switch.turn_off target: entity_id: "{{ switch_entities }}" - alias: "Turn off the night switches" action: switch.turn_off target: entity_id: "{{ night_switch_entities }}" - alias: "Turn off the script" action: script.turn_on data: entity_id: "{{ end_script_entities }}" - alias: "Turn off the boolean for normal lights scenes and scripts" action: input_boolean.turn_off data: entity_id: !input boolean_scenes_scripts - alias: "Turn off the boolean for night lights scenes and scripts" action: 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" action: 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" action: 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" action: homeassistant.turn_off entity_id: !input bypass_lights_stop - stop: "Stop the automation" - alias: "Check if any lights are ON and any trigger is 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 != [] %} {{ is_state(boolean_scenes_scripts, 'on') }} {% endif %} - condition: template value_template: >- {% if night_boolean_scenes_scripts != [] %} {{ is_state(night_boolean_scenes_scripts, 'on') }} {% endif %} - alias: "Check if all triggers are OFF" condition: template value_template: "{{ trigger_options_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 normal lights" action: light.turn_off target: entity_id: "{{ light_entities }}" data: transition: "{{ night_light_transition_off }}" - alias: "Turn off the night lights" action: light.turn_off target: entity_id: "{{ night_light_entities }}" data: transition: "{{ night_light_transition_off }}" - alias: "Turn off the scenes" action: 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" action: light.turn_off target: entity_id: "{{ light_entities }}" - alias: "Turn off the night lights" action: light.turn_off target: entity_id: "{{ night_light_entities }}" - alias: "Turn off the scenes" action: scene.turn_on data: entity_id: "{{ end_scene_entities }}" - alias: "Turn off the normal switches" action: switch.turn_off target: entity_id: "{{ switch_entities }}" - alias: "Turn off the night switches" action: switch.turn_off target: entity_id: "{{ night_switch_entities }}" - alias: "Turn off the script" action: script.turn_on data: entity_id: "{{ end_script_entities }}" - alias: "Turn off the boolean for normal lights scenes and scripts" action: input_boolean.turn_off data: entity_id: !input boolean_scenes_scripts - alias: "Turn off the boolean for night lights scenes and scripts" action: input_boolean.turn_off data: entity_id: !input night_boolean_scenes_scripts - stop: "Stop the automation" - choose: - conditions: - condition: or conditions: - condition: trigger id: - 't0' - 't2' - 't4' - 't6' - 't8_on' - 't10' - 't11' - 't12' - 't18' - 't20' - 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" action: 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 == [] %} false {% elif is_state(boolean_scenes_scripts, 'on') %} true {% else %} false {% endif %} sequence: - delay: 0 - alias: "If transition is selected" conditions: - condition: template value_template: "{{ 'use_transition' in include_night_light_control }}" sequence: - alias: "Turn on the night scenes" action: scene.turn_on target: entity_id: "{{ night_scene_entities }}" data: transition: "{{ night_light_transition_on }}" - alias: "Turn on the boolean for scenes and scripts" action: 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" action: scene.turn_on target: entity_id: "{{ night_scene_entities }}" - alias: "Turn on the boolean for scenes and scripts" action: input_boolean.turn_on data: entity_id: "{{ night_boolean_scenes_scripts_helper }}" - alias: "Turn on the night switches" action: switch.turn_on target: entity_id: "{{ night_switch_entities_off }}" - alias: "Turn on the night scripts" action: 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" action: 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" action: 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" action: 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' - 't19' 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" action: light.turn_off target: entity_id: "{{ night_light_entities }}" data: transition: "{{ night_light_transition_off }}" - alias: "Turn off the scenes" action: 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" action: light.turn_off target: entity_id: "{{ night_light_entities }}" - alias: "Turn off the scenes" action: scene.turn_on data: entity_id: "{{ end_scene_entities }}" - alias: "Turn off the switches" action: switch.turn_off target: entity_id: "{{ night_switch_entities }}" - alias: "Turn off the script" action: script.turn_on data: entity_id: "{{ end_script_entities }}" - alias: "Turn off the boolean for scenes and scripts" action: 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" action: light.turn_off target: entity_id: "{{ light_entities }}" data: transition: "{{ light_transition_off }}" - alias: "Turn off the scenes" action: 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" action: light.turn_off target: entity_id: "{{ light_entities }}" - alias: "Turn off the scenes" action: scene.turn_on data: entity_id: "{{ end_scene_entities }}" - alias: "Turn off the switches" action: switch.turn_off target: entity_id: "{{ switch_entities }}" - alias: "Turn off the script" action: script.turn_on data: entity_id: "{{ end_script_entities }}" - alias: "Turn off the boolean for scenes and scripts" action: input_boolean.turn_off data: entity_id: !input boolean_scenes_scripts - alias: "Turn off the boolean for scenes and scripts" action: input_boolean.turn_off data: entity_id: !input night_boolean_scenes_scripts - choose: - alias: "Dynamic Lighting - Check if Input Boolean Helper is ON" conditions: - condition: template value_template: "{{ include_dynamic_lighting != 'disable_dynamic_lighting' }}" - condition: template value_template: >- {% if dynamic_lighting_boolean != [] %} {{ is_state(dynamic_lighting_boolean, 'on') }} {% endif %} sequence: - alias: "Turn off the boolean for dynamic lighting" action: input_boolean.turn_off data: entity_id: !input dynamic_lighting_boolean - 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" action: 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" action: 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" action: 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" action: 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" action: 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" action: 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: template value_template: "{{ trigger_options_off }}" 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" action: light.turn_off target: entity_id: "{{ light_entities }}" data: transition: "{{ light_transition_off }}" - alias: "Turn off the scenes" action: 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" action: light.turn_off target: entity_id: "{{ light_entities }}" - alias: "Turn off the scenes" action: scene.turn_on data: entity_id: "{{ end_scene_entities }}" - alias: "Turn off the switches" action: switch.turn_off target: entity_id: "{{ switch_entities }}" - alias: "Turn off the script" action: script.turn_on data: entity_id: "{{ end_script_entities }}" - alias: "Turn off the boolean for scenes and scripts" action: input_boolean.turn_off data: entity_id: !input boolean_scenes_scripts - alias: "Turn off the boolean for scenes and scripts" action: input_boolean.turn_off data: entity_id: !input night_boolean_scenes_scripts - choose: - alias: "Dynamic Lighting - Check if Input Boolean Helper is ON" conditions: - condition: template value_template: "{{ include_dynamic_lighting != 'disable_dynamic_lighting' }}" - condition: template value_template: >- {% if dynamic_lighting_boolean != [] %} {{ is_state(dynamic_lighting_boolean, 'on') }} {% endif %} sequence: - alias: "Turn off the boolean for dynamic lighting" action: input_boolean.turn_off data: entity_id: !input dynamic_lighting_boolean - 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" action: 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" action: 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" action: 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: template value_template: "{{ trigger_options_on }}" 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" action: light.turn_off target: entity_id: "{{ light_entities }}" data: transition: "{{ light_transition_off }}" - alias: "Turn off the scenes" action: 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" action: light.turn_off target: entity_id: "{{ light_entities }}" - alias: "Turn off the scenes" action: scene.turn_on data: entity_id: "{{ end_scene_entities }}" - alias: "Turn off the switches" action: switch.turn_off target: entity_id: "{{ switch_entities }}" - alias: "Turn off the script" action: script.turn_on data: entity_id: "{{ end_script_entities }}" - alias: "Turn off the boolean for scenes and scripts" action: input_boolean.turn_off data: entity_id: !input boolean_scenes_scripts - choose: - alias: "Dynamic Lighting - Check if Input Boolean Helper is ON" conditions: - condition: template value_template: "{{ include_dynamic_lighting != 'disable_dynamic_lighting' }}" - condition: template value_template: >- {% if dynamic_lighting_boolean != [] %} {{ is_state(dynamic_lighting_boolean, 'on') }} {% endif %} sequence: - alias: "Turn off the boolean for dynamic lighting" action: input_boolean.turn_off data: entity_id: !input dynamic_lighting_boolean - 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: template value_template: "{{ trigger_options_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" action: light.turn_off target: entity_id: "{{ light_entities }}" data: transition: "{{ light_transition_off }}" - alias: "Turn off the scenes" action: 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" action: light.turn_off target: entity_id: "{{ light_entities }}" - alias: "Turn off the scenes" action: scene.turn_on data: entity_id: "{{ end_scene_entities }}" - alias: "Turn off the switches" action: switch.turn_off target: entity_id: "{{ switch_entities }}" - alias: "Turn off the script" action: script.turn_on data: entity_id: "{{ end_script_entities }}" - alias: "Turn off the boolean for scenes and scripts" action: input_boolean.turn_off data: entity_id: !input boolean_scenes_scripts - choose: - alias: "Dynamic Lighting - Check if Input Boolean Helper is ON" conditions: - condition: template value_template: "{{ include_dynamic_lighting != 'disable_dynamic_lighting' }}" - condition: template value_template: >- {% if dynamic_lighting_boolean != [] %} {{ is_state(dynamic_lighting_boolean, 'on') }} {% endif %} sequence: - alias: "Turn off the boolean for dynamic lighting" action: input_boolean.turn_off data: entity_id: !input dynamic_lighting_boolean - 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" action: 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" action: 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" action: homeassistant.turn_off entity_id: !input bypass_lights_stop - stop: "Stop the automation" - alias: "By-pass is turned off & reset lights to the site conditions" conditions: - condition: trigger id: - 't9_on' - 't9_off' - 't9_stop' 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" action: 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" action: light.turn_off target: entity_id: "{{ crossover_night_lights_light }}" - alias: "Turn off the switches" action: switch.turn_off target: entity_id: "{{ crossover_night_lights_switch }}" - choose: - alias: "Check if night lights scenes & scripts - toggle helper is on" conditions: - condition: template value_template: >- {% if night_boolean_scenes_scripts != [] %} {{ is_state(night_boolean_scenes_scripts, 'on') }} {% endif %} 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" action: 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" action: scene.turn_on data: entity_id: "{{ end_scene_entities }}" - alias: "Turn off the script" action: script.turn_on data: entity_id: "{{ end_script_entities }}" - alias: "Turn off the input boolean night lights" action: input_boolean.turn_off data: entity_id: !input night_boolean_scenes_scripts - choose: - alias: "Turn ON lights" conditions: - alias: "Check the dynamic lighting options" condition: or conditions: - condition: template value_template: "{{ include_dynamic_lighting == 'disable_dynamic_lighting' }}" - alias: "Check that dynamic lighting is active and the state control option is enabled" condition: and conditions: - condition: template value_template: "{{ include_dynamic_lighting != 'disable_dynamic_lighting' }}" - condition: template value_template: "{{ dynamic_lighting_state_control == 'enable_state_control' }}" - condition: template value_template: "{{ states(dynamic_lighting_state_control_entity) == dynamic_lighting_state_control_activation_state_inv }}" sequence: - action: light.turn_on target: entity_id: "{{ crossover_lights_light_on }}" data: "{{ light_data }}" - choose: - alias: "Dynamic Lighting - Check if Input Boolean Helper is ON" conditions: - condition: template value_template: "{{ include_dynamic_lighting != 'disable_dynamic_lighting' }}" - condition: template value_template: >- {% if dynamic_lighting_boolean != [] %} {{ is_state(dynamic_lighting_boolean, 'on') }} {% endif %} sequence: - alias: "Turn off the boolean for dynamic lighting" action: input_boolean.turn_off data: entity_id: !input dynamic_lighting_boolean - choose: - alias: "Turn off night lights when trigger by end night lights conditions" conditions: - condition: trigger id: - 't13' - 't14' - 't15' sequence: - choose: - alias: "If delay is selected in night lights" conditions: - "{{ 'use_delay' in include_night_light_control }}" sequence: delay: minutes: !input cross_over_time_delay - 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" action: 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" action: light.turn_off target: entity_id: "{{ crossover_night_lights_light }}" - alias: "Turn off the switches" action: switch.turn_off target: entity_id: "{{ crossover_night_lights_switch }}" - alias: "Turn off the script" action: 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" action: 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" action: scene.turn_on data: entity_id: "{{ end_scene_entities }}" - alias: "Turn off the input boolean night lights" action: input_boolean.turn_off data: entity_id: !input night_boolean_scenes_scripts - choose: - alias: "Turn ON lights" conditions: - alias: "Check the dynamic lighting options" condition: or conditions: - condition: template value_template: "{{ include_dynamic_lighting == 'disable_dynamic_lighting' }}" - alias: "Check that dynamic lighting is active and the state control option is enabled" condition: and conditions: - condition: template value_template: "{{ include_dynamic_lighting != 'disable_dynamic_lighting' }}" - condition: template value_template: "{{ dynamic_lighting_state_control == 'enable_state_control' }}" - condition: template value_template: "{{ states(dynamic_lighting_state_control_entity) == dynamic_lighting_state_control_activation_state_inv }}" sequence: - action: 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" action: script.turn_on data: entity_id: "{{ end_script_entities }}" - stop: "Stop the automation" - alias: "Safe Guard when HA restarts" conditions: - condition: trigger id: 't20' 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 != [] %} {{ is_state(boolean_scenes_scripts, 'on') }} {% endif %} - condition: template value_template: >- {% if night_boolean_scenes_scripts != [] %} {{ is_state(night_boolean_scenes_scripts, 'on') }} {% endif %} - alias: "Check if all triggers are OFF" condition: template value_template: "{{ trigger_options_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 normal lights" action: light.turn_off target: entity_id: "{{ light_entities }}" data: transition: "{{ light_transition_off }}" - alias: "Turn off the night lights" action: light.turn_off target: entity_id: "{{ night_light_entities }}" data: transition: "{{ light_transition_off }}" - alias: "Turn off the scenes" action: 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" action: light.turn_off target: entity_id: "{{ light_entities }}" - alias: "Turn off the night lights" action: light.turn_off target: entity_id: "{{ night_light_entities }}" - alias: "Turn off the scenes" action: scene.turn_on data: entity_id: "{{ end_scene_entities }}" - alias: "Turn off the normal switches" action: switch.turn_off target: entity_id: "{{ switch_entities }}" - alias: "Turn off the night switches" action: switch.turn_off target: entity_id: "{{ night_switch_entities }}" - alias: "Turn off the script" action: script.turn_on data: entity_id: "{{ end_script_entities }}" - alias: "Turn off the boolean for normal lights scenes and scripts" action: input_boolean.turn_off data: entity_id: !input boolean_scenes_scripts - alias: "Turn off the boolean for night lights scenes and scripts" action: input_boolean.turn_off data: entity_id: !input night_boolean_scenes_scripts - choose: - alias: "Dynamic Lighting - Check if Input Boolean Helper is ON" conditions: - condition: template value_template: "{{ include_dynamic_lighting != 'disable_dynamic_lighting' }}" - condition: template value_template: >- {% if dynamic_lighting_boolean != [] %} {{ is_state(dynamic_lighting_boolean, 'on') }} {% endif %} sequence: - alias: "Turn off the boolean for dynamic lighting" action: input_boolean.turn_off data: entity_id: !input dynamic_lighting_boolean - 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" action: 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" action: 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" action: homeassistant.turn_off entity_id: !input bypass_lights_stop - stop: "Stop the automation" - alias: "Check if any lights are ON and any trigger is 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 != [] %} {{ is_state(boolean_scenes_scripts, 'on') }} {% endif %} - condition: template value_template: >- {% if night_boolean_scenes_scripts != [] %} {{ is_state(night_boolean_scenes_scripts, 'on') }} {% endif %} - alias: "Check if all triggers are OFF" condition: template value_template: "{{ trigger_options_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 normal lights" action: light.turn_off target: entity_id: "{{ light_entities }}" data: transition: "{{ light_transition_off }}" - alias: "Turn off the night lights" action: light.turn_off target: entity_id: "{{ night_light_entities }}" data: transition: "{{ light_transition_off }}" - alias: "Turn off the scenes" action: 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" action: light.turn_off target: entity_id: "{{ light_entities }}" - alias: "Turn off the night lights" action: light.turn_off target: entity_id: "{{ night_light_entities }}" - alias: "Turn off the scenes" action: scene.turn_on data: entity_id: "{{ end_scene_entities }}" - alias: "Turn off the normal switches" action: switch.turn_off target: entity_id: "{{ switch_entities }}" - alias: "Turn off the night switches" action: switch.turn_off target: entity_id: "{{ night_switch_entities }}" - alias: "Turn off the script" action: script.turn_on data: entity_id: "{{ end_script_entities }}" - alias: "Turn off the boolean for normal lights scenes and scripts" action: input_boolean.turn_off data: entity_id: !input boolean_scenes_scripts - alias: "Turn off the boolean for night lights scenes and scripts" action: input_boolean.turn_off data: entity_id: !input night_boolean_scenes_scripts - choose: - alias: "Dynamic Lighting - Check if Input Boolean Helper is ON" conditions: - condition: template value_template: "{{ include_dynamic_lighting != 'disable_dynamic_lighting' }}" - condition: template value_template: >- {% if dynamic_lighting_boolean != [] %} {{ is_state(dynamic_lighting_boolean, 'on') }} {% endif %} sequence: - alias: "Turn off the boolean for dynamic lighting" action: input_boolean.turn_off data: entity_id: !input dynamic_lighting_boolean - stop: "Stop the automation" - choose: - conditions: - condition: or conditions: - condition: trigger id: - 't0' - 't2' - 't4' - 't6' - 't8_on' - 't13' - 't14' - 't15' - 't16' - 't17' - 't18' - 't20' - 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' }}" - alias: "Check the dynamic lighting state control option" condition: or conditions: - condition: template value_template: "{{ dynamic_lighting_state_control == 'disable_state_control' }}" - alias: "Check if the dynamic lighting state control option is enabled" condition: and conditions: - condition: template value_template: "{{ dynamic_lighting_state_control == 'enable_state_control' }}" - condition: state entity_id: !input dynamic_lighting_state_control_entity state: !input dynamic_lighting_state_control_activation_state - choose: - alias: "Dynamic Lighting - Input Boolean Helper" conditions: - condition: template value_template: "{{ dynamic_lighting_boolean != [] }}" sequence: - alias: "Turn on the boolean for dynamic lighting" action: 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 %} {% set bv = dynamic_lighting_max_brightness %} {% elif lux >= dynamic_lighting_max_lux %} {% set bv = dynamic_lighting_min_brightness %} {% else %} {% set bv = ((slope * lux) + ak) | round(1) %} {% endif %} {% if lp <= 0 %} {% set bv = bv %} {% elif (bv > lp) and (dynamic_lighting_max_brightness - lp) <= dynamic_lighting_dead_zone %} {% set bv = dynamic_lighting_max_brightness %} {% elif (lp > bv) and (lp - dynamic_lighting_min_brightness) <= dynamic_lighting_dead_zone %} {% set bv = dynamic_lighting_min_brightness %} {% elif (bv > lp) and (bv - lp) <= dynamic_lighting_dead_zone %} {% set bv = lp %} {% elif (lp > bv) and (lp - bv) <= dynamic_lighting_dead_zone %} {% set bv = lp %} {% elif bv > (lp + dynamic_lighting_step_value) %} {% set bv = lp + dynamic_lighting_step_value %} {% elif bv < (lp - dynamic_lighting_step_value) %} {% set bv = lp - dynamic_lighting_step_value %} {% endif %} {{ bv | round(0) }} 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 %} {% set light.data = dict(light.data, **{ 'transition': light_transition_on }) %} {% endif %} {% if include_light_colour_control == 'use_colour_temperature' %} {% set light.data = dict(light.data, **{ 'color_temp_kelvin': light_colour_temperature }) %} {% endif %} {% if include_light_colour_control == 'use_rgb_colour' %} {% set light.data = dict(light.data, **{ 'rgb_color': light_rgb_colour }) %} {% endif %} {% if include_light_colour_control == 'use_rgbw_colour' %} {% set light.data = dict(light.data, **{ 'rgbw_color': light_rgbw_colour }) %} {% endif %} {% if include_light_colour_control == 'use_rgbww_colour' %} {% set light.data = dict(light.data, **{ 'rgbww_color': light_rgbww_colour }) %} {% endif %} {{ light.data }} 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 %} {% set bv = dynamic_lighting_max_brightness %} {% elif lux >= dynamic_lighting_max_lux %} {% set bv = dynamic_lighting_min_brightness %} {% else %} {% set bv = ((slope * lux) + ak) | round(1) %} {% endif %} {% if (bv > lp) and (dynamic_lighting_max_brightness - lp) <= dynamic_lighting_dead_zone %} false {% elif (lp > bv) and (lp - dynamic_lighting_min_brightness) <= dynamic_lighting_dead_zone %} false {% elif (bv >= lp) and (bv - lp) <= dynamic_lighting_dead_zone %} true {% elif (lp >= bv) and (lp - bv) <= dynamic_lighting_dead_zone %} true {% else %} false {% endif %} - 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' - condition: template value_template: "{{ repeat.index == 1 }}" 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' - condition: template value_template: "{{ repeat.index == 1 }}" sequence: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Dynamic lighting heartbeat" delay: minutes: !input dynamic_lighting_heartbeat - alias: "Adjust the light settings when all bypasses are off or state control is enabled, and the entity is turned ON" conditions: - condition: trigger id: - 't16' - 't9_on' - 't9_off' - 't9_stop' - condition: template value_template: "{{ repeat.index == 1 }}" sequence: - action: 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: - condition: template value_template: "{{ in_dead_zone }}" - condition: template value_template: "{{ repeat.index != 1 }}" 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: - action: 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 %} {% set bv = dynamic_lighting_min_brightness %} {% elif lux >= dynamic_lighting_max_lux %} {% set bv = dynamic_lighting_max_brightness %} {% else %} {% set bv = ((slope * lux) + ak) | round(1) %} {% endif %} {% if lp <= 0 %} {% set bv = bv %} {% elif (bv > lp) and (dynamic_lighting_max_brightness - lp) <= dynamic_lighting_dead_zone %} {% set bv = dynamic_lighting_max_brightness %} {% elif (lp > bv) and (lp - dynamic_lighting_min_brightness) <= dynamic_lighting_dead_zone %} {% set bv = dynamic_lighting_min_brightness %} {% elif (bv > lp) and (bv - lp) <= dynamic_lighting_dead_zone %} {% set bv = lp %} {% elif (lp > bv) and (lp - bv) <= dynamic_lighting_dead_zone %} {% set bv = lp %} {% elif bv > (lp + dynamic_lighting_step_value) %} {% set bv = lp + dynamic_lighting_step_value %} {% elif bv < (lp - dynamic_lighting_step_value) %} {% set bv = lp - dynamic_lighting_step_value %} {% endif %} {{ bv | round(0) }} 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 %} {% set light.data = dict(light.data, **{ 'transition': light_transition_on }) %} {% endif %} {% if include_light_colour_control == 'use_colour_temperature' %} {% set light.data = dict(light.data, **{ 'color_temp_kelvin': light_colour_temperature }) %} {% endif %} {% if include_light_colour_control == 'use_rgb_colour' %} {% set light.data = dict(light.data, **{ 'rgb_color': light_rgb_colour }) %} {% endif %} {% if include_light_colour_control == 'use_rgbw_colour' %} {% set light.data = dict(light.data, **{ 'rgbw_color': light_rgbw_colour }) %} {% endif %} {% if include_light_colour_control == 'use_rgbww_colour' %} {% set light.data = dict(light.data, **{ 'rgbww_color': light_rgbww_colour }) %} {% endif %} {{ light.data }} 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 %} {% set bv = dynamic_lighting_min_brightness %} {% elif lux >= dynamic_lighting_max_lux %} {% set bv = dynamic_lighting_max_brightness %} {% else %} {% set bv = ((slope * lux) + ak) | round(1) %} {% endif %} {% if (bv > lp) and (dynamic_lighting_max_brightness - lp) <= dynamic_lighting_dead_zone %} true {% elif (lp > bv) and (lp - dynamic_lighting_min_brightness) <= dynamic_lighting_dead_zone %} false {% elif (bv >= lp) and (bv - lp) <= dynamic_lighting_dead_zone %} true {% elif (lp >= bv) and (lp - bv) <= dynamic_lighting_dead_zone %} true {% else %} false {% endif %} - 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' - condition: template value_template: "{{ repeat.index == 1 }}" 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' - condition: template value_template: "{{ repeat.index == 1 }}" sequence: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Dynamic lighting heartbeat" delay: minutes: !input dynamic_lighting_heartbeat - alias: "Adjust the light settings when all bypasses are off or state control is enabled, and the entity is turned ON" conditions: - condition: trigger id: - 't16' - 't9_on' - 't9_off' - 't9_stop' - condition: template value_template: "{{ repeat.index == 1 }}" sequence: - action: 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: - condition: template value_template: "{{ in_dead_zone }}" - condition: template value_template: "{{ repeat.index != 1 }}" 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: - action: 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_elevation_cutoff: > {% if is_state_attr('sun.sun', 'rising', true) %} {{ dynamic_lighting_sun_elevation_start_rising }} {% else %} {{ dynamic_lighting_sun_elevation_end_falling }} {% endif %} 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 >= dynamic_elevation_cutoff %} {% if elevation >= dynamic_lighting_sun_elevation_start_rising and elevation <= dynamic_lighting_sun_elevation_end_rising and is_state_attr('sun.sun', 'rising', true) %} {% set colour_temp_value = ((start_slope * elevation) + start_ak) | round(1) %} {% elif elevation <= dynamic_lighting_sun_elevation_start_falling and elevation >= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set colour_temp_value = ((end_slope * elevation) + end_ak) | round(1) %} {% elif elevation >= dynamic_lighting_sun_elevation_end_rising and elevation >= dynamic_lighting_sun_elevation_start_falling %} {% set colour_temp_value = dynamic_lighting_max_colour_temp %} {% elif elevation <= dynamic_lighting_sun_elevation_start_rising and is_state_attr('sun.sun', 'rising', true) %} {% set colour_temp_value = dynamic_lighting_min_colour_temp %} {% elif elevation <= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set colour_temp_value = dynamic_lighting_min_colour_temp %} {% else %} {% set colour_temp_value = dynamic_lighting_max_colour_temp %} {% endif %} {% else %} {% set colour_temp_value = dynamic_lighting_min_colour_temp %} {% endif %} {{ colour_temp_value | round(0) }} 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 %} {% set light.data = dict(light.data, **{ 'transition': light_transition_on }) %} {% endif %} {% if 'use_brightness' in include_light_control %} {% set light.data = dict(light.data, **{ 'brightness_pct': light_brightness }) %} {% endif %} {{ light.data }} should_wait: > {% set elevation = state_attr('sun.sun', 'elevation') | float %} {% if expand(light_entities) | selectattr('state', '==', 'on') | list | count > 0 %} {% 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) %} false {% 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) %} false {% elif elevation >= (dynamic_lighting_sun_elevation_end_rising + 2) and elevation >= (dynamic_lighting_sun_elevation_start_falling - 2) %} true {% elif elevation <= (dynamic_lighting_sun_elevation_start_rising - 2) and is_state_attr('sun.sun', 'rising', true) %} true {% elif elevation <= (dynamic_lighting_sun_elevation_end_falling - 2) and is_state_attr('sun.sun', 'rising', false) %} true {% else %} true {% endif %} {% else %} false {% endif %} - 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: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Wait for sun elevation to change" wait_for_trigger: - trigger: state entity_id: sun.sun attribute: elevation - alias: "Adjust the light settings when all bypasses are off or state control is enabled, and the entity is turned ON" conditions: - condition: trigger id: - 't16' - 't9_on' - 't9_off' - 't9_stop' - condition: template value_template: "{{ repeat.index == 1 }}" sequence: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Wait for sun elevation to change" wait_for_trigger: - trigger: 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: - trigger: 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: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Wait for sun elevation to change" wait_for_trigger: - trigger: 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_elevation_cutoff: > {% if is_state_attr('sun.sun', 'rising', true) %} {{ dynamic_lighting_sun_elevation_start_rising }} {% else %} {{ dynamic_lighting_sun_elevation_end_falling }} {% endif %} 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 >= dynamic_elevation_cutoff %} {% if elevation >= dynamic_lighting_sun_elevation_start_rising and elevation <= dynamic_lighting_sun_elevation_end_rising and is_state_attr('sun.sun', 'rising', true) %} {% set brightness_value = ((start_slope * elevation) + start_ak) | round(1) %} {% elif elevation <= dynamic_lighting_sun_elevation_start_falling and elevation >= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set brightness_value = ((end_slope * elevation) + end_ak) | round(1) %} {% elif elevation >= dynamic_lighting_sun_elevation_end_rising and elevation >= dynamic_lighting_sun_elevation_start_falling %} {% set brightness_value = dynamic_lighting_max_brightness %} {% elif elevation <= dynamic_lighting_sun_elevation_start_rising and is_state_attr('sun.sun', 'rising', true) %} {% set brightness_value = dynamic_lighting_min_brightness %} {% elif elevation <= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set brightness_value = dynamic_lighting_min_brightness %} {% else %} {% set brightness_value = dynamic_lighting_max_brightness %} {% endif %} {% else %} {% set brightness_value = dynamic_lighting_min_brightness %} {% endif %} {{ brightness_value | round(0) }} 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 %} {% set light.data = dict(light.data, **{ 'transition': light_transition_on }) %} {% endif %} {% if include_light_colour_control == 'use_colour_temperature' %} {% set light.data = dict(light.data, **{ 'color_temp_kelvin': light_colour_temperature }) %} {% endif %} {% if include_light_colour_control == 'use_rgb_colour' %} {% set light.data = dict(light.data, **{ 'rgb_color': light_rgb_colour }) %} {% endif %} {% if include_light_colour_control == 'use_rgbw_colour' %} {% set light.data = dict(light.data, **{ 'rgbw_color': light_rgbw_colour }) %} {% endif %} {% if include_light_colour_control == 'use_rgbww_colour' %} {% set light.data = dict(light.data, **{ 'rgbww_color': light_rgbww_colour }) %} {% endif %} {{ light.data }} 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 >= dynamic_elevation_cutoff %} {% if elevation >= dynamic_lighting_sun_elevation_start_rising and elevation <= dynamic_lighting_sun_elevation_end_rising and is_state_attr('sun.sun', 'rising', true) %} {% set brightness_value = ((start_slope * elevation) + start_ak) | round(1) %} {% elif elevation <= dynamic_lighting_sun_elevation_start_falling and elevation >= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set brightness_value = ((end_slope * elevation) + end_ak) | round(1) %} {% elif elevation >= dynamic_lighting_sun_elevation_end_rising and elevation >= dynamic_lighting_sun_elevation_start_falling %} {% set brightness_value = dynamic_lighting_max_brightness %} {% elif elevation <= dynamic_lighting_sun_elevation_start_rising and is_state_attr('sun.sun', 'rising', true) %} {% set brightness_value = dynamic_lighting_min_brightness %} {% elif elevation <= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set brightness_value = dynamic_lighting_min_brightness %} {% else %} {% set brightness_value = dynamic_lighting_max_brightness %} {% endif %} {% else %} {% set brightness_value = dynamic_lighting_min_brightness %} {% endif %} {% if expand(light_entities) | selectattr('state', '==', 'on') | list | count > 0 %} {% if (brightness_value >= (lp * 0.99) and brightness_value <= (lp * 1.01)) %} true {% else %} false {% endif %} {% else %} false {% endif %} - 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: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Wait for sun elevation to change" wait_for_trigger: - trigger: state entity_id: sun.sun attribute: elevation - alias: "Adjust the light settings when all bypasses are off or state control is enabled, and the entity is turned ON" conditions: - condition: trigger id: - 't16' - 't9_on' - 't9_off' - 't9_stop' - condition: template value_template: "{{ repeat.index == 1 }}" sequence: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Wait for sun elevation to change" wait_for_trigger: - trigger: 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: - trigger: 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: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Wait for sun elevation to change" wait_for_trigger: - trigger: 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_elevation_cutoff: > {% if is_state_attr('sun.sun', 'rising', true) %} {{ dynamic_lighting_sun_elevation_start_rising }} {% else %} {{ dynamic_lighting_sun_elevation_end_falling }} {% endif %} 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 > dynamic_elevation_cutoff %} {% if elevation >= dynamic_lighting_sun_elevation_start_rising and elevation <= dynamic_lighting_sun_elevation_end_rising and is_state_attr('sun.sun', 'rising', true) %} {% set brightness_value = ((start_slope * elevation) + start_ak) | round(1) %} {% elif elevation <= dynamic_lighting_sun_elevation_start_falling and elevation >= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set brightness_value = ((end_slope * elevation) + end_ak) | round(1) %} {% elif elevation >= dynamic_lighting_sun_elevation_end_rising and elevation >= dynamic_lighting_sun_elevation_start_falling %} {% set brightness_value = dynamic_lighting_min_brightness %} {% elif elevation <= dynamic_lighting_sun_elevation_start_rising and is_state_attr('sun.sun', 'rising', true) %} {% set brightness_value = dynamic_lighting_max_brightness %} {% elif elevation <= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set brightness_value = dynamic_lighting_max_brightness %} {% else %} {% set brightness_value = dynamic_lighting_min_brightness %} {% endif %} {% else %} {% set brightness_value = dynamic_lighting_max_brightness %} {% endif %} {{ brightness_value | round(0) }} 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 %} {% set light.data = dict(light.data, **{ 'transition': light_transition_on }) %} {% endif %} {% if include_light_colour_control == 'use_colour_temperature' %} {% set light.data = dict(light.data, **{ 'color_temp_kelvin': light_colour_temperature }) %} {% endif %} {% if include_light_colour_control == 'use_rgb_colour' %} {% set light.data = dict(light.data, **{ 'rgb_color': light_rgb_colour }) %} {% endif %} {% if include_light_colour_control == 'use_rgbw_colour' %} {% set light.data = dict(light.data, **{ 'rgbw_color': light_rgbw_colour }) %} {% endif %} {% if include_light_colour_control == 'use_rgbww_colour' %} {% set light.data = dict(light.data, **{ 'rgbww_color': light_rgbww_colour }) %} {% endif %} {{ light.data }} 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 > dynamic_elevation_cutoff %} {% if elevation >= dynamic_lighting_sun_elevation_start_rising and elevation <= dynamic_lighting_sun_elevation_end_rising and is_state_attr('sun.sun', 'rising', true) %} {% set brightness_value = ((start_slope * elevation) + start_ak) | round(1) %} {% elif elevation <= dynamic_lighting_sun_elevation_start_falling and elevation >= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set brightness_value = ((end_slope * elevation) + end_ak) | round(1) %} {% elif elevation >= dynamic_lighting_sun_elevation_end_rising and elevation >= dynamic_lighting_sun_elevation_start_falling %} {% set brightness_value = dynamic_lighting_min_brightness %} {% elif elevation <= dynamic_lighting_sun_elevation_start_rising and is_state_attr('sun.sun', 'rising', true) %} {% set brightness_value = dynamic_lighting_max_brightness %} {% elif elevation <= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set brightness_value = dynamic_lighting_max_brightness %} {% else %} {% set brightness_value = dynamic_lighting_min_brightness %} {% endif %} {% else %} {% set brightness_value = dynamic_lighting_max_brightness %} {% endif %} {% if expand(light_entities) | selectattr('state', '==', 'on') | list | count > 0 %} {% if (brightness_value >= (lp * 0.99) and brightness_value <= (lp * 1.01)) %} true {% else %} false {% endif %} {% else %} false {% endif %} - 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: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Wait for sun elevation to change" wait_for_trigger: - trigger: state entity_id: sun.sun attribute: elevation - alias: "Adjust the light settings when all bypasses are off or state control is enabled, and the entity is turned ON" conditions: - condition: trigger id: - 't16' - 't9_on' - 't9_off' - 't9_stop' - condition: template value_template: "{{ repeat.index == 1 }}" sequence: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Wait for sun elevation to change" wait_for_trigger: - trigger: 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: - trigger: 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: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Wait for sun elevation to change" wait_for_trigger: - trigger: 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_elevation_cutoff: > {% if is_state_attr('sun.sun', 'rising', true) %} {{ dynamic_lighting_sun_elevation_start_rising }} {% else %} {{ dynamic_lighting_sun_elevation_end_falling }} {% endif %} 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 >= dynamic_elevation_cutoff %} {% if elevation >= dynamic_lighting_sun_elevation_start_rising and elevation <= dynamic_lighting_sun_elevation_end_rising and is_state_attr('sun.sun', 'rising', true) %} {% set colour_temp_value = ((start_slope * elevation) + start_ak) | round(1) %} {% elif elevation <= dynamic_lighting_sun_elevation_start_falling and elevation >= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set colour_temp_value = ((end_slope * elevation) + end_ak) | round(1) %} {% elif elevation >= dynamic_lighting_sun_elevation_end_rising and elevation >= dynamic_lighting_sun_elevation_start_falling %} {% set colour_temp_value = dynamic_lighting_max_colour_temp %} {% elif elevation <= dynamic_lighting_sun_elevation_start_rising and is_state_attr('sun.sun', 'rising', true) %} {% set colour_temp_value = dynamic_lighting_min_colour_temp %} {% elif elevation <= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set colour_temp_value = dynamic_lighting_min_colour_temp %} {% else %} {% set colour_temp_value = dynamic_lighting_max_colour_temp %} {% endif %} {% else %} {% set colour_temp_value = dynamic_lighting_min_colour_temp %} {% endif %} {{ colour_temp_value | round(0) }} 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 >= dynamic_elevation_cutoff %} {% if elevation >= dynamic_lighting_sun_elevation_start_rising and elevation <= dynamic_lighting_sun_elevation_end_rising and is_state_attr('sun.sun', 'rising', true) %} {% set brightness_value = ((start_slope * elevation) + start_ak) | round(1) %} {% elif elevation <= dynamic_lighting_sun_elevation_start_falling and elevation >= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set brightness_value = ((end_slope * elevation) + end_ak) | round(1) %} {% elif elevation >= dynamic_lighting_sun_elevation_end_rising and elevation >= dynamic_lighting_sun_elevation_start_falling %} {% set brightness_value = dynamic_lighting_max_brightness %} {% elif elevation <= dynamic_lighting_sun_elevation_start_rising and is_state_attr('sun.sun', 'rising', true) %} {% set brightness_value = dynamic_lighting_min_brightness %} {% elif elevation <= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set brightness_value = dynamic_lighting_min_brightness %} {% else %} {% set brightness_value = dynamic_lighting_max_brightness %} {% endif %} {% else %} {% set brightness_value = dynamic_lighting_min_brightness %} {% endif %} {{ brightness_value | round(0) }} 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 %} {% set light.data = dict(light.data, **{ 'transition': light_transition_on }) %} {% endif %} {{ light.data }} 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 >= dynamic_elevation_cutoff %} {% if elevation >= dynamic_lighting_sun_elevation_start_rising and elevation <= dynamic_lighting_sun_elevation_end_rising and is_state_attr('sun.sun', 'rising', true) %} {% set brightness_value = ((start_slope * elevation) + start_ak) | round(1) %} {% elif elevation <= dynamic_lighting_sun_elevation_start_falling and elevation >= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set brightness_value = ((end_slope * elevation) + end_ak) | round(1) %} {% elif elevation >= dynamic_lighting_sun_elevation_end_rising and elevation >= dynamic_lighting_sun_elevation_start_falling %} {% set brightness_value = dynamic_lighting_max_brightness %} {% elif elevation <= dynamic_lighting_sun_elevation_start_rising and is_state_attr('sun.sun', 'rising', true) %} {% set brightness_value = dynamic_lighting_min_brightness %} {% elif elevation <= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set brightness_value = dynamic_lighting_min_brightness %} {% else %} {% set brightness_value = dynamic_lighting_max_brightness %} {% endif %} {% else %} {% set brightness_value = dynamic_lighting_min_brightness %} {% endif %} {% if expand(light_entities) | selectattr('state', '==', 'on') | list | count > 0 %} {% if (brightness_value >= (lp * 0.99) and brightness_value <= (lp * 1.01)) %} true {% else %} false {% endif %} {% else %} false {% endif %} - 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: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Wait for sun elevation to change" wait_for_trigger: - trigger: state entity_id: sun.sun attribute: elevation - alias: "Adjust the light settings when all bypasses are off or state control is enabled, and the entity is turned ON" conditions: - condition: trigger id: - 't16' - 't9_on' - 't9_off' - 't9_stop' - condition: template value_template: "{{ repeat.index == 1 }}" sequence: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Wait for sun elevation to change" wait_for_trigger: - trigger: 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: - trigger: 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: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Wait for sun elevation to change" wait_for_trigger: - trigger: 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_elevation_cutoff: > {% if is_state_attr('sun.sun', 'rising', true) %} {{ dynamic_lighting_sun_elevation_start_rising }} {% else %} {{ dynamic_lighting_sun_elevation_end_falling }} {% endif %} 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 >= dynamic_elevation_cutoff %} {% if elevation >= dynamic_lighting_sun_elevation_start_rising and elevation <= dynamic_lighting_sun_elevation_end_rising and is_state_attr('sun.sun', 'rising', true) %} {% set colour_temp_value = ((start_slope * elevation) + start_ak) | round(1) %} {% elif elevation <= dynamic_lighting_sun_elevation_start_falling and elevation >= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set colour_temp_value = ((end_slope * elevation) + end_ak) | round(1) %} {% elif elevation >= dynamic_lighting_sun_elevation_end_rising and elevation >= dynamic_lighting_sun_elevation_start_falling %} {% set colour_temp_value = dynamic_lighting_max_colour_temp %} {% elif elevation <= dynamic_lighting_sun_elevation_start_rising and is_state_attr('sun.sun', 'rising', true) %} {% set colour_temp_value = dynamic_lighting_min_colour_temp %} {% elif elevation <= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set colour_temp_value = dynamic_lighting_min_colour_temp %} {% else %} {% set colour_temp_value = dynamic_lighting_max_colour_temp %} {% endif %} {% else %} {% set colour_temp_value = dynamic_lighting_min_colour_temp %} {% endif %} {{ colour_temp_value | round(0) }} 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 > dynamic_elevation_cutoff %} {% if elevation >= dynamic_lighting_sun_elevation_start_rising and elevation <= dynamic_lighting_sun_elevation_end_rising and is_state_attr('sun.sun', 'rising', true) %} {% set brightness_value = ((start_slope * elevation) + start_ak) | round(1) %} {% elif elevation <= dynamic_lighting_sun_elevation_start_falling and elevation >= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set brightness_value = ((end_slope * elevation) + end_ak) | round(1) %} {% elif elevation >= dynamic_lighting_sun_elevation_end_rising and elevation >= dynamic_lighting_sun_elevation_start_falling %} {% set brightness_value = dynamic_lighting_min_brightness %} {% elif elevation <= dynamic_lighting_sun_elevation_start_rising and is_state_attr('sun.sun', 'rising', true) %} {% set brightness_value = dynamic_lighting_max_brightness %} {% elif elevation <= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set brightness_value = dynamic_lighting_max_brightness %} {% else %} {% set brightness_value = dynamic_lighting_min_brightness %} {% endif %} {% else %} {% set brightness_value = dynamic_lighting_max_brightness %} {% endif %} {{ brightness_value | round(0) }} 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 %} {% set light.data = dict(light.data, **{ 'transition': light_transition_on }) %} {% endif %} {{ light.data }} 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 > dynamic_elevation_cutoff %} {% if elevation >= dynamic_lighting_sun_elevation_start_rising and elevation <= dynamic_lighting_sun_elevation_end_rising and is_state_attr('sun.sun', 'rising', true) %} {% set brightness_value = ((start_slope * elevation) + start_ak) | round(1) %} {% elif elevation <= dynamic_lighting_sun_elevation_start_falling and elevation >= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set brightness_value = ((end_slope * elevation) + end_ak) | round(1) %} {% elif elevation >= dynamic_lighting_sun_elevation_end_rising and elevation >= dynamic_lighting_sun_elevation_start_falling %} {% set brightness_value = dynamic_lighting_min_brightness %} {% elif elevation <= dynamic_lighting_sun_elevation_start_rising and is_state_attr('sun.sun', 'rising', true) %} {% set brightness_value = dynamic_lighting_max_brightness %} {% elif elevation <= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set brightness_value = dynamic_lighting_max_brightness %} {% else %} {% set brightness_value = dynamic_lighting_min_brightness %} {% endif %} {% else %} {% set brightness_value = dynamic_lighting_max_brightness %} {% endif %} {% if expand(light_entities) | selectattr('state', '==', 'on') | list | count > 0 %} {% if (brightness_value >= (lp * 0.99) and brightness_value <= (lp * 1.01)) %} true {% else %} false {% endif %} {% else %} false {% endif %} - 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: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Wait for sun elevation to change" wait_for_trigger: - trigger: state entity_id: sun.sun attribute: elevation - alias: "Adjust the light settings when all bypasses are off or state control is enabled, and the entity is turned ON" conditions: - condition: trigger id: - 't16' - 't9_on' - 't9_off' - 't9_stop' - condition: template value_template: "{{ repeat.index == 1 }}" sequence: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Wait for sun elevation to change" wait_for_trigger: - trigger: 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: - trigger: 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: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Wait for sun elevation to change" wait_for_trigger: - trigger: 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_elevation_cutoff: > {% if is_state_attr('sun.sun', 'rising', true) %} {{ dynamic_lighting_sun_elevation_start_rising }} {% else %} {{ dynamic_lighting_sun_elevation_end_falling }} {% endif %} 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 %} {% set bv = dynamic_lighting_max_brightness %} {% elif lux >= dynamic_lighting_max_lux %} {% set bv = dynamic_lighting_min_brightness %} {% else %} {% set bv = ((slope * lux) + ak) | round(1) %} {% endif %} {% if lp <= 0 %} {% set bv = bv %} {% elif (bv > lp) and (dynamic_lighting_max_brightness - lp) <= dynamic_lighting_dead_zone %} {% set bv = dynamic_lighting_max_brightness %} {% elif (lp > bv) and (lp - dynamic_lighting_min_brightness) <= dynamic_lighting_dead_zone %} {% set bv = dynamic_lighting_min_brightness %} {% elif (bv > lp) and (bv - lp) <= dynamic_lighting_dead_zone %} {% set bv = lp %} {% elif (lp > bv) and (lp - bv) <= dynamic_lighting_dead_zone %} {% set bv = lp %} {% elif bv > (lp + dynamic_lighting_step_value) %} {% set bv = lp + dynamic_lighting_step_value %} {% elif bv < (lp - dynamic_lighting_step_value) %} {% set bv = lp - dynamic_lighting_step_value %} {% endif %} {{ bv | round(0) }} dynamic_kelvin: > {% if expand(light_entities) | selectattr('state', '==', 'off') | list | count > 0 %} {% 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 >= dynamic_elevation_cutoff %} {% if elevation >= dynamic_lighting_sun_elevation_start_rising and elevation <= dynamic_lighting_sun_elevation_end_rising and is_state_attr('sun.sun', 'rising', true) %} {% set colour_temp_value = ((start_slope * elevation) + start_ak) | round(1) %} {% elif elevation <= dynamic_lighting_sun_elevation_start_falling and elevation >= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set colour_temp_value = ((end_slope * elevation) + end_ak) | round(1) %} {% elif elevation >= dynamic_lighting_sun_elevation_end_rising and elevation >= dynamic_lighting_sun_elevation_start_falling %} {% set colour_temp_value = dynamic_lighting_max_colour_temp %} {% elif elevation <= dynamic_lighting_sun_elevation_start_rising and is_state_attr('sun.sun', 'rising', true) %} {% set colour_temp_value = dynamic_lighting_min_colour_temp %} {% elif elevation <= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set colour_temp_value = dynamic_lighting_min_colour_temp %} {% else %} {% set colour_temp_value = dynamic_lighting_max_colour_temp %} {% endif %} {% else %} {% set colour_temp_value = dynamic_lighting_min_colour_temp %} {% endif %} {{ colour_temp_value | round(0) }} {% endif %} 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 %} {% set light.data = dict(light.data, **{ 'transition': light_transition_on }) %} {% endif %} {{ light.data }} 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 %} {% set light.data = dict(light.data, **{ 'transition': light_transition_on }) %} {% endif %} {{ light.data }} 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 %} {% set bv = dynamic_lighting_max_brightness %} {% elif lux >= dynamic_lighting_max_lux %} {% set bv = dynamic_lighting_min_brightness %} {% else %} {% set bv = ((slope * lux) + ak) | round(1) %} {% endif %} {% if (bv > lp) and (dynamic_lighting_max_brightness - lp) <= dynamic_lighting_dead_zone %} false {% elif (lp > bv) and (lp - dynamic_lighting_min_brightness) <= dynamic_lighting_dead_zone %} false {% elif (bv >= lp) and (bv - lp) <= dynamic_lighting_dead_zone %} true {% elif (lp >= bv) and (lp - bv) <= dynamic_lighting_dead_zone %} true {% else %} false {% endif %} - 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' - condition: template value_template: "{{ repeat.index == 1 }}" 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' - condition: template value_template: "{{ repeat.index == 1 }}" sequence: - alias: "Delay for parallel actions needed for when the light is on" delay: milliseconds: 100 - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Dynamic lighting heartbeat" delay: minutes: !input dynamic_lighting_heartbeat - alias: "Adjust the light settings when all bypasses are off or state control is enabled, and the entity is turned ON" conditions: - condition: trigger id: - 't16' - 't9_on' - 't9_off' - 't9_stop' - condition: template value_template: "{{ repeat.index == 1 }}" sequence: - alias: "Delay for parallel actions needed for when the light is on" delay: milliseconds: 100 - action: 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: - condition: template value_template: "{{ in_dead_zone }}" - condition: template value_template: "{{ repeat.index != 1 }}" 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: - action: 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: - action: 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_elevation_cutoff: > {% if is_state_attr('sun.sun', 'rising', true) %} {{ dynamic_lighting_sun_elevation_start_rising }} {% else %} {{ dynamic_lighting_sun_elevation_end_falling }} {% endif %} 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 >= dynamic_elevation_cutoff %} {% if elevation >= dynamic_lighting_sun_elevation_start_rising and elevation <= dynamic_lighting_sun_elevation_end_rising and is_state_attr('sun.sun', 'rising', true) %} {% set colour_temp_value = ((start_slope * elevation) + start_ak) | round(1) %} {% elif elevation <= dynamic_lighting_sun_elevation_start_falling and elevation >= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set colour_temp_value = ((end_slope * elevation) + end_ak) | round(1) %} {% elif elevation >= dynamic_lighting_sun_elevation_end_rising and elevation >= dynamic_lighting_sun_elevation_start_falling %} {% set colour_temp_value = dynamic_lighting_max_colour_temp %} {% elif elevation <= dynamic_lighting_sun_elevation_start_rising and is_state_attr('sun.sun', 'rising', true) %} {% set colour_temp_value = dynamic_lighting_min_colour_temp %} {% elif elevation <= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set colour_temp_value = dynamic_lighting_min_colour_temp %} {% else %} {% set colour_temp_value = dynamic_lighting_max_colour_temp %} {% endif %} {% else %} {% set colour_temp_value = dynamic_lighting_min_colour_temp %} {% endif %} {{ colour_temp_value | round(0) }} 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 %} {% set light.data = dict(light.data, **{ 'transition': light_transition_on }) %} {% endif %} {{ light.data }} should_wait: > {% set elevation = state_attr('sun.sun', 'elevation') | float %} {% if expand(light_entities) | selectattr('state', '==', 'on') | list | count > 0 %} {% 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) %} false {% 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) %} false {% elif elevation >= (dynamic_lighting_sun_elevation_end_rising + 2) and elevation >= (dynamic_lighting_sun_elevation_start_falling - 2) %} true {% elif elevation <= (dynamic_lighting_sun_elevation_start_rising - 2) and is_state_attr('sun.sun', 'rising', true) %} true {% elif elevation <= (dynamic_lighting_sun_elevation_end_falling - 2) and is_state_attr('sun.sun', 'rising', false) %} true {% else %} true {% endif %} {% else %} false {% endif %} - 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: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Wait for sun elevation to change" wait_for_trigger: - trigger: state entity_id: sun.sun attribute: elevation - alias: "Adjust the light settings when all bypasses are off or state control is enabled, and the entity is turned ON" conditions: - condition: trigger id: - 't16' - 't9_on' - 't9_off' - 't9_stop' - condition: template value_template: "{{ repeat.index == 1 }}" sequence: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Wait for sun elevation to change" wait_for_trigger: - trigger: 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: - trigger: 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: - trigger: 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: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Wait for sun elevation to change" wait_for_trigger: - trigger: 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_elevation_cutoff: > {% if is_state_attr('sun.sun', 'rising', true) %} {{ dynamic_lighting_sun_elevation_start_rising }} {% else %} {{ dynamic_lighting_sun_elevation_end_falling }} {% endif %} 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 %} {% set bv = dynamic_lighting_min_brightness %} {% elif lux >= dynamic_lighting_max_lux %} {% set bv = dynamic_lighting_max_brightness %} {% else %} {% set bv = ((slope * lux) + ak) | round(1) %} {% endif %} {% if lp <= 0 %} {% set bv = bv %} {% elif (bv > lp) and (dynamic_lighting_max_brightness - lp) <= dynamic_lighting_dead_zone %} {% set bv = dynamic_lighting_max_brightness %} {% elif (lp > bv) and (lp - dynamic_lighting_min_brightness) <= dynamic_lighting_dead_zone %} {% set bv = dynamic_lighting_min_brightness %} {% elif (bv > lp) and (bv - lp) <= dynamic_lighting_dead_zone %} {% set bv = lp %} {% elif (lp > bv) and (lp - bv) <= dynamic_lighting_dead_zone %} {% set bv = lp %} {% elif bv > (lp + dynamic_lighting_step_value) %} {% set bv = lp + dynamic_lighting_step_value %} {% elif bv < (lp - dynamic_lighting_step_value) %} {% set bv = lp - dynamic_lighting_step_value %} {% endif %} {{ bv | round(0) }} dynamic_kelvin: > {% if expand(light_entities) | selectattr('state', '==', 'off') | list | count > 0 %} {% 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 >= dynamic_elevation_cutoff %} {% if elevation >= dynamic_lighting_sun_elevation_start_rising and elevation <= dynamic_lighting_sun_elevation_end_rising and is_state_attr('sun.sun', 'rising', true) %} {% set colour_temp_value = ((start_slope * elevation) + start_ak) | round(1) %} {% elif elevation <= dynamic_lighting_sun_elevation_start_falling and elevation >= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set colour_temp_value = ((end_slope * elevation) + end_ak) | round(1) %} {% elif elevation >= dynamic_lighting_sun_elevation_end_rising and elevation >= dynamic_lighting_sun_elevation_start_falling %} {% set colour_temp_value = dynamic_lighting_max_colour_temp %} {% elif elevation <= dynamic_lighting_sun_elevation_start_rising and is_state_attr('sun.sun', 'rising', true) %} {% set colour_temp_value = dynamic_lighting_min_colour_temp %} {% elif elevation <= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set colour_temp_value = dynamic_lighting_min_colour_temp %} {% else %} {% set colour_temp_value = dynamic_lighting_max_colour_temp %} {% endif %} {% else %} {% set colour_temp_value = dynamic_lighting_min_colour_temp %} {% endif %} {{ colour_temp_value | round(0) }} {% endif %} 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 %} {% set light.data = dict(light.data, **{ 'transition': light_transition_on }) %} {% endif %} {{ light.data }} 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 %} {% set light.data = dict(light.data, **{ 'transition': light_transition_on }) %} {% endif %} {{ light.data }} 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 %} {% set bv = dynamic_lighting_min_brightness %} {% elif lux >= dynamic_lighting_max_lux %} {% set bv = dynamic_lighting_max_brightness %} {% else %} {% set bv = ((slope * lux) + ak) | round(1) %} {% endif %} {% if (bv > lp) and (dynamic_lighting_max_brightness - lp) <= dynamic_lighting_dead_zone %} true {% elif (lp > bv) and (lp - dynamic_lighting_min_brightness) <= dynamic_lighting_dead_zone %} false {% elif (bv >= lp) and (bv - lp) <= dynamic_lighting_dead_zone %} true {% elif (lp >= bv) and (lp - bv) <= dynamic_lighting_dead_zone %} true {% else %} false {% endif %} - 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' - condition: template value_template: "{{ repeat.index == 1 }}" 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' - condition: template value_template: "{{ repeat.index == 1 }}" sequence: - alias: "Delay for parallel actions needed for when the light is on" delay: milliseconds: 100 - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Dynamic lighting heartbeat" delay: minutes: !input dynamic_lighting_heartbeat - alias: "Adjust the light settings when all bypasses are off or state control is enabled, and the entity is turned ON" conditions: - condition: trigger id: - 't16' - 't9_on' - 't9_off' - 't9_stop' - condition: template value_template: "{{ repeat.index == 1 }}" sequence: - alias: "Delay for parallel actions needed for when the light is on" delay: milliseconds: 100 - action: 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: - condition: template value_template: "{{ in_dead_zone }}" - condition: template value_template: "{{ repeat.index != 1 }}" 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: - action: 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: - action: 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_elevation_cutoff: > {% if is_state_attr('sun.sun', 'rising', true) %} {{ dynamic_lighting_sun_elevation_start_rising }} {% else %} {{ dynamic_lighting_sun_elevation_end_falling }} {% endif %} 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 >= dynamic_elevation_cutoff %} {% if elevation >= dynamic_lighting_sun_elevation_start_rising and elevation <= dynamic_lighting_sun_elevation_end_rising and is_state_attr('sun.sun', 'rising', true) %} {% set colour_temp_value = ((start_slope * elevation) + start_ak) | round(1) %} {% elif elevation <= dynamic_lighting_sun_elevation_start_falling and elevation >= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set colour_temp_value = ((end_slope * elevation) + end_ak) | round(1) %} {% elif elevation >= dynamic_lighting_sun_elevation_end_rising and elevation >= dynamic_lighting_sun_elevation_start_falling %} {% set colour_temp_value = dynamic_lighting_max_colour_temp %} {% elif elevation <= dynamic_lighting_sun_elevation_start_rising and is_state_attr('sun.sun', 'rising', true) %} {% set colour_temp_value = dynamic_lighting_min_colour_temp %} {% elif elevation <= dynamic_lighting_sun_elevation_end_falling and is_state_attr('sun.sun', 'rising', false) %} {% set colour_temp_value = dynamic_lighting_min_colour_temp %} {% else %} {% set colour_temp_value = dynamic_lighting_max_colour_temp %} {% endif %} {% else %} {% set colour_temp_value = dynamic_lighting_min_colour_temp %} {% endif %} {{ colour_temp_value | round(0) }} 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 %} {% set light.data = dict(light.data, **{ 'transition': light_transition_on }) %} {% endif %} {{ light.data }} should_wait: > {% set elevation = state_attr('sun.sun', 'elevation') | float %} {% if expand(light_entities) | selectattr('state', '==', 'on') | list | count > 0 %} {% 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) %} false {% 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) %} false {% elif elevation >= (dynamic_lighting_sun_elevation_end_rising + 2) and elevation >= (dynamic_lighting_sun_elevation_start_falling - 2) %} true {% elif elevation <= (dynamic_lighting_sun_elevation_start_rising - 2) and is_state_attr('sun.sun', 'rising', true) %} true {% elif elevation <= (dynamic_lighting_sun_elevation_end_falling - 2) and is_state_attr('sun.sun', 'rising', false) %} true {% else %} true {% endif %} {% else %} false {% endif %} - 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: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Wait for sun elevation to change" wait_for_trigger: - trigger: state entity_id: sun.sun attribute: elevation - alias: "Adjust the light settings when all bypasses are off or state control is enabled, and the entity is turned ON" conditions: - condition: trigger id: - 't16' - 't9_on' - 't9_off' - 't9_stop' - condition: template value_template: "{{ repeat.index == 1 }}" sequence: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Wait for sun elevation to change" wait_for_trigger: - trigger: 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: - trigger: 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: - trigger: 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: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Wait for sun elevation to change" wait_for_trigger: - trigger: state entity_id: sun.sun attribute: elevation - choose: - alias: "10 - Dynamic Lighting - Time Controlled - Colour Temp" conditions: - condition: template value_template: "{{ include_dynamic_lighting == 'enable_time_controled_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 current_time = now().hour + (now().minute / 60) %} {% set start_time_morning = dynamic_lighting_time_start_morning.split(':')[0] | int + (dynamic_lighting_time_start_morning.split(':')[1] | int / 60) %} {% set end_time_morning = dynamic_lighting_time_end_morning.split(':')[0] | int + (dynamic_lighting_time_end_morning.split(':')[1] | int / 60) %} {% set start_time_evening = dynamic_lighting_time_start_evening.split(':')[0] | int + (dynamic_lighting_time_start_evening.split(':')[1] | int / 60) %} {% set end_time_evening = dynamic_lighting_time_end_evening.split(':')[0] | int + (dynamic_lighting_time_end_evening.split(':')[1] | int / 60) %} {% if end_time_morning < start_time_morning %} {% if current_time < end_time_evening %} {% set current_time = current_time + 24 %} {% endif %} {% set end_time_morning = end_time_morning + 24 %} {% set start_time_evening = start_time_evening + 24 %} {% set end_time_evening = end_time_evening + 24 %} {% endif %} {% if end_time_evening < start_time_evening %} {% if current_time < end_time_evening %} {% set current_time = current_time + 24 %} {% endif %} {% set end_time_evening = end_time_evening + 24 %} {% endif %} {% set start_slope = (dynamic_lighting_min_colour_temp - dynamic_lighting_max_colour_temp) / (start_time_morning - end_time_morning) %} {% set start_ak = (start_slope * (-end_time_morning)) + dynamic_lighting_max_colour_temp %} {% set end_slope = (dynamic_lighting_min_colour_temp - dynamic_lighting_max_colour_temp) / (end_time_evening - start_time_evening) %} {% set end_ak = (end_slope * (-end_time_evening)) + dynamic_lighting_min_colour_temp %} {% if current_time >= start_time_morning and current_time <= end_time_morning %} {% set colour_temp_value = (start_slope * current_time + start_ak) | round(1) %} {% elif current_time >= start_time_evening and current_time <= end_time_evening %} {% set colour_temp_value = (end_slope * current_time + end_ak) | round(1) %} {% elif current_time > end_time_morning and current_time < start_time_evening %} {% set colour_temp_value = dynamic_lighting_max_colour_temp %} {% elif current_time < start_time_morning %} {% set colour_temp_value = dynamic_lighting_min_colour_temp %} {% elif current_time > end_time_evening %} {% set colour_temp_value = dynamic_lighting_min_colour_temp %} {% else %} {% set colour_temp_value = dynamic_lighting_max_colour_temp %} {% endif %} {{ colour_temp_value | round(0) }} 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 %} {% set light.data = dict(light.data, **{ 'transition': light_transition_on }) %} {% endif %} {% if 'use_brightness' in include_light_control %} {% set light.data = dict(light.data, **{ 'brightness_pct': light_brightness }) %} {% endif %} {{ light.data }} should_wait: > {% set current_time = now().hour + (now().minute / 60) %} {% set start_time_morning = dynamic_lighting_time_start_morning.split(':')[0] | int + (dynamic_lighting_time_start_morning.split(':')[1] | int / 60) %} {% set end_time_morning = dynamic_lighting_time_end_morning.split(':')[0] | int + (dynamic_lighting_time_end_morning.split(':')[1] | int / 60) %} {% set start_time_evening = dynamic_lighting_time_start_evening.split(':')[0] | int + (dynamic_lighting_time_start_evening.split(':')[1] | int / 60) %} {% set end_time_evening = dynamic_lighting_time_end_evening.split(':')[0] | int + (dynamic_lighting_time_end_evening.split(':')[1] | int / 60) %} {% if end_time_morning < start_time_morning %} {% if current_time < end_time_evening %} {% set current_time = current_time + 24 %} {% endif %} {% set end_time_morning = end_time_morning + 24 %} {% set start_time_evening = start_time_evening + 24 %} {% set end_time_evening = end_time_evening + 24 %} {% endif %} {% if end_time_evening < start_time_evening %} {% if current_time < end_time_evening %} {% set current_time = current_time + 24 %} {% endif %} {% set end_time_evening = end_time_evening + 24 %} {% endif %} {% set lights_on = expand(light_entities) | selectattr('state', '==', 'on') | list | count > 0 %} {% set in_morning = start_time_morning <= current_time <= end_time_morning %} {% set in_evening = start_time_evening <= current_time <= end_time_evening %} {{ lights_on and not (in_morning or in_evening) }} - 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' - condition: template value_template: "{{ repeat.index == 1 }}" 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' - condition: template value_template: "{{ repeat.index == 1 }}" sequence: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Dynamic lighting heartbeat" delay: minutes: !input dynamic_lighting_heartbeat - alias: "Adjust the light settings when all bypasses are off or state control is enabled, and the entity is turned ON" conditions: - condition: trigger id: - 't16' - 't9_on' - 't9_off' - 't9_stop' - condition: template value_template: "{{ repeat.index == 1 }}" sequence: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Dynamic lighting heartbeat" delay: minutes: !input dynamic_lighting_heartbeat - alias: "If time is outside the adjustment zone and the lights are ON" conditions: "{{ should_wait }}" sequence: - choose: - conditions: - condition: time after: !input dynamic_lighting_time_end_morning before: !input dynamic_lighting_time_start_evening sequence: - wait_for_trigger: - trigger: time at: !input dynamic_lighting_time_start_evening - conditions: - condition: time after: !input dynamic_lighting_time_end_evening before: !input dynamic_lighting_time_start_morning sequence: - wait_for_trigger: - trigger: time at: !input dynamic_lighting_time_start_morning - alias: "Set the dynamic lighting brightness for the normal lights" conditions: - condition: template value_template: "{{ include_dynamic_lighting == 'enable_time_controled_colour' }}" sequence: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Dynamic lighting heartbeat" delay: minutes: !input dynamic_lighting_heartbeat - choose: - alias: "11 - Dynamic Lighting - Time Controlled - Brightness" conditions: - condition: template value_template: "{{ include_dynamic_lighting == 'enable_time_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 current_time = now().hour + (now().minute / 60) %} {% set start_time_morning = dynamic_lighting_time_start_morning.split(':')[0] | int + (dynamic_lighting_time_start_morning.split(':')[1] | int / 60) %} {% set end_time_morning = dynamic_lighting_time_end_morning.split(':')[0] | int + (dynamic_lighting_time_end_morning.split(':')[1] | int / 60) %} {% set start_time_evening = dynamic_lighting_time_start_evening.split(':')[0] | int + (dynamic_lighting_time_start_evening.split(':')[1] | int / 60) %} {% set end_time_evening = dynamic_lighting_time_end_evening.split(':')[0] | int + (dynamic_lighting_time_end_evening.split(':')[1] | int / 60) %} {% if end_time_morning < start_time_morning %} {% if current_time < end_time_evening %} {% set current_time = current_time + 24 %} {% endif %} {% set end_time_morning = end_time_morning + 24 %} {% set start_time_evening = start_time_evening + 24 %} {% set end_time_evening = end_time_evening + 24 %} {% endif %} {% if end_time_evening < start_time_evening %} {% if current_time < end_time_evening %} {% set current_time = current_time + 24 %} {% endif %} {% set end_time_evening = end_time_evening + 24 %} {% endif %} {% set start_slope = (dynamic_lighting_min_brightness - dynamic_lighting_max_brightness) / (start_time_morning - end_time_morning) %} {% set start_ak = (start_slope * (-end_time_morning)) + dynamic_lighting_max_brightness %} {% set end_slope = (dynamic_lighting_min_brightness - dynamic_lighting_max_brightness) / (end_time_evening - start_time_evening) %} {% set end_ak = (end_slope * (-end_time_evening)) + dynamic_lighting_min_brightness %} {% if current_time >= start_time_morning and current_time <= end_time_morning %} {% set brightness_value = (start_slope * current_time + start_ak) | round(1) %} {% elif current_time >= start_time_evening and current_time <= end_time_evening %} {% set brightness_value = (end_slope * current_time + end_ak) | round(1) %} {% elif current_time > end_time_morning and current_time < start_time_evening %} {% set brightness_value = dynamic_lighting_max_brightness %} {% elif current_time < start_time_morning %} {% set brightness_value = dynamic_lighting_min_brightness %} {% elif current_time > end_time_evening %} {% set brightness_value = dynamic_lighting_min_brightness %} {% else %} {% set brightness_value = dynamic_lighting_max_brightness %} {% endif %} {{ brightness_value | round(0) }} 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 %} {% set light.data = dict(light.data, **{ 'transition': light_transition_on }) %} {% endif %} {% if include_light_colour_control == 'use_colour_temperature' %} {% set light.data = dict(light.data, **{ 'color_temp_kelvin': light_colour_temperature }) %} {% endif %} {% if include_light_colour_control == 'use_rgb_colour' %} {% set light.data = dict(light.data, **{ 'rgb_color': light_rgb_colour }) %} {% endif %} {% if include_light_colour_control == 'use_rgbw_colour' %} {% set light.data = dict(light.data, **{ 'rgbw_color': light_rgbw_colour }) %} {% endif %} {% if include_light_colour_control == 'use_rgbww_colour' %} {% set light.data = dict(light.data, **{ 'rgbww_color': light_rgbww_colour }) %} {% endif %} {{ light.data }} should_wait: > {% set current_time = now().hour + (now().minute / 60) %} {% set start_time_morning = dynamic_lighting_time_start_morning.split(':')[0] | int + (dynamic_lighting_time_start_morning.split(':')[1] | int / 60) %} {% set end_time_morning = dynamic_lighting_time_end_morning.split(':')[0] | int + (dynamic_lighting_time_end_morning.split(':')[1] | int / 60) %} {% set start_time_evening = dynamic_lighting_time_start_evening.split(':')[0] | int + (dynamic_lighting_time_start_evening.split(':')[1] | int / 60) %} {% set end_time_evening = dynamic_lighting_time_end_evening.split(':')[0] | int + (dynamic_lighting_time_end_evening.split(':')[1] | int / 60) %} {% if end_time_morning < start_time_morning %} {% if current_time < end_time_evening %} {% set current_time = current_time + 24 %} {% endif %} {% set end_time_morning = end_time_morning + 24 %} {% set start_time_evening = start_time_evening + 24 %} {% set end_time_evening = end_time_evening + 24 %} {% endif %} {% if end_time_evening < start_time_evening %} {% if current_time < end_time_evening %} {% set current_time = current_time + 24 %} {% endif %} {% set end_time_evening = end_time_evening + 24 %} {% endif %} {% set lights_on = expand(light_entities) | selectattr('state', '==', 'on') | list | count > 0 %} {% set in_morning = start_time_morning <= current_time <= end_time_morning %} {% set in_evening = start_time_evening <= current_time <= end_time_evening %} {{ lights_on and not (in_morning or in_evening) }} - 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' - condition: template value_template: "{{ repeat.index == 1 }}" 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' - condition: template value_template: "{{ repeat.index == 1 }}" sequence: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Dynamic lighting heartbeat" delay: minutes: !input dynamic_lighting_heartbeat - alias: "Adjust the light settings when all bypasses are off or state control is enabled, and the entity is turned ON" conditions: - condition: trigger id: - 't16' - 't9_on' - 't9_off' - 't9_stop' - condition: template value_template: "{{ repeat.index == 1 }}" sequence: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Dynamic lighting heartbeat" delay: minutes: !input dynamic_lighting_heartbeat - alias: "If time is outside the adjustment zone and the lights are ON" conditions: "{{ should_wait }}" sequence: - choose: - conditions: - condition: time after: !input dynamic_lighting_time_end_morning before: !input dynamic_lighting_time_start_evening sequence: - wait_for_trigger: - trigger: time at: !input dynamic_lighting_time_start_evening - conditions: - condition: time after: !input dynamic_lighting_time_end_evening before: !input dynamic_lighting_time_start_morning sequence: - wait_for_trigger: - trigger: time at: !input dynamic_lighting_time_start_morning - alias: "Set the dynamic lighting brightness for the normal lights" conditions: - condition: template value_template: "{{ include_dynamic_lighting == 'enable_time_controled_brightness' }}" sequence: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Dynamic lighting heartbeat" delay: minutes: !input dynamic_lighting_heartbeat - choose: - alias: "12 - Dynamic Lighting - Time Controlled - Brightness Inverted" conditions: - condition: template value_template: "{{ include_dynamic_lighting == 'enable_time_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 current_time = now().hour + (now().minute / 60) %} {% set start_time_morning = dynamic_lighting_time_start_morning.split(':')[0] | int + (dynamic_lighting_time_start_morning.split(':')[1] | int / 60) %} {% set end_time_morning = dynamic_lighting_time_end_morning.split(':')[0] | int + (dynamic_lighting_time_end_morning.split(':')[1] | int / 60) %} {% set start_time_evening = dynamic_lighting_time_start_evening.split(':')[0] | int + (dynamic_lighting_time_start_evening.split(':')[1] | int / 60) %} {% set end_time_evening = dynamic_lighting_time_end_evening.split(':')[0] | int + (dynamic_lighting_time_end_evening.split(':')[1] | int / 60) %} {% if end_time_morning < start_time_morning %} {% if current_time < end_time_evening %} {% set current_time = current_time + 24 %} {% endif %} {% set end_time_morning = end_time_morning + 24 %} {% set start_time_evening = start_time_evening + 24 %} {% set end_time_evening = end_time_evening + 24 %} {% endif %} {% if end_time_evening < start_time_evening %} {% if current_time < end_time_evening %} {% set current_time = current_time + 24 %} {% endif %} {% set end_time_evening = end_time_evening + 24 %} {% endif %} {% set start_slope = (dynamic_lighting_max_brightness - dynamic_lighting_min_brightness) / (start_time_morning - end_time_morning) %} {% set start_ak = (start_slope * (-end_time_morning)) + dynamic_lighting_min_brightness %} {% set end_slope = (dynamic_lighting_max_brightness - dynamic_lighting_min_brightness) / (end_time_evening - start_time_evening) %} {% set end_ak = (end_slope * (-end_time_evening)) + dynamic_lighting_max_brightness %} {% if current_time >= start_time_morning and current_time <= end_time_morning %} {% set brightness_value = (start_slope * current_time + start_ak) | round(1) %} {% elif current_time >= start_time_evening and current_time <= end_time_evening %} {% set brightness_value = (end_slope * current_time + end_ak) | round(1) %} {% elif current_time > end_time_morning and current_time < start_time_evening %} {% set brightness_value = dynamic_lighting_min_brightness %} {% elif current_time < start_time_morning %} {% set brightness_value = dynamic_lighting_max_brightness %} {% elif current_time > end_time_evening %} {% set brightness_value = dynamic_lighting_max_brightness %} {% else %} {% set brightness_value = dynamic_lighting_min_brightness %} {% endif %} {{ brightness_value | round(0) }} 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 %} {% set light.data = dict(light.data, **{ 'transition': light_transition_on }) %} {% endif %} {% if include_light_colour_control == 'use_colour_temperature' %} {% set light.data = dict(light.data, **{ 'color_temp_kelvin': light_colour_temperature }) %} {% endif %} {% if include_light_colour_control == 'use_rgb_colour' %} {% set light.data = dict(light.data, **{ 'rgb_color': light_rgb_colour }) %} {% endif %} {% if include_light_colour_control == 'use_rgbw_colour' %} {% set light.data = dict(light.data, **{ 'rgbw_color': light_rgbw_colour }) %} {% endif %} {% if include_light_colour_control == 'use_rgbww_colour' %} {% set light.data = dict(light.data, **{ 'rgbww_color': light_rgbww_colour }) %} {% endif %} {{ light.data }} should_wait: > {% set current_time = now().hour + (now().minute / 60) %} {% set start_time_morning = dynamic_lighting_time_start_morning.split(':')[0] | int + (dynamic_lighting_time_start_morning.split(':')[1] | int / 60) %} {% set end_time_morning = dynamic_lighting_time_end_morning.split(':')[0] | int + (dynamic_lighting_time_end_morning.split(':')[1] | int / 60) %} {% set start_time_evening = dynamic_lighting_time_start_evening.split(':')[0] | int + (dynamic_lighting_time_start_evening.split(':')[1] | int / 60) %} {% set end_time_evening = dynamic_lighting_time_end_evening.split(':')[0] | int + (dynamic_lighting_time_end_evening.split(':')[1] | int / 60) %} {% if end_time_morning < start_time_morning %} {% if current_time < end_time_evening %} {% set current_time = current_time + 24 %} {% endif %} {% set end_time_morning = end_time_morning + 24 %} {% set start_time_evening = start_time_evening + 24 %} {% set end_time_evening = end_time_evening + 24 %} {% endif %} {% if end_time_evening < start_time_evening %} {% if current_time < end_time_evening %} {% set current_time = current_time + 24 %} {% endif %} {% set end_time_evening = end_time_evening + 24 %} {% endif %} {% set lights_on = expand(light_entities) | selectattr('state', '==', 'on') | list | count > 0 %} {% set in_morning = start_time_morning <= current_time <= end_time_morning %} {% set in_evening = start_time_evening <= current_time <= end_time_evening %} {{ lights_on and not (in_morning or in_evening) }} - 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' - condition: template value_template: "{{ repeat.index == 1 }}" 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' - condition: template value_template: "{{ repeat.index == 1 }}" sequence: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Dynamic lighting heartbeat" delay: minutes: !input dynamic_lighting_heartbeat - alias: "Adjust the light settings when all bypasses are off or state control is enabled, and the entity is turned ON" conditions: - condition: trigger id: - 't16' - 't9_on' - 't9_off' - 't9_stop' - condition: template value_template: "{{ repeat.index == 1 }}" sequence: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Dynamic lighting heartbeat" delay: minutes: !input dynamic_lighting_heartbeat - alias: "If time is outside the adjustment zone and the lights are ON" conditions: "{{ should_wait }}" sequence: - choose: - conditions: - condition: time after: !input dynamic_lighting_time_end_morning before: !input dynamic_lighting_time_start_evening sequence: - wait_for_trigger: - trigger: time at: !input dynamic_lighting_time_start_evening - conditions: - condition: time after: !input dynamic_lighting_time_end_evening before: !input dynamic_lighting_time_start_morning sequence: - wait_for_trigger: - trigger: time at: !input dynamic_lighting_time_start_morning - alias: "Set the dynamic lighting brightness for the normal lights" conditions: - condition: template value_template: "{{ include_dynamic_lighting == 'enable_time_controled_brightness_inv' }}" sequence: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Dynamic lighting heartbeat" delay: minutes: !input dynamic_lighting_heartbeat - choose: - alias: "13 - Dynamic Lighting - Time Controlled - Colour Temp & Brightness" conditions: - condition: template value_template: "{{ include_dynamic_lighting == 'enable_time_controled_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_brightness_pct: > {% set current_time = now().hour + (now().minute / 60) %} {% set start_time_morning = dynamic_lighting_time_start_morning.split(':')[0] | int + (dynamic_lighting_time_start_morning.split(':')[1] | int / 60) %} {% set end_time_morning = dynamic_lighting_time_end_morning.split(':')[0] | int + (dynamic_lighting_time_end_morning.split(':')[1] | int / 60) %} {% set start_time_evening = dynamic_lighting_time_start_evening.split(':')[0] | int + (dynamic_lighting_time_start_evening.split(':')[1] | int / 60) %} {% set end_time_evening = dynamic_lighting_time_end_evening.split(':')[0] | int + (dynamic_lighting_time_end_evening.split(':')[1] | int / 60) %} {% if end_time_morning < start_time_morning %} {% if current_time < end_time_evening %} {% set current_time = current_time + 24 %} {% endif %} {% set end_time_morning = end_time_morning + 24 %} {% set start_time_evening = start_time_evening + 24 %} {% set end_time_evening = end_time_evening + 24 %} {% endif %} {% if end_time_evening < start_time_evening %} {% if current_time < end_time_evening %} {% set current_time = current_time + 24 %} {% endif %} {% set end_time_evening = end_time_evening + 24 %} {% endif %} {% set start_slope = (dynamic_lighting_min_brightness - dynamic_lighting_max_brightness) / (start_time_morning - end_time_morning) %} {% set start_ak = (start_slope * (-end_time_morning)) + dynamic_lighting_max_brightness %} {% set end_slope = (dynamic_lighting_min_brightness - dynamic_lighting_max_brightness) / (end_time_evening - start_time_evening) %} {% set end_ak = (end_slope * (-end_time_evening)) + dynamic_lighting_min_brightness %} {% if current_time >= start_time_morning and current_time <= end_time_morning %} {% set brightness_value = (start_slope * current_time + start_ak) | round(1) %} {% elif current_time >= start_time_evening and current_time <= end_time_evening %} {% set brightness_value = (end_slope * current_time + end_ak) | round(1) %} {% elif current_time > end_time_morning and current_time < start_time_evening %} {% set brightness_value = dynamic_lighting_max_brightness %} {% elif current_time < start_time_morning %} {% set brightness_value = dynamic_lighting_min_brightness %} {% elif current_time > end_time_evening %} {% set brightness_value = dynamic_lighting_min_brightness %} {% else %} {% set brightness_value = dynamic_lighting_max_brightness %} {% endif %} {{ brightness_value | round(0) }} dynamic_kelvin: > {% set current_time = now().hour + (now().minute / 60) %} {% set start_time_morning = dynamic_lighting_time_start_morning.split(':')[0] | int + (dynamic_lighting_time_start_morning.split(':')[1] | int / 60) %} {% set end_time_morning = dynamic_lighting_time_end_morning.split(':')[0] | int + (dynamic_lighting_time_end_morning.split(':')[1] | int / 60) %} {% set start_time_evening = dynamic_lighting_time_start_evening.split(':')[0] | int + (dynamic_lighting_time_start_evening.split(':')[1] | int / 60) %} {% set end_time_evening = dynamic_lighting_time_end_evening.split(':')[0] | int + (dynamic_lighting_time_end_evening.split(':')[1] | int / 60) %} {% if end_time_morning < start_time_morning %} {% if current_time < end_time_evening %} {% set current_time = current_time + 24 %} {% endif %} {% set end_time_morning = end_time_morning + 24 %} {% set start_time_evening = start_time_evening + 24 %} {% set end_time_evening = end_time_evening + 24 %} {% endif %} {% if end_time_evening < start_time_evening %} {% if current_time < end_time_evening %} {% set current_time = current_time + 24 %} {% endif %} {% set end_time_evening = end_time_evening + 24 %} {% endif %} {% set start_slope = (dynamic_lighting_min_colour_temp - dynamic_lighting_max_colour_temp) / (start_time_morning - end_time_morning) %} {% set start_ak = (start_slope * (-end_time_morning)) + dynamic_lighting_max_colour_temp %} {% set end_slope = (dynamic_lighting_min_colour_temp - dynamic_lighting_max_colour_temp) / (end_time_evening - start_time_evening) %} {% set end_ak = (end_slope * (-end_time_evening)) + dynamic_lighting_min_colour_temp %} {% if current_time >= start_time_morning and current_time <= end_time_morning %} {% set colour_temp_value = (start_slope * current_time + start_ak) | round(1) %} {% elif current_time >= start_time_evening and current_time <= end_time_evening %} {% set colour_temp_value = (end_slope * current_time + end_ak) | round(1) %} {% elif current_time > end_time_morning and current_time < start_time_evening %} {% set colour_temp_value = dynamic_lighting_max_colour_temp %} {% elif current_time < start_time_morning %} {% set colour_temp_value = dynamic_lighting_min_colour_temp %} {% elif current_time > end_time_evening %} {% set colour_temp_value = dynamic_lighting_min_colour_temp %} {% else %} {% set colour_temp_value = dynamic_lighting_max_colour_temp %} {% endif %} {{ colour_temp_value | round(0) }} 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 %} {% set light.data = dict(light.data, **{ 'transition': light_transition_on }) %} {% endif %} {{ light.data }} should_wait: > {% set current_time = now().hour + (now().minute / 60) %} {% set start_time_morning = dynamic_lighting_time_start_morning.split(':')[0] | int + (dynamic_lighting_time_start_morning.split(':')[1] | int / 60) %} {% set end_time_morning = dynamic_lighting_time_end_morning.split(':')[0] | int + (dynamic_lighting_time_end_morning.split(':')[1] | int / 60) %} {% set start_time_evening = dynamic_lighting_time_start_evening.split(':')[0] | int + (dynamic_lighting_time_start_evening.split(':')[1] | int / 60) %} {% set end_time_evening = dynamic_lighting_time_end_evening.split(':')[0] | int + (dynamic_lighting_time_end_evening.split(':')[1] | int / 60) %} {% if end_time_morning < start_time_morning %} {% if current_time < end_time_evening %} {% set current_time = current_time + 24 %} {% endif %} {% set end_time_morning = end_time_morning + 24 %} {% set start_time_evening = start_time_evening + 24 %} {% set end_time_evening = end_time_evening + 24 %} {% endif %} {% if end_time_evening < start_time_evening %} {% if current_time < end_time_evening %} {% set current_time = current_time + 24 %} {% endif %} {% set end_time_evening = end_time_evening + 24 %} {% endif %} {% set lights_on = expand(light_entities) | selectattr('state', '==', 'on') | list | count > 0 %} {% set in_morning = start_time_morning <= current_time <= end_time_morning %} {% set in_evening = start_time_evening <= current_time <= end_time_evening %} {{ lights_on and not (in_morning or in_evening) }} - 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' - condition: template value_template: "{{ repeat.index == 1 }}" 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' - condition: template value_template: "{{ repeat.index == 1 }}" sequence: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Dynamic lighting heartbeat" delay: minutes: !input dynamic_lighting_heartbeat - alias: "Adjust the light settings when all bypasses are off or state control is enabled, and the entity is turned ON" conditions: - condition: trigger id: - 't16' - 't9_on' - 't9_off' - 't9_stop' - condition: template value_template: "{{ repeat.index == 1 }}" sequence: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Dynamic lighting heartbeat" delay: minutes: !input dynamic_lighting_heartbeat - alias: "If time is outside the adjustment zone and the lights are ON" conditions: "{{ should_wait }}" sequence: - choose: - conditions: - condition: time after: !input dynamic_lighting_time_end_morning before: !input dynamic_lighting_time_start_evening sequence: - wait_for_trigger: - trigger: time at: !input dynamic_lighting_time_start_evening - conditions: - condition: time after: !input dynamic_lighting_time_end_evening before: !input dynamic_lighting_time_start_morning sequence: - wait_for_trigger: - trigger: time at: !input dynamic_lighting_time_start_morning - alias: "Set the dynamic lighting brightness for the normal lights" conditions: - condition: template value_template: "{{ include_dynamic_lighting == 'enable_time_controled_colour_brightness' }}" sequence: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ dynamic_light_data }}" - alias: "Dynamic lighting heartbeat" delay: minutes: !input dynamic_lighting_heartbeat - stop: "Stop the automation" - sequence: - choose: - alias: "Turn ON lights" conditions: - alias: "Check the dynamic lighting options" condition: or conditions: - condition: template value_template: "{{ include_dynamic_lighting == 'disable_dynamic_lighting' }}" - alias: "Check that dynamic lighting is active and the state control option is enabled" condition: and conditions: - condition: template value_template: "{{ include_dynamic_lighting != 'disable_dynamic_lighting' }}" - condition: template value_template: "{{ dynamic_lighting_state_control == 'enable_state_control' }}" - condition: template value_template: "{{ states(dynamic_lighting_state_control_entity) == dynamic_lighting_state_control_activation_state_inv }}" sequence: - action: light.turn_on target: entity_id: "{{ light_entities_off }}" data: "{{ light_data }}" - choose: - alias: "Dynamic Lighting State Control Turning OFF" conditions: - condition: trigger id: 't17' - condition: template value_template: "{{ include_dynamic_lighting != 'disable_dynamic_lighting' }}" sequence: - action: light.turn_on target: entity_id: "{{ light_entities }}" data: "{{ light_data }}" - choose: - alias: "Dynamic Lighting - Check if Input Boolean Helper is ON" conditions: - condition: template value_template: >- {% if dynamic_lighting_boolean != [] %} {{ is_state(dynamic_lighting_boolean, 'on') }} {% endif %} sequence: - alias: "Turn off the boolean for dynamic lighting" action: 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 on the scenes" action: scene.turn_on target: entity_id: "{{ scene_entities }}" data: transition: "{{ light_transition_on }}" - alias: "Turn on the boolean for scenes and scripts" action: 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" action: scene.turn_on target: entity_id: "{{ scene_entities }}" - alias: "Turn on the boolean for scenes and scripts" action: input_boolean.turn_on data: entity_id: "{{ boolean_scenes_scripts_helper }}" - alias: "Turn on the switches" action: switch.turn_on target: entity_id: "{{ switch_entities_off }}" - alias: "Turn on the scripts" action: 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" action: 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" action: 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" action: 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' - 't19' sequence: - choose: - alias: "Dynamic Lighting - Check if Input Boolean Helper is ON" conditions: - condition: template value_template: "{{ include_dynamic_lighting != 'disable_dynamic_lighting' }}" - condition: template value_template: >- {% if dynamic_lighting_boolean != [] %} {{ is_state(dynamic_lighting_boolean, 'on') }} {% endif %} sequence: - alias: "Turn off the boolean for dynamic lighting" action: 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" action: light.turn_off target: entity_id: "{{ light_entities }}" data: transition: "{{ light_transition_off }}" - alias: "Turn off the scenes" action: 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" action: light.turn_off target: entity_id: "{{ light_entities }}" - alias: "Turn off the scenes" action: scene.turn_on data: entity_id: "{{ end_scene_entities }}" - alias: "Turn off the switches" action: switch.turn_off target: entity_id: "{{ switch_entities }}" - alias: "Turn off the script" action: script.turn_on data: entity_id: "{{ end_script_entities }}" - alias: "Turn off the boolean for scenes and scripts" action: input_boolean.turn_off data: entity_id: !input boolean_scenes_scripts