#Add ons
#Add Container User Interfaces to Navigation Menu
#Portainer
panel_iframe:
  portainer:
    title: "Portainer"
    url: "https://docker.metzner.myhome-server.de/#!/1/docker/containers"
    icon: mdi:docker
    require_admin: true
  esphome:
    title: "ESPHome"
    url: "https://esph.metzner.myhome-server.de/"
    icon: mdi:chip
    require_admin: true
  configurator:
    title: Configurator
    icon: mdi:wrench
    url: http://192.168.1.146:3218/
    require_admin: true
  nodered:
    title: Node-Red
    icon: mdi:shuffle-variant
    url: http://192.168.1.146:1880/
    require_admin: true

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

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

#Stop to record the history of some domains and entities
recorder:
  db_url: mysql://homeassistant:ha_dbdatabasepassword@192.168.1.146:3307/ha_db?charset=utf8mb4
  db_max_retries : 10
  auto_purge: true
  purge_keep_days: 60
  exclude:
    domains:
      - updater
      - media_player
    entities:
      - sensor.power_text
      - sensor.total_energy_text

# Home Assistant configuration.yaml
template:
  - sensor:
      - name: "Total Energy Consumption"
        unit_of_measurement: "kWh"
        state: >
          {% if states('sensor.total_energy_text') == 'unavailable' %}
            {{ states('sensor.total_energy_consumption') }}
          {% else %}
            {{ ((states('sensor.total_energy_text') | float) * 0.0001) | round(2) }}
          {% endif %}
      
      - name: "Current Power Consumption"
        unit_of_measurement: "W"
        state: >
          {% if states('sensor.power_text') == 'unavailable' %}
            {{ states('sensor.current_power_consumption') }}
          {% else %}
            {{ ((states('sensor.power_text') | float) * 0.01) | round(2) }}
          {% endif %}

# SONOFF S20_02
mqtt:
  switch:
    - unique_id: studio_switch
      name: "Studio Schalter"
      state_topic: "/SmartHome/Sonoff/S20_02/stat/POWER1"
      command_topic: "/SmartHome/Sonoff/S20_02/cmnd/power"
      availability:
        - topic: "/SmartHome/Sonoff/S20_02/tele/LWT"
          payload_available: "Online"
          payload_not_available: "Offline"
      payload_on: "on"
      payload_off: "off"
      state_on: "ON"
      state_off: "OFF"
      optimistic: false
      qos: 0
      retain: true

# Proxyconfig
http:
  use_x_forwarded_for: true
  trusted_proxies:
    - 172.20.0.0/24
  ip_ban_enabled: true
  login_attempts_threshold: 3
