{
  "version": 1,
  "minor_version": 1,
  "key": "lovelace.dashboard_spa",
  "data": {
    "config": {
      "views": [
        {
          "title": "Whirlpool",
          "type": "sections",
          "max_columns": 2,
          "path": "whirlpool",
          "icon": "mdi:hot-tub",
          "sections": [
            {
              "type": "grid",
              "cards": [
                {
                  "type": "heading",
                  "heading": "Status & Steuerung"
                },
                {
                  "type": "custom:mushroom-template-card",
                  "primary": "{% set ph = states('sensor.whirlpool_ph') | float(0) %} {% set orp = states('sensor.whirlpool_oxydo_reduktionspotenzial') | float(0) %} {% set online = is_state('binary_sensor.isonline_2', 'on') %} {% if not online %} Offline ⚠️ {% elif ph >= 7.0 and ph <= 7.6 and orp >= 650 %} Badespaß bereit! 🛁 {% else %} Wasser prüfen! ⚠️ {% endif %}",
                  "secondary": "{% set temp = states('sensor.spa_current_temperature') | float | round(1) %} {% set ziel = states('sensor.spa_desired_temperature') | float | round(1) %} {% set rate = states('sensor.whirlpool_heizrate') | float(0) | round(2) %} {{ temp }}°C → Ziel {{ ziel }}°C {%- if rate > 0 %} ↑ {{ rate }} °C/min {%- elif rate < 0 %} ↓ {{ rate | abs }} °C/min {%- endif %}",
                  "icon": "mdi:hot-tub",
                  "icon_color": "{% set ph = states('sensor.whirlpool_ph') | float(0) %} {% set orp = states('sensor.whirlpool_oxydo_reduktionspotenzial') | float(0) %} {% if not is_state('binary_sensor.isonline_2', 'on') %} grey {% elif ph >= 7.0 and ph <= 7.6 and orp >= 650 %} green {% elif (ph < 6.8 or ph > 7.9) or orp < 550 %} red {% else %} orange {% endif %}",
                  "vertical": true,
                  "grid_options": {
                    "columns": 12,
                    "rows": 2
                  }
                },
                {
                  "type": "custom:mushroom-chips-card",
                  "chips": [
                    {
                      "type": "template",
                      "icon": "mdi:ph",
                      "content": "{{ states(\"sensor.whirlpool_ph\") | float | round(1) }}",
                      "icon_color": "blue"
                    },
                    {
                      "type": "template",
                      "icon": "mdi:water-percent",
                      "content": "{{ states(\"sensor.whirlpool_oxydo_reduktionspotenzial\") | int }} mV",
                      "icon_color": "purple"
                    },
                    {
                      "type": "template",
                      "icon": "mdi:flash",
                      "content": "{{ states(\"sensor.whirlpool_leistung\") | int(0) }} W",
                      "icon_color": "amber"
                    },
                    {
                      "type": "entity",
                      "entity": "binary_sensor.isonline_2",
                      "icon": "mdi:wifi"
                    }
                  ],
                  "alignment": "center"
                },
                {
                  "type": "custom:mushroom-climate-card",
                  "entity": "climate.spa_thermostat",
                  "name": "Temperatur einstellen",
                  "show_temperature_control": true,
                  "layout": "horizontal"
                },
                {
                  "type": "horizontal-stack",
                  "cards": [
                    {
                      "type": "custom:mushroom-entity-card",
                      "entity": "switch.whirlpool",
                      "name": "Strom",
                      "icon": "mdi:power"
                    },
                    {
                      "type": "custom:mushroom-entity-card",
                      "entity": "switch.spa_pump",
                      "name": "Düsen",
                      "icon": "mdi:pump"
                    },
                    {
                      "type": "custom:mushroom-entity-card",
                      "entity": "switch.spa_light",
                      "name": "Licht",
                      "icon": "mdi:lightbulb-on"
                    }
                  ]
                },
                {
                  "type": "horizontal-stack",
                  "cards": [
                    {
                      "type": "custom:mushroom-entity-card",
                      "entity": "sensor.spa_filter_1",
                      "name": "Filter 1"
                    },
                    {
                      "type": "custom:mushroom-entity-card",
                      "entity": "sensor.spa_ozone",
                      "name": "UVC/Ozon"
                    },
                    {
                      "type": "custom:mushroom-entity-card",
                      "entity": "sensor.spa_circulation_pump",
                      "name": "Zirkulation"
                    }
                  ]
                },
                {
                  "type": "horizontal-stack",
                  "cards": [
                    {
                      "type": "custom:mushroom-select-card",
                      "entity": "select.spa_heater_mode",
                      "name": "Heizmodus",
                      "icon": "mdi:fire"
                    },
                    {
                      "type": "custom:mushroom-select-card",
                      "entity": "select.spa_temperature_range",
                      "name": "Temp.-Bereich",
                      "icon": "mdi:thermometer-lines"
                    }
                  ]
                },
                {
                  "type": "custom:mushroom-template-card",
                  "primary": "{% set alerts = states('sensor.spa_total_alerts') | int(0) %} {% if alerts == 0 %} Keine Störungen {% else %} {{ alerts }} Warnung(en) aktiv {% endif %}",
                  "secondary": "{{ states(\"sensor.spa_fault_message\") }}",
                  "icon": "{% if states('sensor.spa_total_alerts') | int(0) > 0 %} mdi:alert-circle {% else %} mdi:check-circle {% endif %}",
                  "icon_color": "{% if states('sensor.spa_total_alerts') | int(0) > 0 %} red {% else %} green {% endif %}",
                  "fill_container": true,
                  "grid_options": {
                    "columns": 12,
                    "rows": 1
                  }
                },
                {
                  "type": "heading",
                  "heading": "Ambiente"
                },
                {
                  "type": "custom:mushroom-light-card",
                  "entity": "light.ruheplatz_lichterkette",
                  "name": "Lichterkette",
                  "show_brightness_control": true,
                  "use_light_color": true
                },
                {
                  "type": "custom:mushroom-light-card",
                  "entity": "light.ruheplatz_wegbeleuchtung",
                  "name": "Wegbeleuchtung",
                  "show_brightness_control": true,
                  "use_light_color": true
                }
              ]
            },
            {
              "type": "grid",
              "cards": [
                {
                  "type": "heading",
                  "heading": "Wasseranalyse (24h)"
                },
                {
                  "type": "custom:apexcharts-card",
                  "graph_span": "24h",
                  "header": {
                    "show": true,
                    "show_states": true,
                    "colorize_states": true
                  },
                  "yaxis": [
                    {
                      "id": "ph",
                      "min": 6.5,
                      "max": 8,
                      "decimals": 1,
                      "apex_config": {
                        "tickAmount": 3
                      }
                    },
                    {
                      "id": "orp",
                      "min": 400,
                      "max": 900,
                      "opposite": true,
                      "decimals": 0
                    }
                  ],
                  "series": [
                    {
                      "entity": "sensor.whirlpool_ph",
                      "name": "pH",
                      "yaxis_id": "ph",
                      "color": "#2196f3",
                      "stroke_width": 3
                    },
                    {
                      "entity": "sensor.whirlpool_oxydo_reduktionspotenzial",
                      "name": "ORP",
                      "yaxis_id": "orp",
                      "color": "#9c27b0",
                      "stroke_width": 3
                    }
                  ],
                  "apex_config": {
                    "annotations": {
                      "position": "back",
                      "yaxis": [
                        {
                          "y": 7,
                          "y2": 7.6,
                          "y_axis_id": "ph",
                          "fillColor": "#4CAF50",
                          "opacity": 0.15,
                          "label": {
                            "text": "IDEAL"
                          }
                        }
                      ]
                    }
                  }
                },
                {
                  "type": "custom:apexcharts-card",
                  "graph_span": "24h",
                  "header": {
                    "show": true,
                    "title": "Temperaturverlauf",
                    "show_states": true,
                    "colorize_states": true
                  },
                  "series": [
                    {
                      "entity": "sensor.spa_current_temperature",
                      "name": "Ist",
                      "color": "#f44336",
                      "stroke_width": 3
                    },
                    {
                      "entity": "sensor.spa_desired_temperature",
                      "name": "Soll",
                      "color": "#ff9800",
                      "stroke_width": 2,
                      "curve": "stepline"
                    }
                  ]
                },
                {
                  "type": "custom:apexcharts-card",
                  "graph_span": "24h",
                  "header": {
                    "show": true,
                    "title": "Verbrauch (W)",
                    "show_states": true,
                    "colorize_states": true
                  },
                  "series": [
                    {
                      "entity": "sensor.whirlpool_leistung",
                      "name": "Gesamtleistung",
                      "color": "#FF5722",
                      "stroke_width": 2,
                      "type": "area"
                    }
                  ]
                },
                {
                  "type": "heading",
                  "heading": "Energieverbrauch"
                },
                {
                  "type": "horizontal-stack",
                  "cards": [
                    {
                      "type": "custom:mushroom-template-card",
                      "primary": "{{ states('sensor.spa_heater_energy') | float | round(2) }} kWh",
                      "secondary": "Heizung",
                      "icon": "mdi:fire",
                      "icon_color": "red"
                    },
                    {
                      "type": "custom:mushroom-template-card",
                      "primary": "{{ states('sensor.spa_pump_energy') | float | round(2) }} kWh",
                      "secondary": "Düsen",
                      "icon": "mdi:pump",
                      "icon_color": "blue"
                    },
                    {
                      "type": "custom:mushroom-template-card",
                      "primary": "{{ states('sensor.spa_circulation_pump_energy') | float | round(2) }} kWh",
                      "secondary": "Zirkulation",
                      "icon": "mdi:water-sync",
                      "icon_color": "cyan"
                    }
                  ]
                },
                {
                  "type": "heading",
                  "heading": "Ondilo ICO Sensor"
                },
                {
                  "type": "horizontal-stack",
                  "cards": [
                    {
                      "type": "custom:mushroom-template-card",
                      "primary": "{{ states(\"sensor.whirlpool_batterie\") }} %",
                      "secondary": "Sensor Akku",
                      "icon": "mdi:battery-bluetooth",
                      "icon_color": "{% set b = states('sensor.whirlpool_batterie') | int(100) %} {% if b < 20 %} red {% elif b < 50 %} orange {% else %} green {% endif %}"
                    },
                    {
                      "type": "custom:mushroom-template-card",
                      "primary": "{{ states(\"sensor.whirlpool_rssi\") }} dBm",
                      "secondary": "Signal",
                      "icon": "mdi:wifi",
                      "icon_color": "{% set r = states('sensor.whirlpool_rssi') | int(-100) %} {% if r < -80 %} red {% elif r < -60 %} orange {% else %} green {% endif %}"
                    }
                  ]
                }
              ]
            },
            {
              "type": "grid",
              "cards": [
                {
                  "type": "heading",
                  "heading": "Pflege-Protokoll"
                },
                {
                  "type": "custom:mushroom-template-card",
                  "primary": "{% set last = states('input_datetime.whirlpool_letzte_wasserpflege') %} {% if last == 'unknown' or last == '' %}\n  Noch kein Datum gesetzt\n{% else %}\n  {% set days = ((now().date() - strptime(last[:10], '%Y-%m-%d').date()).days) %}\n  Letzte Pflege: vor {{ days }} Tag{{ 'en' if days != 1 else '' }}\n{% endif %}",
                  "secondary": "{% set last = states('input_datetime.whirlpool_letzte_wasserpflege') %} {% set ph = states('sensor.whirlpool_ph') | float(7.2) %} {% set orp = states('sensor.whirlpool_oxydo_reduktionspotenzial') | float(700) %} {% if last != 'unknown' and last != '' %}\n  {% set days = ((now().date() - strptime(last[:10], '%Y-%m-%d').date()).days) %}\n  {% if days >= 10 %} ⚠️ Pflege überfällig!\n  {% elif days >= 7 %} Pflegerunde empfohlen\n  {% else %} Nächste Pflege in {{ 7 - days }} Tagen\n  {% endif %}\n{% else %}\n  pH + Brom + Wasserrein einmal wöchentlich\n{% endif %} {%- set ph_ok = ph >= 7.0 and ph <= 7.6 %} {%- set orp_ok = orp >= 650 and orp <= 750 %} {{ ' | pH: ✓' if ph_ok else ' | pH: ⚠️ ' ~ ph | round(1) }} {{ ' | ORP: ✓' if orp_ok else ' | ORP: ⚠️ ' ~ orp | round(0) ~ ' mV' }}",
                  "icon": "mdi:water-check",
                  "icon_color": "{% set last = states('input_datetime.whirlpool_letzte_wasserpflege') %} {% set ph = states('sensor.whirlpool_ph') | float(7.2) %} {% set orp = states('sensor.whirlpool_oxydo_reduktionspotenzial') | float(700) %} {% if last == 'unknown' or last == '' %} grey {% elif ph < 6.8 or ph > 7.9 or orp < 550 %} red {% else %}\n  {% set days = ((now().date() - strptime(last[:10], '%Y-%m-%d').date()).days) %}\n  {% if days >= 10 %} red\n  {% elif days >= 7 %} orange\n  {% else %} green {% endif %}\n{% endif %}",
                  "fill_container": true,
                  "grid_options": {
                    "columns": 12,
                    "rows": 2
                  }
                },
                {
                  "type": "custom:mushroom-entity-card",
                  "entity": "input_datetime.whirlpool_letzte_wasserpflege",
                  "name": "Wasserpflege – Datum setzen",
                  "icon": "mdi:calendar-edit"
                },
                {
                  "type": "custom:mushroom-template-card",
                  "primary": "{% set last = states('input_datetime.whirlpool_letzter_kartuschenwechsel') %} {% if last == 'unknown' or last == '' %}\n  Noch kein Datum gesetzt\n{% else %}\n  {% set days = ((now().date() - strptime(last[:10], '%Y-%m-%d').date()).days) %}\n  Letzter Kartuschenwechsel: vor {{ days }} Tag{{ 'en' if days != 1 else '' }}\n{% endif %}",
                  "secondary": "{% set last = states('input_datetime.whirlpool_letzter_kartuschenwechsel') %} {% set intervall = 60 %} {% if last != 'unknown' and last != '' %}\n  {% set days = ((now().date() - strptime(last[:10], '%Y-%m-%d').date()).days) %}\n  {% set rest = intervall - days %}\n  {% if rest <= 0 %} ⚠️ Kartusche wechseln! ({{ days }} Tage alt)\n  {% elif rest <= 14 %} Wechsel in {{ rest }} Tagen empfohlen\n  {% else %} Nächster Wechsel in {{ rest }} Tagen (alle 2 Monate)\n  {% endif %}\n{% else %}\n  Empfehlung: alle 60 Tage bei 1–2× Nutzung/Woche\n{% endif %}",
                  "icon": "mdi:air-filter",
                  "icon_color": "{% set last = states('input_datetime.whirlpool_letzter_kartuschenwechsel') %} {% if last == 'unknown' or last == '' %} grey {% else %}\n  {% set days = ((now().date() - strptime(last[:10], '%Y-%m-%d').date()).days) %}\n  {% if days >= 60 %} red\n  {% elif days >= 46 %} orange\n  {% else %} green {% endif %}\n{% endif %}",
                  "fill_container": true,
                  "grid_options": {
                    "columns": 12,
                    "rows": 1
                  }
                },
                {
                  "type": "custom:mushroom-entity-card",
                  "entity": "input_datetime.whirlpool_letzter_kartuschenwechsel",
                  "name": "Kartuschenwechsel – Datum setzen",
                  "icon": "mdi:calendar-edit"
                },
                {
                  "type": "custom:mushroom-template-card",
                  "primary": "{% set last = states('input_datetime.whirlpool_letzter_wasserwechsel') %} {% if last == 'unknown' or last == '' %}\n  Noch kein Datum gesetzt\n{% else %}\n  {% set days = ((now().date() - strptime(last[:10], '%Y-%m-%d').date()).days) %}\n  Letzter Wasserwechsel: vor {{ days }} Tag{{ 'en' if days != 1 else '' }}\n{% endif %}",
                  "secondary": "{% set last = states('input_datetime.whirlpool_letzter_wasserwechsel') %} {% set intervall = 120 %} {% if last != 'unknown' and last != '' %}\n  {% set days = ((now().date() - strptime(last[:10], '%Y-%m-%d').date()).days) %}\n  {% set rest = intervall - days %}\n  {% if rest <= 0 %} ⚠️ Wasserwechsel überfällig! ({{ days }} Tage alt)\n  {% elif rest <= 21 %} Wasserwechsel in {{ rest }} Tagen planen\n  {% else %} Nächster Wechsel in {{ rest }} Tagen (alle 4 Monate)\n  {% endif %}\n{% else %}\n  Empfehlung: alle 4 Monate bei 1–2× Nutzung/Woche\n{% endif %}",
                  "icon": "mdi:water-sync",
                  "icon_color": "{% set last = states('input_datetime.whirlpool_letzter_wasserwechsel') %} {% if last == 'unknown' or last == '' %} grey {% else %}\n  {% set days = ((now().date() - strptime(last[:10], '%Y-%m-%d').date()).days) %}\n  {% if days >= 120 %} red\n  {% elif days >= 99 %} orange\n  {% else %} green {% endif %}\n{% endif %}",
                  "fill_container": true,
                  "grid_options": {
                    "columns": 12,
                    "rows": 1
                  }
                },
                {
                  "type": "custom:mushroom-entity-card",
                  "entity": "input_datetime.whirlpool_letzter_wasserwechsel",
                  "name": "Wasserwechsel – Datum setzen",
                  "icon": "mdi:calendar-edit"
                },
                {
                  "type": "heading",
                  "heading": "Dosierungsempfehlung"
                },
                {
                  "type": "custom:mushroom-template-card",
                  "primary": "Dosierung diese Woche",
                  "secondary": "{% set ph = states('sensor.whirlpool_ph') | float(7.2) %} {% set orp = states('sensor.whirlpool_oxydo_reduktionspotenzial') | float(700) %}\n🧪 pH ({{ ph | round(1) }}): {% if ph >= 7.0 and ph <= 7.6 %} Optimal – nichts nötig. {% elif ph > 7.6 %}\n  pH-Minus: ca. {{ (((ph - 7.6) / 0.1) * 10 / 1.1) | round(0) | int }} g zugeben.\n{% else %}\n  pH-Plus: ca. {{ (((7.0 - ph) / 0.1) * 10) | round(0) | int }} g zugeben.\n{% endif %} Warte 4h, dann nachmessen. |\n💊 Brom ({{ orp | round(0) }} mV): {% if orp >= 650 and orp <= 750 %} Optimal – nichts nötig. {% elif orp > 750 %} Zu hoch – keine Tabletten, Deckel öffnen. {% elif orp < 600 %} 3–4 Tabletten in Dosierschwimmer. {% else %} 1–2 Tabletten nachlegen. {% endif %} |\n🫧 Wasserrein (Bayrol): 10 ml auf 1.500 l wöchentlich zugeben, Pumpe dabei 30 min laufen lassen.",
                  "icon": "mdi:flask-outline",
                  "icon_color": "{% set ph = states('sensor.whirlpool_ph') | float(7.2) %} {% set orp = states('sensor.whirlpool_oxydo_reduktionspotenzial') | float(700) %} {% if ph < 6.8 or ph > 7.9 or orp < 550 %} red {% elif (ph < 7.0 or ph > 7.6) or (orp < 650 or orp > 750) %} orange {% else %} green {% endif %}",
                  "fill_container": true,
                  "grid_options": {
                    "columns": 12,
                    "rows": 4
                  }
                },
                {
                  "type": "custom:mushroom-template-card",
                  "primary": "Nach Wasserwechsel – Erstbefüllung",
                  "secondary": "① 30 g Aktivsauerstoff (Bayrol Soft & Easy) direkt zugeben | ② Pumpe 1h laufen lassen | ③ pH messen & korrigieren (Ziel 7,0–7,6) | ④ Brom-Tabletten in Dosierschwimmer legen | ⑤ Nach 24h nochmals alle Werte prüfen",
                  "icon": "mdi:flask",
                  "icon_color": "blue",
                  "fill_container": true,
                  "grid_options": {
                    "columns": 12,
                    "rows": 3
                  }
                },
                {
                  "type": "custom:mushroom-template-card",
                  "primary": "Wöchentliche Pflege-Checkliste",
                  "secondary": "① pH messen & ggf. korrigieren (Ziel 7,0–7,6) | ② Brom-Tabletten im Dosierschwimmer prüfen & ggf. nachlegen | ③ 10 ml Wasserrein (Bayrol) zugeben | ④ Pumpe mind. 30 min laufen lassen | ⑤ Filtration läuft? (mind. 4–6h/Tag) | ⑥ Abdeckung nach Nutzung schließen",
                  "icon": "mdi:clipboard-check-outline",
                  "icon_color": "teal",
                  "fill_container": true,
                  "grid_options": {
                    "columns": 12,
                    "rows": 3
                  }
                }
              ]
            },
            {
              "type": "grid",
              "cards": [
                {
                  "type": "heading",
                  "heading": "Filterprogramme"
                },
                {
                  "type": "horizontal-stack",
                  "cards": [
                    {
                      "type": "custom:mushroom-select-card",
                      "entity": "select.spa_filter_time_1",
                      "name": "Filterzeit 1",
                      "icon": "mdi:clock-start"
                    },
                    {
                      "type": "custom:mushroom-select-card",
                      "entity": "select.spa_filter_duration_1",
                      "name": "Dauer 1",
                      "icon": "mdi:timer"
                    }
                  ]
                },
                {
                  "type": "horizontal-stack",
                  "cards": [
                    {
                      "type": "custom:mushroom-select-card",
                      "entity": "select.spa_filter_time_2",
                      "name": "Filterzeit 2",
                      "icon": "mdi:clock-start"
                    },
                    {
                      "type": "custom:mushroom-select-card",
                      "entity": "select.spa_filter_duration_2",
                      "name": "Dauer 2",
                      "icon": "mdi:timer"
                    }
                  ]
                },
                {
                  "type": "custom:mushroom-entity-card",
                  "entity": "switch.whirlpool_filterzyklus_2_aktivieren",
                  "name": "Filterzyklus 2 aktiv",
                  "icon": "mdi:filter-check"
                },
                {
                  "type": "heading",
                  "heading": "Zeitpläne & Automatik"
                },
                {
                  "type": "custom:scheduler-card",
                  "include": [
                    "climate.spa_thermostat",
                    "switch.spa_pump",
                    "switch.whirlpool"
                  ],
                  "title": "Whirlpool Automatik"
                }
              ]
            }
          ]
        }
      ]
    }
  }
}