Heat Pump heating automation

I have automated controlling my heat pumps heating control based on the power provided/returned to the grid. I’m controlling the actual heating using thermostats later on, but I’d like to pre-heat water when there’s excess power, and dial back to minimum when there’s not. There’s a single “override” - an input boolean that I turn on when I’m out of home for a longer period - so called “vacation mode”. I’m doing that using heat curve (based on temperature outside set the temperature to heat the water for floor heating). The more power I produce the higher the curve should be, If I start drawing power from grid, the more I decrease it. The higher the return is, the more steps I’m skipping. Right now the automation will go between curve 4 and 13. I’ve written it a long time ago, so there’s a lot of repetition. Is there some way to use variables in it? I’d like to set a different minimal value for when someone’s at home (4) and a different one (say 3) when there’s no one? How else could I streamline it to have less steps?


alias: Pompa ciepła - grzanie
description: ""
triggers:
  - entity_id:
      - sensor.electricity_meter_power_active_phase_2
    for:
      hours: 0
      minutes: 15
      seconds: 0
    below: -1500
    id: "-1500 > Phase 2"
    trigger: numeric_state
  - entity_id:
      - sensor.electricity_meter_power_active_phase_2
    for:
      hours: 0
      minutes: 10
      seconds: 0
    below: -800
    id: " -800 > Phase 2 > -1500  "
    above: -1500
    trigger: numeric_state
  - entity_id:
      - sensor.electricity_meter_power_active_phase_2
    for:
      hours: 0
      minutes: 10
      seconds: 0
    below: -500
    id: "-500 > Phase 2 > -800 "
    above: -800
    trigger: numeric_state
  - entity_id:
      - sensor.electricity_meter_power_active_phase_2
    for:
      hours: 0
      minutes: 10
      seconds: 0
    below: 0
    id: "0 > Phase 2 > -500 "
    above: -500
    trigger: numeric_state
  - entity_id:
      - sensor.electricity_meter_power_active_phase_2
    for:
      hours: 0
      minutes: 10
      seconds: 0
    id: 200 > Phase 2 > 0
    above: 0
    below: 200
    enabled: true
    trigger: numeric_state
  - entity_id:
      - sensor.electricity_meter_power_active_phase_2
    for:
      hours: 0
      minutes: 10
      seconds: 0
    id: 600 > Phase 2 > 200
    above: 200
    enabled: true
    below: 600
    trigger: numeric_state
  - entity_id:
      - sensor.electricity_meter_power_active_phase_2
    for:
      hours: 0
      minutes: 10
      seconds: 0
    id: 1000 > Phase 2 > 600
    above: 600
    enabled: true
    below: 1000
    trigger: numeric_state
  - entity_id:
      - sensor.electricity_meter_power_active_phase_2
    for:
      hours: 0
      minutes: 10
      seconds: 0
    id: Phase 2 > 1000
    above: 1000
    enabled: true
    trigger: numeric_state
  - alias: Inverter Error
    entity_id:
      - sensor.t_series_inverter_mode
    id: inverter_error
    trigger: state
    to: Error
  - alias: Inverter Offline
    entity_id:
      - sensor.t_series_inverter_mode
    id: inverter_offline
    trigger: state
    to: Offline
conditions:
  - condition: and
    conditions:
      - condition: not
        conditions:
          - condition: state
            entity_id: input_boolean.tryb_wakacji
            state: "on"
        alias: Vacation mode off
      - condition: state
        entity_id: switch.allow_heating_47371
        state: "on"
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - "-1500 > Phase 2"
        sequence:
          - alias: Increase by 4 until it hits 13
            if:
              - alias: Increase heat curve
                condition: numeric_state
                entity_id: number.heat_curve_s1_47007
                below: 10
            then:
              - target:
                  entity_id:
                    - number.heat_curve_s1_47007
                data:
                  amount: 4
                action: number.increment
            else:
              - device_id: 72ba90db6cc35b385aed530f704fd270
                domain: number
                entity_id: e6462d287620782a29712ebf7f8b6341
                type: set_value
                value: 13
      - conditions:
          - condition: trigger
            id:
              - " -800 > Phase 2 > -1500  "
        sequence:
          - alias: Increase by 3 until it hits 13
            if:
              - alias: Increase heat curve
                condition: numeric_state
                entity_id: number.heat_curve_s1_47007
                below: 11
            then:
              - target:
                  entity_id:
                    - number.heat_curve_s1_47007
                data:
                  amount: 3
                action: number.increment
            else:
              - device_id: 72ba90db6cc35b385aed530f704fd270
                domain: number
                entity_id: e6462d287620782a29712ebf7f8b6341
                type: set_value
                value: 13
      - conditions:
          - condition: trigger
            id:
              - "-500 > Phase 2 > -800 "
        sequence:
          - alias: Increase by 2 until it hits 13
            if:
              - alias: Increase heat curve
                condition: numeric_state
                entity_id: number.heat_curve_s1_47007
                below: 12
            then:
              - target:
                  entity_id: number.heat_curve_s1_47007
                data:
                  amount: 2
                action: number.increment
            else:
              - device_id: 72ba90db6cc35b385aed530f704fd270
                domain: number
                entity_id: e6462d287620782a29712ebf7f8b6341
                type: set_value
                value: 13
                enabled: true
      - conditions:
          - condition: trigger
            id:
              - "0 > Phase 2 > -500 "
        sequence:
          - alias: Increase by 1 until it hits 13
            if:
              - alias: Increase heat curve
                condition: numeric_state
                entity_id: number.heat_curve_s1_47007
                below: 12
            then:
              - target:
                  entity_id: number.heat_curve_s1_47007
                data:
                  amount: 1
                action: number.increment
            else:
              - device_id: 72ba90db6cc35b385aed530f704fd270
                domain: number
                entity_id: e6462d287620782a29712ebf7f8b6341
                type: set_value
                value: 13
                enabled: true
      - conditions:
          - condition: trigger
            id:
              - 200 > Phase 2 > 0
        sequence:
          - alias: Decrease by 1 until it hits 4
            if:
              - alias: Decrease heat curve
                condition: numeric_state
                entity_id: number.heat_curve_s1_47007
                above: 4
            then:
              - target:
                  entity_id:
                    - number.heat_curve_s1_47007
                data:
                  amount: 1
                action: number.decrement
            else:
              - device_id: 72ba90db6cc35b385aed530f704fd270
                domain: number
                entity_id: e6462d287620782a29712ebf7f8b6341
                type: set_value
                value: 4
                enabled: true
      - conditions:
          - condition: trigger
            id:
              - 600 > Phase 2 > 200
        sequence:
          - alias: Decrease by 2 until it hits 4
            if:
              - alias: Decrease heat curve
                condition: numeric_state
                entity_id: number.heat_curve_s1_47007
                above: 6
            then:
              - target:
                  entity_id:
                    - number.heat_curve_s1_47007
                data:
                  amount: 2
                action: number.decrement
            else:
              - device_id: 72ba90db6cc35b385aed530f704fd270
                domain: number
                entity_id: e6462d287620782a29712ebf7f8b6341
                type: set_value
                value: 4
                enabled: true
      - conditions:
          - condition: trigger
            id:
              - 1000 > Phase 2 > 600
        sequence:
          - alias: Decrease by 3 until it hits 4
            if:
              - alias: Decrease heat curve
                condition: numeric_state
                entity_id: number.heat_curve_s1_47007
                above: 6.8
            then:
              - target:
                  entity_id:
                    - number.heat_curve_s1_47007
                data:
                  amount: 3
                action: number.decrement
            else:
              - device_id: 72ba90db6cc35b385aed530f704fd270
                domain: number
                entity_id: e6462d287620782a29712ebf7f8b6341
                type: set_value
                value: 4
                enabled: true
      - conditions:
          - condition: trigger
            id:
              - inverter_error
              - inverter_offline
              - Phase 2 > 1000
        sequence:
          - device_id: 72ba90db6cc35b385aed530f704fd270
            domain: number
            entity_id: e6462d287620782a29712ebf7f8b6341
            type: set_value
            value: 4
            enabled: true
variables:
  min_heat_curve_auto: 4
  max_heat_curve_auto: 1
mode: single