#-------------------------------------------
#  When the Sliding door opens, at night, turn on Pool deck lights.
# @CCOSTAN
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
#-------------------------------------------

- alias: Pool Deck light helper
  id: 9521d521-00dc-4116-b467-5150735fcff9
  trigger:
    - platform: state
      entity_id: binary_sensor.MCU2_GPIO12
      to: 'on'
      for: '00:3:00'
    - platform: state
      entity_id: sun.sun
      to: 'below_horizon'
      from: 'above_horizon'

  condition:
    - condition: state
      entity_id: sun.sun
      state: 'below_horizon'
    - condition: state
      entity_id: binary_sensor.MCU2_GPIO12
      state: 'on'
    - condition: numeric_state
      entity_id: sensor.pirateweather_temperature
      below: 80

  action:
    - service: switch.turn_on
      entity_id: switch.back_landscaping
    - service: light.turn_on
      entity_id: light.outdoor_pool_lights
      data:
        color_temp: 369
    - wait_template: >-
        {{ states.binary_sensor.MCU2_GPIO12.state == 'off' }}
    - service: light.turn_off
      entity_id: light.outdoor_pool_lights