Untitled

 avatar
unknown
plain_text
10 months ago
14 kB
15
Indexable
###############################################################
# 🧠 Adaptive Self-Learning Floor Heating Controller
# Room: Sebi
# Entity: climate.incalzire_d_sebi
# Temperature source: climate attribute 'current_temperature'
# Notifications: WhatsApp
###############################################################

template:
  ###############################################################
  # 1️⃣ Track heating start / stop timestamps
  ###############################################################
  - trigger:
      - platform: state
        entity_id: climate.incalzire_d_sebi
        attribute: hvac_action
    sensor:
      - name: "Sebi Heating Start Time"
        state: >
          {% if trigger.to_state.attributes.hvac_action == 'heating' %}
            {{ now().isoformat() }}
          {% else %}
            {{ this.state }}
          {% endif %}
      - name: "Sebi Heating Stop Time"
        state: >
          {% if trigger.to_state.attributes.hvac_action == 'idle' %}
            {{ now().isoformat() }}
          {% else %}
            {{ this.state }}
          {% endif %}

  ###############################################################
  # 2️⃣ Learn system behaviour: delay + overshoot
  ###############################################################
  - sensor:
      - name: "Sebi Heating Delay"
        unit_of_measurement: "min"
        icon: mdi:timer-outline
        state: >
          {% set start = states('sensor.sebi_heating_start_time') | as_datetime %}
          {% set temp = state_attr('climate.incalzire_d_sebi','current_temperature') | float %}
          {% set prev = state_attr('sensor.sebi_heating_delay', 'last_temp') | float(0) %}
          {% set delay = states('sensor.sebi_heating_delay') | float(60) %}
          {% if temp > prev + 0.1 and start %}
            {% set minutes = ((now() - start).total_seconds() / 60) | float %}
            {{ (delay + minutes) / 2 }}
          {% else %}
            {{ delay }}
          {% endif %}
        attributes:
          last_temp: "{{ state_attr('climate.incalzire_d_sebi','current_temperature') | float }}"

      - name: "Sebi Heating Overshoot"
        unit_of_measurement: "°C"
        icon: mdi:chart-line
        state: >
          {% set stop = states('sensor.sebi_heating_stop_time') | as_datetime %}
          {% set temp_now = state_attr('climate.incalzire_d_sebi','current_temperature') | float %}
          {% set prev_max = state_attr('sensor.sebi_heating_overshoot', 'max_temp') | float(temp_now) %}
          {% set overshoot = states('sensor.sebi_heating_overshoot') | float(0.4) %}
          {% if stop %}
            {% if temp_now > prev_max %}
              {% set new_overshoot = temp_now - 23.0 %}
              {{ (overshoot + new_overshoot) / 2 }}
            {% else %}
              {{ overshoot }}
            {% endif %}
          {% else %}
            {{ overshoot }}
          {% endif %}
        attributes:
          max_temp: "{{ state_attr('climate.incalzire_d_sebi','current_temperature') | float }}"

  ###############################################################
  # 3️⃣ Adaptive thresholds (based on learned delay + overshoot)
  ###############################################################
  - sensor:
      - name: "Sebi Adaptive Heat Start"
        unit_of_measurement: "°C"
        state: >
          {% set target = states('input_number.sebi_day_target') | float(23.0) %}
          {% set delay = states('sensor.sebi_heating_delay') | float(60) %}
          {% set adjust = (delay / 180) | float %}
          {{ (target - 0.2 - adjust) | round(2) }}

      - name: "Sebi Adaptive Heat Stop"
        unit_of_measurement: "°C"
        state: >
          {% set target = states('input_number.sebi_day_target') | float(23.0) %}
          {% set overshoot = states('sensor.sebi_heating_overshoot') | float(0.4) %}
          {{ (target + 0.2 - overshoot) | round(2) }}

###############################################################
# 4️⃣ Helper Inputs – Day/Night Target Temperatures
###############################################################
input_number:
  sebi_day_target:
    name: "Sebi Day Target"
    min: 20
    max: 24
    step: 0.1
    unit_of_measurement: "°C"
    initial: 23.0
  sebi_night_target:
    name: "Sebi Night Target"
    min: 18
    max: 23
    step: 0.1
    unit_of_measurement: "°C"
    initial: 21.5

###############################################################
# 5️⃣ Binary Sensor – Night Detection
###############################################################
binary_sensor:
  - platform: template
    sensors:
      sebi_is_night:
        friendly_name: "Night Time for Sebi"
        value_template: >
          {% set hour = now().hour %}
          {{ hour >= 22 or hour < 7 }}

###############################################################
# 6️⃣ Adaptive Target Adjust Automation
###############################################################
automation:
  - alias: Adaptive Sebi Target Adjust
    trigger:
      - platform: state
        entity_id: binary_sensor.sebi_is_night
    action:
      - service: climate.set_temperature
        target:
          entity_id: climate.incalzire_d_sebi
        data:
          temperature: >
            {% if is_state('binary_sensor.sebi_is_night', 'on') %}
              {{ states('input_number.sebi_night_target') }}
            {% else %}
              {{ states('input_number.sebi_day_target') }}
            {% endif %}
      - service: notify.whatsapp
        data:
          message: >
            🔧 Adaptive Target Update – Sebi
            Target temp: {% if is_state('binary_sensor.sebi_is_night','on') %}
            {{ states('input_number.sebi_night_target') }}
            {% else %}
            {{ states('input_number.sebi_day_target') }}
            {% endif %}°C

###############################################################
# 7️⃣ Main Predictive Heating Control Automation
###############################################################
  - alias: Adaptive Floor Heating Control - Sebi
    mode: restart
    trigger:
      - platform: state
        entity_id: climate.incalzire_d_sebi
        attribute: current_temperature
    variables:
      start_temp: "{{ states('sensor.sebi_adaptive_heat_start') | float }}"
      stop_temp: "{{ states('sensor.sebi_adaptive_heat_stop') | float }}"
      temp_now: "{{ state_attr('climate.incalzire_d_sebi','current_temperature') | float }}"
    action:
      - choose:
          - conditions:
              - condition: template
                value_template: "{{ temp_now < start_temp }}"
            sequence:
              - service: climate.set_hvac_mode
                target:
                  entity_id: climate.incalzire_d_sebi
                data:
                  hvac_mode: heat
              - service: notify.whatsapp
                data:
                  message: >
                    🔥 Heating ON – Sebi Room
                    Temp {{ temp_now }}°C < start {{ start_temp }}°C
                    Delay: {{ states('sensor.sebi_heating_delay') | round(1) }} min
                    Overshoot: {{ states('sensor.sebi_heating_overshoot') | round(2) }}°C
          - conditions:
              - condition: template
                value_template: "{{ temp_now > stop_temp }}"
            sequence:
              - service: climate.set_hvac_mode
                target:
                  entity_id: climate.incalzire_d_sebi
                data:
                  hvac_mode: 'off'
              - service: notify.whatsapp
                data:
                  message: >
                    🧊 Heating OFF – Sebi Room
                    Temp {{ temp_now }}°C > stop {{ stop_temp }}°C
                    Delay: {{ states('sensor.sebi_heating_delay') | round(1) }} min
                    Overshoot: {{ states('sensor.sebi_heating_overshoot') | round(2) }}°C

###############################################################
# 8️⃣ Debug Learning Event Notifications
###############################################################
  - alias: Debug Learning Events - Sebi
    mode: queued
    trigger:
      - platform: state
        entity_id:
          - sensor.sebi_heating_delay
          - sensor.sebi_heating_overshoot
    condition:
      - condition: template
        value_template: "{{ trigger.to_state.state not in ['unknown','unavailable','none'] }}"
    action:
      - service: notify.whatsapp
        data:
          message: >
            📈 Learning Update – Sebi Heating
            {{ trigger.entity_id }} updated to {{ trigger.to_state.state }}
            (previous: {{ trigger.from_state.state if trigger.from_state else 'n/a' }})



title: Adaptive Heating - Sebi
path: adaptive-heating-sebi
views:
  - title: Adaptive Heating - Sebi
    path: adaptive-heating-sebi
    badges: []
    cards:

      # 1️⃣ Main Temperature + Adaptive Threshold Graph
      - type: custom:mini-graph-card
        name: Sebi Adaptive Heating - Learning Curve
        entities:
          - entity: climate.incalzire_d_sebi
            attribute: current_temperature
            name: Room Temp
          - entity: sensor.sebi_adaptive_heat_start
            name: Start Threshold
            color: red
            show_fill: false
          - entity: sensor.sebi_adaptive_heat_stop
            name: Stop Threshold
            color: blue
            show_fill: false
          - entity: climate.incalzire_d_sebi
            attribute: hvac_action
            name: Heating State
            color: orange
        line_width: 2
        hours_to_show: 12
        points_per_hour: 6
        show:
          labels: true
          fill: false
          icon: false
        animate: true

      # 2️⃣ Learning Metrics Card
      - type: entities
        title: Adaptive Learning Metrics - Sebi
        entities:
          - entity: sensor.sebi_heating_delay
            name: Delay (min)
          - entity: sensor.sebi_heating_overshoot
            name: Overshoot (°C)
          - entity: sensor.sebi_adaptive_heat_start
            name: Current Start Threshold (°C)
          - entity: sensor.sebi_adaptive_heat_stop
            name: Current Stop Threshold (°C)
          - entity: climate.incalzire_d_sebi
            name: Climate Entity

      # 3️⃣ Visual Training Progress
      - type: custom:mushroom-template-card
        primary: Adaptive Learning Progress
        icon: mdi:brain
        layout: vertical
        multiline_secondary: true
        secondary: >
          {% set delay = states('sensor.sebi_heating_delay') | float(0) %}
          {% set overshoot = states('sensor.sebi_heating_overshoot') | float(0) %}
          {% if delay > 20 and overshoot > 0.2 %}
          🧠 Learning stabilized  
          - Delay: {{ delay | round(0) }} min  
          - Overshoot: {{ overshoot | round(2) }} °C
          {% else %}
          ⏳ Still learning...  
          - Delay: {{ delay | round(0) }} min  
          - Overshoot: {{ overshoot | round(2) }} °C
          {% endif %}
        icon_color: >
          {% set delay = states('sensor.sebi_heating_delay') | float(0) %}
          {% if delay > 20 %}
            green
          {% else %}
            amber
          {% endif %}
        tap_action:
          action: none

      # 4️⃣ Quick Controls
      - type: entities
        title: Quick Controls - Sebi Room
        entities:
          - entity: climate.incalzire_d_sebi
          - entity: input_number.sebi_day_target
          - entity: input_number.sebi_night_target
          - entity: binary_sensor.sebi_is_night


###############################################################
# Daily Summary Notification
###############################################################
  - alias: Sebi Adaptive Heating Daily Summary
    trigger:
      - platform: time
        at: "21:00:00"
    action:
      - service: notify.whatsapp
        data:
          message: >
            📅 Daily Summary – Sebi Adaptive Heating
            Current Room Temp: {{ state_attr('climate.incalzire_d_sebi','current_temperature') | round(1) }}°C
            Day Target: {{ states('input_number.sebi_day_target') }}°C
            Night Target: {{ states('input_number.sebi_night_target') }}°C
            Adaptive Start Threshold: {{ states('sensor.sebi_adaptive_heat_start') }}°C
            Adaptive Stop Threshold: {{ states('sensor.sebi_adaptive_heat_stop') }}°C
            Delay Learned: {{ states('sensor.sebi_heating_delay') | round(1) }} min
            Overshoot Learned: {{ states('sensor.sebi_heating_overshoot') | round(2) }}°C
###############################################################
# Weekly Summary Notification
###############################################################
  - alias: Sebi Adaptive Heating Weekly Summary
    trigger:
      - platform: time
        # Sunday at 21:00
        weekday: 6
        at: "21:00:00"
    action:
      - service: notify.whatsapp
        data:
          message: >
            📊 Weekly Summary – Sebi Adaptive Heating
            Current Room Temp: {{ state_attr('climate.incalzire_d_sebi','current_temperature') | round(1) }}°C
            Day Target: {{ states('input_number.sebi_day_target') }}°C
            Night Target: {{ states('input_number.sebi_night_target') }}°C
            Adaptive Start Threshold: {{ states('sensor.sebi_adaptive_heat_start') }}°C
            Adaptive Stop Threshold: {{ states('sensor.sebi_adaptive_heat_stop') }}°C
            Delay Learned: {{ states('sensor.sebi_heating_delay') | round(1) }} min
            Overshoot Learned: {{ states('sensor.sebi_heating_overshoot') | round(2) }}°C
            This week’s updates: 
            - Heating ON/OFF events, delay & overshoot learned during week (check dashboard for details)


Editor is loading...
Leave a Comment