# Loads default set of integrations. Do not remove.
default_config:
# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes
# Text to speech
tts:
  - platform: google_translate
 
####################
#     INCLUDES     #
####################
# Automatitonen
automation: !include automations.yaml
# Skripte
script: !include scripts.yaml
# Szenen
scene: !include scenes.yaml
# Groups
group: !include groups.yaml
# Email and whatsapp
notify: !include notify.yaml
# nextcloud
nextcloud: !include nextcloud.yaml
# homematic ccu2
#homematic: !include homematic.yaml
# scrape, "moon, moonphase,"
#scrape: !include scrape.yaml
# backup cleanup
#discovery: !include discovery.yaml
# template sensors
#template: !include template.yaml
# homeassistant
homeassistant:
  customize_glob:
 
# IR Stromzähler total
    sensor.stromnetz_mt681_gesamt:
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      last_reset: 1970-01-01T00:00:00+00:00
# Gas_Verbrauch Buderus
    sensor.buderus_gas:
      unit_of_measurement: "m³"
      device_class: gas
      state_class: total_increasing
      last_reset: 1970-01-01T00:00:00+00:00
# tamplate
template:
# Formatierte Zeit und Datum
  - sensor:
    - name: "Datum Uhrzeit"
      unique_id: datum_uhrzeit
      state: >
        {% set wochentag = ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"] %}
        {% set monat = ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"] %}
        {% set wochentag = wochentag[now().weekday()] %}
        {% set monat = monat[now().month - 1] %} {{ wochentag }}, der {{ now().day }} {{ monat }} {{now().year}}, {{now().timestamp() | timestamp_custom('%-X')}} Uhr
      icon: "mdi:calendar-clock"
  - sensor:
    - name: "Formatierte Zeit"
      unique_id: formatierte_uhrzeit
      state: >
          {% set wochentag = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"] %}
          {% set monat = ["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"] %}
          {% set wochentag = wochentag[now().weekday()] %}
          {% set monat = monat[now().month - 1] %}
          {{ wochentag }}, {{ now().day }} {{ monat }} {{now().year}}, {{ now().timestamp() | timestamp_custom('%H:%M') }}
      icon: "mdi:calendar-clock"
# Mondphase Bild neue version
  - sensor:
    - name: 'mein Mond'
      unique_id: mein_mond
      state: >
        {% set phase = states('sensor.moon_phase') %}
        {% set mapper = {'new_moon':'Neumond',
                         'waxing_crescent':'zunehmender Mond',
                         'first_quarter':'Erstes Viertel',
                         'waxing_gibbous':'Halbmond',
                         'full_moon':'Vollmond',
                         'waning_gibbous':'Abnehmender Mond',
                         'last_quarter':'Letztes Viertel'} %}
        {{mapper.get(phase,'Aschgrauer Mond')}}
      picture: >
        {% set state = states('sensor.moon_phase') %}
        /local/moon_phases/{{state}}.png
# Sternzeichen Elemente
  - sensor:
    - name: 'Sternzeichen Element'
      unique_id: zodiac_element
      state: >
        {% set cond = state_attr('sensor.zodiac', 'element') %}
        {% if cond == 'earth' %}
          Erde
        {% elif cond == 'fire' %}
          Feuer
        {% elif cond == 'air' %}
          Luft
        {% elif cond == 'water' %}
          Wasser
        {% endif %}
      picture: >
        {% set state = state_attr('sensor.zodiac', 'element') %}
        /local/zodiac/element/{{state}}.png
# Sternzeichen Modalität
  - sensor:
    - name: 'Sternzeichen Modalität'
      unique_id: zodiac_modality
      state: >
          {% set cond = state_attr('sensor.zodiac', 'modality') %}
          {% if cond == 'cardinal' %}
            Kardinalzeichen
          {% elif cond == 'fixed' %}
            Feste Zeichen
          {% elif cond == 'air' %}
            Bewegliche Zeichen
          {% endif %}
# Sternzeichen Energie
  - sensor:
    - name: 'Sternzeichen Energie'
      unique_id: zodiac_enegrie
      state: >
          {% if is_state('sensor.zodiac', 'aries') %}
             Männlich
          {% elif is_state('sensor.zodiac', 'taurus') %}
             Weiblich   
          {% elif is_state('sensor.zodiac', 'gemini') %}
             Männlich
          {% elif is_state('sensor.zodiac', 'cancer') %}
             Weiblich
          {% elif is_state('sensor.zodiac', 'leo') %}
             Männlich
          {% elif is_state('sensor.zodiac', 'virgo') %}
             Weiblich
          {% elif is_state('sensor.zodiac', 'libra') %}
             Männlich
          {% elif is_state('sensor.zodiac', 'scorpio') %}
             Weiblich
          {% elif is_state('sensor.zodiac', 'sagittarius') %}
             Männlich   
          {% elif is_state('sensor.zodiac', 'capricorn') %}
             Weiblich
          {% elif is_state('sensor.zodiac', 'aquarius') %}
             Männlich
          {% elif is_state('sensor.zodiac', 'pisces') %}
             Weilich
          {% endif %}
      picture: >
        {% set state = states('sensor.zodiac') %}
        /local/zodiac/energie/{{state}}.png
# Buderus Gas Heizkreis
  - sensor:
    - name: "Buderus HK Gas"
      device_class: "gas"
      unit_of_measurement: "m³"
      state: >
        {% set kwh = states('sensor.recording_ractualchpower') | float %}
        {% set normdichte_value = states('input_number.gas_normdichte') | float %}
        {% set mengengewichtet_value = states('input_number.gas_mengengewichtet') | float %}
        {{ '%.4f' | format( kwh/(normdichte_value * mengengewichtet_value) ) | round(4) }}
# Buderus Gas Warmwasser
  - sensor:
    - name: "Buderus WW Gas"
      device_class: "gas"
      unit_of_measurement: "m³"
      state: >
        {% set kwh = states('sensor.recording_ractualdhwpower') | float %}
        {% set normdichte_value = states('input_number.gas_normdichte') | float %}
        {% set mengengewichtet_value = states('input_number.gas_mengengewichtet') | float %}
        {{ '%.4f' | format( kwh/(normdichte_value * mengengewichtet_value) ) | round(4) }}
# sensors
sensor:
# email
  - platform: imap
    name: imap_state_req
    server: imap.gmx.net
    port: 993
    username: !secret email_username
    password: !secret email_password
# Date & Time
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'date_time'
      - 'date_time_utc'
      - 'date_time_iso'
      - 'time_date'
      - 'time_utc'
      - 'beat'
    
 # Einkaufsliste Bring!
  - platform: command_line
    scan_interval: 10
    name: Shopping List
    unique_id: sensor.shopping_list
    command: python3 /config/python_scripts/shopping_list_json.py
    json_attributes:
      - not_complete
      - content
    value_template: "{{ value_json.state }}"
# homematic
homematic:
  interfaces:
    rf:
      host: 192.168.178.243
      resolvenames: "json"
      username: "xxx"
      password: "xxx"
    wired:
      host: 192.168.178.243
      port: 2000
      resolvenames: "json"
      username: "xxx"
      password: "xxx"
    ip:
      host: 192.168.178.243
      port: 2010
    groups:
      host: 192.168.178.243
      port: 9292
      resolvenames: "json"
      username: "xxx"
      password: "xxx"
      path: /groups
  hosts:
    ccu2:
      host: 192.168.178.243
      port: 2001
      username: "xxx"
      password: "xxx"
    
# Scrapper
scrape:
  - resource: https://www.der-mond.de/
    sensor:
      - name: "Beleuchtungsgrad"
        unique_id: mond.beleuchtungsgrad
        icon: "mdi:lightbulb-night-outline"
        select: ".table > tbody:nth-child(1) > tr:nth-child(8) > td:nth-child(2)"
      - name: "Mondaufgang"
        unique_id: mond.mondaufgang
        icon: "mdi:arrow-up-circle-outline"
        select: ".table > tbody:nth-child(1) > tr:nth-child(9) > td:nth-child(2)"
      - name: "Monduntergang"
        unique_id: mond.monduntergang
        icon: "mdi:arrow-down-circle-outline"
        select: ".table > tbody:nth-child(1) > tr:nth-child(10) > td:nth-child(2)"
      - name: "Mondalter"
        unique_id: mond.mondalter
        icon: "mdi:calendar-clock-outline"
        select: ".table > tbody:nth-child(1) > tr:nth-child(7) > td:nth-child(2)"
      - name: "Kommende Mondphase"
        unique_id: mond.kommende.mondphase
        icon: "mdi:moon-waxing-crescent"
        select: ".table > tbody:nth-child(1) > tr:nth-child(11) > td:nth-child(2)"
      - name: "Mondphase heute"
        unique_id: mond.mondphase.heute
        icon: "mdi:moon-waning-crescent"
        select: ".table > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2)"
      - name: "Astronomisches Sternbild"
        unique_id: mond.astronomisches.sternbild
        icon: "mdi:weather-night"
        select: ".table > tbody:nth-child(1) > tr:nth-child(5) > td:nth-child(2)"
      - name: "Astrologisches Sternbild"
        unique_id: mond.astrologisches.sternbild
        icon: "mdi:star-crescent"
        select: ".table > tbody:nth-child(1) > tr:nth-child(6) > td:nth-child(2)"
      - name: "Mondhöhe"
        unique_id: mond.mondhoehe
        select: ".table > tbody:nth-child(1) > tr:nth-child(3) > td:nth-child(2)"
        icon: "mdi:theme-light-dark"
      - name: "Himmelsrichtung"
        unique_id: mond.himmelsrichtung
        select: ".table > tbody:nth-child(1) > tr:nth-child(4) > td:nth-child(2)"
        icon: "mdi:compass-rose"
          
# clenup snapshot service for backup
discovery:
clean_up_snapshots_service:
  host: http://192.168.178.230:8123
  token: xxx
  number_of_snapshots_to_keep: 8