###################################
##  Late Night lights Section
# @CCOSTAN
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
###################################
- alias: 'Late Night Helper outside'
  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

    - service_template: >-
        {% if states.group.entry_points.state == 'on' or states.group.garage_doors.state != 'closed' -%}
          light.turn_on
          entity_id:
            - light.living_room_accents
          rgb_color: [255,0,0]
        {% else %}
          light.turn_on
          entity_id:
            - light.living_room_accents
          rgb_color: [255,215,0]
        {% endif %}

    - service_template: >
       {% 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
    - service: light.turn_on
      entity_id:
        - light.living_room_accents
      data_template:
        # Red if Open, Gold if Closed
        rgb_color: >
          {% if states.group.entry_points.state == 'on' or states.group.garage_doors.state != 'closed' -%}
          - '255'
          - '0'
          - '0'
          {% else %}
          - '255'
          - '215'
          - '0'
          {% endif %}