- id: ac_turn_on
  alias: '[AC] Computer cave too hot'
  description: ''
  mode: single
  trigger:
    - platform: numeric_state
      entity_id: sensor.office_sensor_temperature
      above: '26'
      for:
        minutes: 5
  condition:
    - condition: state
      entity_id: input_select.home_mode
      state: Day
    - condition: state
      entity_id: input_boolean.vacation_mode
      state: 'off'
    - condition: state
      entity_id: binary_sensor.dining_window_1_open_close
      state: 'off'
    - condition: state
      entity_id: binary_sensor.dining_window_2_open_close
      state: 'off'
    - condition: state
      entity_id: binary_sensor.office_window_open_close
      state: 'off'
  action:
    - service: script.ac_on
    - choose:
        - conditions:
            - condition: state
              entity_id: climate.ac
              state: cool
          sequence:
            - service: climate.set_temperature
              target:
                entity_id: climate.ac
              data_template:
                temperature: "{{ state_attr('climate.ac', 'temperature') -1 }} "

- id: ac_precool
  alias: '[AC] Pre cool office'
  trigger:
    - platform: state
      entity_id: input_select.home_mode
      to: 'Day'
  condition:
    - condition: state
      entity_id: input_select.home_mode
      state: Day
    - condition: state
      entity_id: input_boolean.vacation_mode
      state: 'off'
    - condition: state
      entity_id: binary_sensor.dining_window_1_open_close
      state: 'off'
    - condition: state
      entity_id: binary_sensor.dining_window_2_open_close
      state: 'off'
    - condition: state
      entity_id: binary_sensor.office_window_open_close
      state: 'off'
    - condition: template
      value_template: "{{ state_attr('weather.home', 'forecast')[0].temperature > 24 }}"
  action:
    - service: script.ac_on
    - service: climate.set_temperature
      target:
        entity_id: climate.ac
      data:
        temperature: 24

- id: ac_enable
  alias: '[AC] Enable back AC when windows are closed'
  trigger:
    - platform: state
      entity_id: binary_sensor.dining_window_1_open_close
      to: 'off'
      for:
        minutes: 1
    - platform: state
      entity_id: binary_sensor.dining_window_2_open_close
      to: 'off'
      for:
        minutes: 1
    - platform: state
      entity_id: binary_sensor.office_window_open_close
      to: 'off'
      for:
        minutes: 1
  condition:
    - condition: state
      entity_id: input_select.home_mode
      state: Day
    - condition: state
      entity_id: input_boolean.vacation_mode
      state: 'off'
    - condition: state
      entity_id: binary_sensor.dining_window_1_open_close
      state: 'off'
    - condition: state
      entity_id: binary_sensor.dining_window_2_open_close
      state: 'off'
    - condition: state
      entity_id: binary_sensor.office_window_open_close
      state: 'off'
  action:
    - service: switch.turn_on
      entity_id: switch.ac_power_outlet

- id: ac_turn_off
  alias: '[AC] Turn off when windows are open'
  mode: single
  trigger:
    - platform: state
      entity_id: binary_sensor.dining_window_1_open_close
      to: 'on'
      for:
        minutes: 1
    - platform: state
      entity_id: binary_sensor.dining_window_2_open_close
      to: 'on'
      for:
        minutes: 1
    - platform: state
      entity_id: binary_sensor.office_window_open_close
      to: 'on'
      for:
        minutes: 1
  action:
    - service: script.ac_off