###################################
##  Late Night lights Section
# @CCOSTAN
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
###################################
- alias: 'Late Night Helper outside'
  id: 14115d72-6bea-41c1-8411-1eaf41b4ef2b
  trigger:
    - platform: state
      entity_id: group.garage_doors
    - platform: state
      entity_id: sun.sun
      to: 'below_horizon'
      from: 'above_horizon'

  condition:
    - condition: state
      entity_id: sun.sun
      state: 'below_horizon'

  action:
    - service: scene.turn_on
      entity_id: scene.front_full_brightness

    - choose:
        - conditions: >
            {{ states.group.entry_points.state == 'on' or
               states.group.garage_doors.state != 'closed' }}
          sequence:
            - service: scene.turn_on
              entity_id: scene.Red_living_Room
      default:
        - service: scene.turn_on
          entity_id: scene.tv_time

    - service: >
       {% set hour=states("sensor.time").split(':')[0] | int %}
       {% if hour >= 5 and hour <= 9 and states.group.bed.state == 'on'%}
         switch.turn_off
       {% else %}
          switch.turn_on
       {% endif %}
      entity_id:
        - group.master_bathroom_accents
        - switch.back_landscaping
        - switch.front_door_outlet
        - switch.foyer_outlet
    - wait_template: >-
        {{ states.group.garage_doors.state == 'closed' }}
    - service: script.monthly_color_scene
    - choose:
        - conditions: >
            {{ states.group.entry_points.state == 'on' or
               states.group.garage_doors.state != 'closed' }}
          sequence:
            - service: scene.turn_on
              entity_id: scene.Red_living_Room
      default:
        - service: scene.turn_on
          entity_id: scene.tv_time