######################################################################
##  Good night Routine
######################################################################

- alias: 'Good Night Trigger'
  trigger:
    - platform: state
      entity_id: input_boolean.good_night
      to: 'on'
      from: 'off'
    - platform: state
      entity_id:
        - binary_sensor.sleepnumber_carlo_carlo_is_in_bed
        - binary_sensor.sleepnumber_carlo_stacey_is_in_bed
      to: 'on'

  condition:
    - condition: state
      entity_id: sun.sun
      state: 'below_horizon'
    - condition: state
      entity_id: input_boolean.guest_mode
      state: 'off'
    - condition: or
      conditions:
        - condition: state
          entity_id: binary_sensor.sleepnumber_carlo_carlo_is_in_bed
          state: 'on'
        - condition: state
          entity_id: device_tracker.carlo
          state: 'not_home'
    - condition: or
      conditions:
        - condition: state
          entity_id: binary_sensor.sleepnumber_carlo_stacey_is_in_bed
          state: 'on'
        - condition: state
          entity_id: device_tracker.stacey
          state: 'not_home'

  action:
    - service: input_boolean.turn_off
      entity_id: input_boolean.good_night
    - service: homeassistant.turn_off
      entity_id: group.outdoor_xmas_lights
    - service: script.interior_off