version: 1

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

hub:
  hostname: home-hub
  http:
    host: 0.0.0.0
    port: 8123
    trusted_proxies:
      - 192.168.1.10
    use_forwarded_for: true
  database:
    url: sqlite:////data/home-automation.db
    retention_days: 30
  logging:
    level: info
    components:
      automation: info
      mqtt: warning
      zigbee: info

integrations:
  mqtt:
    broker: mosquitto
    port: 1883
    username: home_hub
    password: "${MQTT_PASSWORD}"
    discovery: true
    discovery_prefix: homeassistant
    birth_message:
      topic: home/hub/status
      payload: online
      qos: 1
      retain: true
    will_message:
      topic: home/hub/status
      payload: offline
      qos: 1
      retain: true

  zigbee:
    adapter: /dev/ttyUSB0
    channel: 20
    network_key: "${ZIGBEE_NETWORK_KEY}"
    permit_join: false

  weather:
    provider: openweathermap
    api_key: "${WEATHER_API_KEY}"
    location: Toronto,CA
    update_interval: 15m

areas:
  - id: living_room
    name: Living Room
  - id: kitchen
    name: Kitchen
  - id: primary_bedroom
    name: Primary Bedroom
  - id: entryway
    name: Entryway

devices:
  - id: living_room_lamp
    name: Living Room Lamp
    area: living_room
    platform: mqtt
    type: dimmable_light
    state_topic: home/living-room/lamp/state
    command_topic: home/living-room/lamp/set
    brightness: true
    availability_topic: home/living-room/lamp/availability

  - id: kitchen_motion
    name: Kitchen Motion Sensor
    area: kitchen
    platform: zigbee
    type: motion_sensor
    ieee_address: "00:12:4b:00:24:ab:cd:01"

  - id: bedroom_thermostat
    name: Bedroom Thermostat
    area: primary_bedroom
    platform: mqtt
    type: thermostat
    state_topic: home/bedroom/thermostat/state
    command_topic: home/bedroom/thermostat/set
    min_temperature: 16
    max_temperature: 24

  - id: front_door
    name: Front Door Sensor
    area: entryway
    platform: zigbee
    type: contact_sensor
    ieee_address: "00:12:4b:00:24:ab:cd:02"

scenes:
  - id: evening
    name: Evening
    entities:
      living_room_lamp:
        state: "on"
        brightness: 55
        color_temperature: 3200
      bedroom_thermostat:
        target_temperature: 20

  - id: away
    name: Away
    entities:
      living_room_lamp:
        state: "off"
      bedroom_thermostat:
        target_temperature: 17

automations:
  - id: kitchen_motion_lighting
    name: Kitchen motion lighting
    mode: restart
    triggers:
      - platform: state
        entity_id: kitchen_motion
        to: detected
    conditions:
      - condition: sun
        after: sunset
        before: sunrise
    actions:
      - service: light.turn_on
        target:
          entity_id: living_room_lamp
        data:
          brightness: 35
      - delay: 5m
      - service: light.turn_off
        target:
          entity_id: living_room_lamp

  - id: front_door_alert
    name: Front door left open
    mode: single
    triggers:
      - platform: state
        entity_id: front_door
        to: open
        for: 10m
    actions:
      - service: notify.mobile
        data:
          title: Front door alert
          message: The front door has been open for 10 minutes.

  - id: bedtime_temperature
    name: Lower bedroom temperature at night
    mode: single
    triggers:
      - platform: time
        at: "22:30:00"
    actions:
      - service: climate.set_temperature
        target:
          entity_id: bedroom_thermostat
        data:
          temperature: 18

notifications:
  mobile:
    provider: firebase
    credentials_file: /run/secrets/firebase_credentials
    default_priority: normal

healthcheck:
  enabled: true
  interval: 30s
  timeout: 5s
  failure_threshold: 3

backup:
  enabled: true
  schedule: "0 3 * * *"
  destination: /backups
  retention:
    daily: 7
    weekly: 4
    monthly: 6