Logical automation problem for heating water, when enough solar energy

Hello,

I have a solar energy (Fronius). And I have a heat patrone for my warm water.
I can switch on/off 3 steps of this heat patrone via KNX (1 to 3 kw).

I built the following logic:

Calculate the mean solar overflow (within 10 minutes).

Then i have the following ON rules:

Heat1: When solar overflow is > 1000w switch on heat1.
Heat2: When solar overflow is > 1000w AND heat1 is ON switch on heat2.
Heat3: When solar overflow is > 1000w AND heat2 is ON switch on heat3.

For OFF i have the following rules:

Heat3: When solar overflow is < 100w switch off heat3.
Heat2: When solar overflow is < 100w AND heat3 is OFF switch off heat2.
Heat1: When solar overflow is < 100w AND heat2 is OFF switch off heat1.

Now i have the following problem: My trigger is always, when the solar overflow (mean) entity gets bigger or lower my set value.

But now it can happen that there is solar overflow < 100w. Now Heat3 switches off.
If now the solar overflow will not gets bigger than 100w for a small time, then the rule for heat 2 and heat1 won´t trigger again, and this 2 heating stay online.

I hope you understand my problem, how can i solve this? I think i need another trigger?

You can use a delay to add waiting time after one of these steps just ran.

Additionally your hysteresis is negative. I’d use more. If your heat1 uses 1000W and you turn on at overflow 1000 → your overflow is 0 now. Your turn-off rule immediately applies.

Fronius inverters have quite nice internal logics for these kind of stuff. I use a KNX binary sensor to read the IOs of my inverters and trigger some KNX switch actuators based on that (KNX to transport the signal through the house). That makes it independent of HA, but still supervisable through KNX.

Hello,

Thanks a lot for your answer. The delay won´t fix my problem.
Since I use the mean solar overflow over 10 minutes, it can happen that Heat3 switches off, and the solar overflow won´t get over the 100w again, and then the other 2 stays on, because automation is only triggered when the overflow gets below 100w.

Ah, I see what you mean. You can change the trigger to not use numeric_state with below (if you use this now), but only state. This will not only trigger when the value is crossed, but on every change. You can then evaluate if it is below or above a value in the action part.

If you need real periodic evaluation you could just use a time trigger (maybe additionally). But I think its very unlikely that that value stays exactly the same for a longer time period.
Or consider not using a calculated mean value, but a more often updated one. You can’t look in the future anyway :crystal_ball::rofl:

I use this in my solar automation (thermal, not photovoltaic).

trigger:
  - platform: state
    entity_id:
      - sensor.solar_vorlauftemp_kollektor
      - sensor.solar_vorlauftemp_keller
      - sensor.hof_boiler_unten
condition: []
action:
  - choose:
      - conditions:
          - condition: numeric_state
            entity_id: sensor.hof_boiler_unten
            above: 70
        sequence:
          - service: switch.turn_off
            target:
              entity_id: switch.pumpe_solaranlage
            data: {}
          - delay: "0:10:00"
...

Hello,

Thanks a lot, this was exactly what i was looking for.

One last question: Should i use the the calculated mean value? Or whats the alternative? The live value with a delay, like you did?

Using a mean value is always a look in the past. You can’t predict if anyone will start cooking a meal just when your automation starts anyway.

Id use some leeway in the turn on power - like when it uses 1000W - start at ~1200W and turn off at 0W.
A delay helps to not switch too often - to not wear out the Relais or heater.

Okay, so using the leeway. And additional a delay?

If there more than 1200w wait 5 minutes and then turn on?

What happens if another trigger happens in this time? Can the delay lead to problems?
Like we are over 1200w, he waits 5 minutes and switches on. But in the meantime we are already below 1200w, and the off switch triggers?

No, turn on immediately and then wait 5 minutes before evaluating the next trigger.

You can specify that with mode: - see automation documentation for how the modes work.

Or just try without delay and see if it switches fast (like on - off every 30 seconds) or not.

Thanks so much.

One last question: “Wait 5 minutes before evaluating next trigger” - isn´t that exactly the delay?
Like when the automation1 switches on the first heating, and aftert this i set the delay?

Or how do i say, after heating1 is on, wait 5 minutes till evaluating next rule?

Right. That’s what the delay does.
In the Fronius inverters logic you can set a “minimum on time” for its IO ports - this is somewhat similar I think.

Tried this now, but does not work for me.

Automation1: If power is more than 1000w, switch on heating1. Delay 5 minutes.

The Automation2 (Power off, if less than 10w), with the trigger if power value changes is triggered always, and its not waiting the 5 minutes.

So its like because i have 2 different automation rules? Rule 2, won´t wait till rule1 waited the 5 min delay?

Did you do 2 separate automations? They would be independent.
Mind if you paste the yaml here?

Yeah, actually i have 6 automations!

Heating1 ON
Heating2 ON
Heating 3 ON
Heating1 OFF
Heating2 OFF
Heating3 OFF

You mean i can have all of this rules in one automation?

Heating1 ON:

alias: Warmwasser 1 ON
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.solar_uberschuss_3
    above: 800
condition: []
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.warmwasser_e1
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
mode: single

Heating1 OFF:

alias: Warmwasser 1 OFF
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.test_solar_2
condition:
  - condition: numeric_state
    entity_id: sensor.test_solar_2
    below: 50
  - condition: state
    entity_id: switch.warmwasser_e2
    state: "off"
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.warmwasser_e1
mode: single

Heating2 ON:

alias: Warmwasser 2 ON
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.solar_uberschuss_gemittelt
    above: 1000
condition:
  - condition: state
    entity_id: switch.warmwasser_e1
    state: "on"
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.warmwasser_e2
mode: single

Sure. With some choose: or if: then: you can probably do this in one. See my example above - you can add a and condition to evaluate if heat_1 or heat_2 already runs. Or you use templates.

Not sure if it gets easier to read though :rofl:
Another way would be to activate / deactivate the upper level automation from a lower level one. So if heat_1 is ON, delay (or not) and then activate heat_2 automation. Same for heat_3 from heat_2. You’d have to make sure that it is always turned off when an automation gets deactivated then :thinking:
I’d probably do ON and OFF in the same automation in any way.

Hello,

I tried now your idea. With your idea, i need 2 automations right? One for on switching and one for off?

Here is my automation for switching on, may you can have look please?

alias: Warmwasser 1 ON
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.solar_uberschuss_3
    above: 800
condition: []
action:
  - if:
      - condition: state
        entity_id: switch.warmwasser_e2
        state: "off"
      - condition: state
        entity_id: switch.warmwasser_e3
        state: "off"
      - condition: state
        entity_id: switch.warmwasser_e1
        state: ""
    then:
      - service: switch.turn_on
        data: {}
        target:
          entity_id: switch.warmwasser_e1
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - if:
      - condition: state
        entity_id: switch.warmwasser_e1
        state: "on"
      - condition: state
        entity_id: switch.warmwasser_e3
        state: "off"
      - condition: state
        entity_id: switch.warmwasser_e2
        state: "off"
    then:
      - service: switch.turn_on
        data: {}
        target:
          entity_id: switch.warmwasser_e2
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - if:
      - condition: state
        entity_id: switch.warmwasser_e1
        state: "on"
      - condition: state
        entity_id: switch.warmwasser_e2
        state: "on"
      - condition: state
        entity_id: switch.warmwasser_e3
        state: "off"
    then:
      - service: switch.turn_on
        data: {}
        target:
          entity_id: switch.warmwasser_e3
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
mode: single

It can be done in one too.

trigger:
  - platform: state
    entity_id:
      - sensor.solar_uberschuss_3
condition: []
action:
  - choose:
      - conditions:
          - condition: numeric_state
            entity_id: sensor.solar_uberschuss_3
            above: 800
        sequence:
          # your on sequence here
      - conditions:
          - condition: numeric_state
            entity_id: sensor.solar_uberschuss_3
            below: 20
        sequence:
          # your off sequence here

with templates this can be done even more compact / complex :rofl:
Eg. set a variable to “on” or “off” depending on the state of sensor.solar_uberschuss_3 or use a variable for which switch should be switched.
Have a look here for some examples Best Practices for ON/OFF within the same Automation

Thanks a lot, now my final try:

alias: Warmwasser Gesamt
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.solar_uberschuss_3
condition: []
action:
  - choose:
      - conditions:
          - condition: numeric_state
            entity_id: sensor.solar_uberschuss_3
            above: 1000
        sequence:
          - if:
              - condition: state
                entity_id: switch.warmwasser_e1
                state: "off"
              - condition: state
                entity_id: switch.warmwasser_e2
                state: "off"
              - condition: state
                entity_id: switch.warmwasser_e3
                state: "off"
            then:
              - service: switch.turn_on
                data: {}
                target:
                  entity_id: switch.warmwasser_e1
              - delay:
                  hours: 0
                  minutes: 5
                  seconds: 0
                  milliseconds: 0
          - if:
              - condition: state
                entity_id: switch.warmwasser_e1
                state: "on"
              - condition: state
                entity_id: switch.warmwasser_e2
                state: "off"
              - condition: state
                entity_id: switch.warmwasser_e3
                state: "off"
            then:
              - service: switch.turn_on
                data: {}
                target:
                  entity_id: switch.warmwasser_e2
              - delay:
                  hours: 0
                  minutes: 5
                  seconds: 0
                  milliseconds: 0
          - if:
              - condition: state
                entity_id: switch.warmwasser_e1
                state: "on"
              - condition: state
                entity_id: switch.warmwasser_e2
                state: "on"
              - condition: state
                entity_id: switch.warmwasser_e3
                state: "off"
            then:
              - service: switch.turn_on
                data: {}
                target:
                  entity_id: switch.warmwasser_e3
              - delay:
                  hours: 0
                  minutes: 5
                  seconds: 0
                  milliseconds: 0
      - conditions:
          - condition: numeric_state
            entity_id: sensor.solar_uberschuss_3
            below: 100
        sequence:
          - if:
              - condition: state
                entity_id: switch.warmwasser_e1
                state: "on"
              - condition: state
                entity_id: switch.warmwasser_e2
                state: "on"
              - condition: state
                entity_id: switch.warmwasser_e3
                state: "on"
            then:
              - service: switch.turn_off
                data: {}
                target:
                  entity_id: switch.warmwasser_e3
              - delay:
                  hours: 0
                  minutes: 5
                  seconds: 0
                  milliseconds: 0
          - if:
              - condition: state
                entity_id: switch.warmwasser_e3
                state: "off"
              - condition: state
                entity_id: switch.warmwasser_e2
                state: "on"
              - condition: state
                entity_id: switch.warmwasser_e1
                state: "on"
            then:
              - service: switch.turn_off
                data: {}
                target:
                  entity_id: switch.warmwasser_e2
              - delay:
                  hours: 0
                  minutes: 5
                  seconds: 0
                  milliseconds: 0
          - if:
              - condition: state
                entity_id: switch.warmwasser_e1
                state: "on"
              - condition: state
                entity_id: switch.warmwasser_e2
                state: "off"
              - condition: state
                entity_id: switch.warmwasser_e3
                state: "off"
            then:
              - service: switch.turn_off
                data: {}
                target:
                  entity_id: switch.warmwasser_e1
              - delay:
                  hours: 0
                  minutes: 5
                  seconds: 0
                  milliseconds: 0
mode: single

1 Like