#
# ─── INTEGRATIONS ───────────────────────────────────────────────────────────────
#

# Depends on integrations (config flow):
# - https://www.home-assistant.io/integrations/mikrotik
# - https://www.home-assistant.io/integrations/synologydsm
# - https://www.home-assistant.io/integrations/zha

# https://www.home-assistant.io/integrations/fastdotcom
fastdotcom:
  scan_interval:
    minutes: 90

# https://www.home-assistant.io/integrations/wake_on_lan
wake_on_lan:


homekit:
  filter:
    include_entities:
      # Living Room
      - light.living_room
      - light.living_room_main
      - light.living_room_ambient
      - light.hue_ambiance_7
      - binary_sensor.living_room_right_window_contact
      - climate.living_room_radiator_mode
      - climate.toshiba_ac
      - cover.living_room
      - media_player.living_room
      - media_player.nvidia_shield
      - scene.living_room_ambient_neon
      - sensor.living_room_radiator_temperature
      - sensor.multisensor_6_relative_humidity
      - sensor.multisensor_6_temperature
      - switch.desk_outlet

      # Bedroom
      - light.master_bedroom
      - light.master_bedroom_main
      - light.bedside
      - binary_sensor.bedroom_door_contact
      - binary_sensor.bedroom_left_window_contact
      - binary_sensor.bedroom_right_window_contact
      - climate.bedroom_radiator_mode
      - fan.philips_airpurifier
      - media_player.master_bedroom
      - sensor.bedroom_weather_humidity
      - sensor.bedroom_weather_temperature
      - sensor.purifier_air_quality
      - sensor.purifier_allergens

      # Kitchen
      - light.kitchen
      - light.kitchen_main
      - light.kitchen_secondary
      - climate.kitchen_radiator_mode
      - binary_sensor.kitchen_motion_occupancy
      - binary_sensor.kitchen_window_contact
      - input_number.brita_remaining_liters
      - script.brita_pour_water
      - sensor.kitchen_weather_humidity
      - sensor.kitchen_weather_temperature
      - vacuum.vacuum

      # Bathroom
      - sensor.bathroom_weather_temperature
      - sensor.bathroom_weather_humidity

      # Hallway
      - light.hallway
      - light.hallway_entrance
      - light.hallway_main
      - group.hallway_motion
      - sensor.hallway_weather_temperature
      - sensor.hallway_weather_humidity

  entity_config:
    light.living_room_main:
      name: Living Room Main
    light.living_room_ambient:
      name: Living Room Ambient
    light.hue_ambiance_7:
      name: PC Light
    binary_sensor.living_room_right_window_contact:
      linked_battery_sensor: sensor.living_room_right_window_battery
      low_battery_threshold: 20
      name: Living Room Window
    sensor.multisensor_6_temperature:
      linked_battery_sensor: sensor.multisensor_6_battery_level
      low_battery_threshold: 20
      name: Living Room Temperature
    sensor.multisensor_6_relative_humidity:
      linked_battery_sensor: sensor.multisensor_6_battery_level
      low_battery_threshold: 20
      name: Living Room Humidity
    climate.living_room_radiator_mode:
      linked_battery_sensor: sensor.living_room_radiator_battery_level
      low_battery_threshold: 20
      name: Living Room Radiator
    switch.desk_outlet:
      type: outlet

    # Bedroom
    light.master_bedroom_main:
      name: Bedroom Main
    light.bedside:
      name: Bedside Lamp
    sensor.bedroom_weather_temperature:
      linked_battery_sensor: sensor.bedroom_weather_battery
      low_battery_threshold: 20
      name: Bedroom Temperature
    sensor.bedroom_weather_humidity:
      linked_battery_sensor: sensor.bedroom_weather_battery
      low_battery_threshold: 20
      name: Bedroom Humidity
    fan.philips_airpurifier:
      name: Purifier
    sensor.purifier_air_quality:
      name: Bedroom Air Quality
    sensor.purifier_allergens:
      name: Bedroom Allergens
    binary_sensor.bedroom_door_contact:
      linked_battery_sensor: sensor.bedroom_door_battery
      low_battery_threshold: 20
      name: Bedroom Door
    binary_sensor.bedroom_left_window_contact:
      linked_battery_sensor: sensor.bedroom_left_window_battery
      low_battery_threshold: 20
      name: Bedroom Left Window
    binary_sensor.bedroom_right_window_contact:
      linked_battery_sensor: sensor.bedroom_right_window_battery
      low_battery_threshold: 20
      name: Bedroom Right Window
    climate.bedroom_radiator_mode:
      linked_battery_sensor: sensor.bedroom_radiator_battery_level
      low_battery_threshold: 20
      name: Bedroom Radiator
    media_player.master_bedroom:
      feature_list:
        - feature: play_pause
        - feature: play_stop
        - feature: toggle_mute

    # Kitchen
    light.kitchen_main:
      name: Kitchen Main
    light.kitchen_secondary:
      name: Kitchen Secondary
    binary_sensor.kitchen_motion_occupancy:
      linked_battery_sensor: sensor.kitchen_motion_battery
      low_battery_threshold: 20
      name: Kitchen Motion
    binary_sensor.kitchen_window_contact:
      linked_battery_sensor: sensor.kitchen_window_battery
      low_battery_threshold: 20
      name: Kitchen Window
    sensor.kitchen_weather_temperature:
      linked_battery_sensor: sensor.kitchen_weather_battery
      low_battery_threshold: 20
      name: Kitchen Temperature
    sensor.kitchen_weather_humidity:
      linked_battery_sensor: sensor.kitchen_weather_battery
      low_battery_threshold: 20
      name: Kitchen Humidity
    climate.kitchen_radiator_mode:
      name: Kitchen Radiator

    # Bathroom
    sensor.bathroom_weather_temperature:
      linked_battery_sensor: sensor.bathroom_weather_battery
      low_battery_threshold: 20
      name: Bathroom Temperature
    sensor.bathroom_weather_humidity:
      linked_battery_sensor: sensor.bathroom_weather_battery
      low_battery_threshold: 20
      name: Bathroom Humidity

    # Hallway
    light.hallway_entrance:
      name: Hallway Entrance
    light.hallway_main:
      name: Hallway Main
    group.hallway_motion:
      name: Hallway Motion
    sensor.hallway_weather_temperature:
      linked_battery_sensor: sensor.hallway_weather_battery
      low_battery_threshold: 20
      name: Hallway Temperature
    sensor.hallway_weather_humidity:
      linked_battery_sensor: sensor.hallway_weather_battery
      low_battery_threshold: 20
      name: Hallway Humidity



#
# ─── ENTITIES ───────────────────────────────────────────────────────────────────
#

switch:
  - platform: command_line
    switches:
      pihole_temp_disable:
        friendly_name: "Pi-Hole pause for 5 mins"
        command_on: !secret pihole_disable_5
        command_off: !secret pihole_enable
        command_state: !secret pihole_status
        value_template: '{{ value_json.status == "disabled" }}'

binary_sensor:
  - platform: command_line
    name: "Pi-Hole enabled"
    command: !secret pihole_status
    payload_on: "enabled"
    payload_off: "disabled"
    value_template: '{{ value_json.status }}'

mqtt:
  sensor:
    - name: "Zigbee2MQTT Networkmap"
      # if you change base_topic of Zigbee2mqtt, change state_topic accordingly
      state_topic: "z2m_deconz/bridge/networkmap/raw"
      value_template: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
      # again, if you change base_topic of Zigbee2mqtt, change json_attributes_topic accordingly
      json_attributes_topic: z2m_deconz/bridge/networkmap/raw

    - name: "Zigbee2MQTT Devices count"
      availability_topic: "z2m_deconz/bridge/state"
      state_topic: "z2m_deconz/bridge/config/devices"
      value_template: "{{ value_json | count }}"
      icon: "mdi:counter"

    - name: "Router 1 LQI"
      state_topic: "z2m_deconz/router_1"
      availability_topic: "z2m_deconz/bridge/state"
      unit_of_measurement: "lqi"
      device_class: "signal_strength"
      value_template: "{{ value_json.linkquality }}"

script:
  zigbee2mqtt_get_device_count:
    alias: "Network · Zigbee2MQTT · Get device count"
    icon: "mdi:reload"
    sequence:
      service: mqtt.publish
      data:
        topic: "z2m_deconz/bridge/config/devices/get"

homeassistant:
  customize:
    switch.pihole_temp_disable:
      icon: mdi:pause-circle-outline
    sensor.pi_hole_seen_clients:
      icon: mdi:devices
    sensor.pi_hole_ads_percentage_blocked_today:
      icon: mdi:percent
    sensor.pi_hole_ads_blocked_today:
      icon: mdi:close-box-outline
    sensor.pi_hole_dns_queries_today:
      icon: mdi:radio-tower
