homeassistant:
  name: Maple House
  latitude: 43.6532
  longitude: -79.3832
  elevation: 76
  unit_system: metric
  currency: CAD
  country: CA
  time_zone: America/Toronto
  external_url: "https://home.example.net"
  internal_url: "http://192.168.1.20:8123"
  packages: !include_dir_named packages

default_config:

frontend:
  themes: !include_dir_merge_named themes

http:
  use_x_forwarded_for: true
  trusted_proxies:
    - 192.168.1.10
  ip_ban_enabled: true
  login_attempts_threshold: 5

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

recorder:
  db_url: !secret recorder_db_url
  purge_keep_days: 14
  auto_purge: true
  exclude:
    domains:
      - camera
      - updater
    entity_globs:
      - sensor.*_rssi
      - sensor.*_linkquality

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

mqtt:
  broker: 192.168.1.30
  port: 1883
  username: !secret mqtt_username
  password: !secret mqtt_password
  discovery: true
  birth_message:
    topic: homeassistant/status
    payload: online
  will_message:
    topic: homeassistant/status
    payload: offline

zha:
  database_path: /config/zigbee.db
  enable_quirks: true

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

template:
  - sensor:
      - name: Whole Home Power
        unique_id: whole_home_power
        device_class: power
        state_class: measurement
        unit_of_measurement: W
        state: >
          {{ states('sensor.panel_channel_1_power') | float(0)
             + states('sensor.panel_channel_2_power') | float(0) }}
  - binary_sensor:
      - name: Any Exterior Door Open
        unique_id: any_exterior_door_open
        device_class: door
        state: >
          {{ is_state('binary_sensor.front_door', 'on')
             or is_state('binary_sensor.back_door', 'on')
             or is_state('binary_sensor.garage_entry_door', 'on') }}

automation:
  - id: porch_lights_at_sunset
    alias: Porch lights at sunset
    mode: restart
    trigger:
      - platform: sun
        event: sunset
        offset: "-00:15:00"
    condition:
      - condition: state
        entity_id: input_boolean.vacation_mode
        state: "off"
    action:
      - service: light.turn_on
        target:
          entity_id:
            - light.front_porch
            - light.back_patio
        data:
          brightness_pct: 65
          color_temp_kelvin: 2700
      - delay: "05:00:00"
      - service: light.turn_off
        target:
          entity_id:
            - light.front_porch
            - light.back_patio

  - id: notify_water_leak
    alias: Notify on water leak
    mode: single
    trigger:
      - platform: state
        entity_id:
          - binary_sensor.basement_leak
          - binary_sensor.kitchen_leak
          - binary_sensor.laundry_leak
        to: "on"
    action:
      - service: notify.household
        data:
          title: Water leak detected
          message: "Leak reported by {{ trigger.to_state.name }}."
          data:
            priority: high
      - service: switch.turn_off
        target:
          entity_id: switch.main_water_valve

  - id: night_setback
    alias: Nighttime thermostat setback
    mode: single
    trigger:
      - platform: time
        at: "22:30:00"
    condition:
      - condition: state
        entity_id: input_boolean.guest_mode
        state: "off"
    action:
      - service: climate.set_temperature
        target:
          entity_id: climate.main_floor
        data:
          temperature: 18

script:
  goodnight:
    alias: Goodnight
    mode: single
    sequence:
      - service: light.turn_off
        target:
          area_id:
            - kitchen
            - living_room
            - basement
      - service: lock.lock
        target:
          entity_id:
            - lock.front_door
            - lock.back_door
      - service: alarm_control_panel.alarm_arm_home
        target:
          entity_id: alarm_control_panel.house
      - service: input_boolean.turn_off
        target:
          entity_id: input_boolean.guest_mode

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

input_number:
  target_day_temperature:
    name: Target daytime temperature
    min: 16
    max: 24
    step: 0.5
    unit_of_measurement: "°C"
    icon: mdi:thermometer

scene: !include scenes.yaml
sensor: !include sensors.yaml
group: !include groups.yaml