homeassistant:
  name: Maple House
  latitude: 43.6532
  longitude: -79.3832
  elevation: 76
  unit_system: metric
  time_zone: America/Toronto
  currency: CAD
  country: CA

default_config:

frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

http:
  use_x_forwarded_for: true
  trusted_proxies:
    - 172.20.0.0/16
  ip_ban_enabled: true
  login_attempts_threshold: 5

recorder:
  purge_keep_days: 14
  auto_purge: true
  commit_interval: 5
  exclude:
    domains:
      - updater
      - sun
    entity_globs:
      - sensor.*_rssi
      - sensor.*_linkquality

history:
  include:
    domains:
      - climate
      - light
      - sensor
      - switch

logbook:
  exclude:
    entity_globs:
      - sensor.*_rssi
      - sensor.*_linkquality

logger:
  default: warning
  logs:
    homeassistant.components.mqtt: info
    homeassistant.components.zha: warning

mqtt:
  sensor:
    - name: Basement Temperature
      unique_id: basement_temperature
      state_topic: home/basement/environment
      value_template: "{{ value_json.temperature }}"
      unit_of_measurement: "°C"
      device_class: temperature
      state_class: measurement
      expire_after: 600
    - name: Basement Humidity
      unique_id: basement_humidity
      state_topic: home/basement/environment
      value_template: "{{ value_json.humidity }}"
      unit_of_measurement: "%"
      device_class: humidity
      state_class: measurement
      expire_after: 600
  binary_sensor:
    - name: Garage Side Door
      unique_id: garage_side_door
      state_topic: home/garage/side_door
      payload_on: "OPEN"
      payload_off: "CLOSED"
      device_class: door
  switch:
    - name: Patio String Lights
      unique_id: patio_string_lights
      command_topic: home/patio/lights/set
      state_topic: home/patio/lights/state
      payload_on: "ON"
      payload_off: "OFF"
      optimistic: false

template:
  - sensor:
      - name: Average Indoor Temperature
        unique_id: average_indoor_temperature
        unit_of_measurement: "°C"
        device_class: temperature
        state_class: measurement
        state: >
          {% set values = [
            states('sensor.living_room_temperature') | float(none),
            states('sensor.bedroom_temperature') | float(none),
            states('sensor.basement_temperature') | float(none)
          ] | reject('eq', none) | list %}
          {{ (values | sum / values | count) | round(1) if values else 'unknown' }}
  - binary_sensor:
      - name: Any Exterior Door Open
        unique_id: any_exterior_door_open
        device_class: opening
        state: >
          {{ is_state('binary_sensor.front_door', 'on')
             or is_state('binary_sensor.back_door', 'on')
             or is_state('binary_sensor.garage_side_door', 'on') }}

utility_meter:
  daily_energy:
    source: sensor.house_energy_total
    cycle: daily
  monthly_energy:
    source: sensor.house_energy_total
    cycle: monthly

input_boolean:
  guest_mode:
    name: Guest Mode
    icon: mdi:account-group
  vacation_mode:
    name: Vacation Mode
    icon: mdi:airplane

input_number:
  nighttime_temperature:
    name: Nighttime Temperature
    min: 16
    max: 22
    step: 0.5
    unit_of_measurement: "°C"
    icon: mdi:thermometer

timer:
  bathroom_fan:
    name: Bathroom Fan
    duration: "00:20:00"

notify:
  - platform: group
    name: household
    services:
      - service: mobile_app_alex_phone
      - service: mobile_app_sam_phone

sensor:
  - platform: time_date
    display_options:
      - time
      - date

binary_sensor:
  - platform: workday
    country: CA
    province: "ON"

energy:
  solar_forecast:
    - solcast_solar