# Mode config
input_select:
  house_mode:
    name: House mode
    icon: mdi:home-analytics
    options:
      - day
      - bed
      - night

binary_sensor:
  - platform: template
    sensors:
      house_mode:
        friendly_name: House mode
        value_template: "{{ states('input_select.house_mode') }}"
        icon_template: >-

          {% if is_state('input_select.house_mode', 'day') %}
            mdi:weather-sunny
          {% elif is_state('input_select.house_mode', 'bed') %}
            mdi:bed-king-outline
          {% else %}
            mdi:weather-night
          {% endif %}


automation:
  - alias: House mode · Set to day
    trigger:
      platform: state
      entity_id: input_select.house_mode
      to: "day"
    action:
      - service: script.routine_waking_up

  - alias: House mode · Set to bed
    trigger:
      platform: state
      entity_id: input_select.house_mode
      to: "bed"
    action:
      - service: script.routine_bedtime

  - alias: House mode · Set to night
    trigger:
      platform: state
      entity_id: input_select.house_mode
      to: "night"
    action:
      - service: script.routine_good_night

  - alias: House mode · Set to day if bedroom door was opened
    trigger:
      - platform: state
        entity_id: binary_sensor.bedroom_door
        to: "on"
      - platform: state
        entity_id: group.bedroom_windows
    condition:
      - condition: template
        value_template: "{{ now().hour >= states('input_datetime.alarm_time')[0:2]|int }}"
      - condition: not
        conditions:
          - condition: state
            entity_id: input_select.house_mode
            state: "day"
      - condition: state
        entity_id: input_boolean.georgi_home
        state: "on"
    action:
      - service: input_select.select_option
        entity_id: input_select.house_mode
        data:
          option: "day"
