Hysteresis in HA automations?

mrb13676

Well-Known Member
Joined
Sep 30, 2007
Messages
216
Reaction score
51
Struggling a bit converting a Node Red automation for my geyser.
The behaviour I want is :
  • Evaluate the time for the windows where I want the geyser to operate
  • Check the temperature. If <50 then turn geyser on. If >55 turn geyser off
  • BUT - If between the range of 55 and 50 it must kepp the geyser on if the range is entered from below. If the range is entered from above... i.e the temp dropping from above 55 then it must only turn on again when temp drops below 50.
I'm trying to stop the geyser from turning on and off at 55deg the whole day.
Is this hysteresis type behaviour possible with automations? The code below is as far as I've got at the moment. I have a helper which evaluates the schedule and outputs on or off

YAML:
mode: single
trigger:
  - platform: template
    value_template: "{{ states('schedule.geyser_windows') == 'on' }}"
    for:
      hours: 0
      minutes: 1
      seconds: 0
condition: []
action:
  - choose:
      - conditions:
          - condition: numeric_state
            entity_id: switch.sonoff_******
            below: 50.1
        sequence:
          - service: switch.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: switch.<gesyerswitch>
      - conditions:
          - condition: numeric_state
            entity_id: switch.sonoff_******
            above: 50
            below: 55.1
        sequence:
          - if:
              - condition: state
                entity_id: ""
                state: ""
            then:
              - type: turn_on
      
                entity_id: *********
                domain: switch
      - conditions:
          - condition: numeric_state
            entity_id: switch.sonoff_*******
            above: 55
        sequence:
          - service: switch.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: switch.sonoff.******
 
Hi, just typing some ideas from memory, did not validate syntax.
How about 2 triggers, start & stop, then a choose on trigger-id to turn the switch on or off

Code:
trigger:
  - platform: template
    value_template: >-
      {% set temp = states('sensor.geyser_temperature')|float(0) %}
      {% set sw = states('switch.geyser') %}
      {% set window = states('schedule.geyser_windows') %}
      {% if window == 'on' and sw == 'off' and temp < 50.1 %}
      true
      {% else %}
      false
      {% endif %}
    id: start
  - platform: template
    value_template: >-
      {% set temp = states('sensor.geyser_temperature')|float(0) %}
      {% set sw = states('switch.geyser') %}
      {% set window = states('schedule.geyser_windows') %}
      {% if (window == 'off' and sw == 'on') or temp > 55 %}
      true
      {% else %}
      false
      {% endif %}
    id: stop
 
I love programming...
It's unfortunate that I usually fall asleep when I start coding and the 'syntax errors' start popping up.

God help me.
 
Hi, just typing some ideas from memory, did not validate syntax.
How about 2 triggers, start & stop, then a choose on trigger-id to turn the switch on or off
This was a great start....

unfortunately it the templates never seem to trigger? Could someone check my code and see if it should work? (at the moment I'm just trying to get it to send a notification to my phone so the clan of the long hair do not get frustrated with not having hot water...

YAML:
trigger:
  - platform: template
    value_template: >-
      {% set temp = states('sensor.geysertemp')|float(0) %}
      {% set sw = states('switch.geyserlocaltuyaswitch') %}   
      {% set window = states('schedule.geyser_windows') %}  
      {% set target_temp = states('input_number.geyser_setpoint_ui') %} 

      {% if window == 'on' and sw == 'off' and temp < (target_temp + 0.1) %}
        true
      {% else %}
        false
      {% endif %}
    id: start

  - platform: template
    value_template: >-
      {% set temp = states('sensor.geysertemp')|float(0) %} 
      {% set sw = states('switch.geyserlocaltuyaswitch') %}  
      {% set target_temp = states('input_number.geyser_setpoint_ui') %} 

      {% if (window == 'off' and sw == 'on') or temp > target_temp %}
        true
      {% else %}
        false
      {% endif %}
    id: stop
condition:
  - condition: template
    value_template: ""
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - start
        sequence:
          - service: notify.mobile_app_mikes_phone
            metadata: {}
            data:
              title: GEYSER TURNS ON
              message: Hello
              data:
                push:
                  sound: null
      - conditions:
          - condition: trigger
            id:
              - stop
        sequence:
          - service: notify.mobile_app_mikes_phone
            metadata: {}
            data:
              title: geyser turns off
              message: Hello
              data:
                push:
                  sound: null
 
Hi, maybe jus convert your 2 target_temp's to float.
Code:
{% set target_temp = states('input_number.geyser_setpoint_ui')|float(0) %}

If that does not help, put all in developer-tools, templates to look at the values. For example:
Code:
      {% set temp = states('sensor.geysertemp')|float(0) %}
      {% set sw = states('switch.geyserlocaltuyaswitch') %}   
      {% set window = states('schedule.geyser_windows') %} 
      {% set target_temp = states('input_number.geyser_setpoint_ui') %}
      {{ temp }}
      {{ sw }}
      {{ window }}
      {{ target_temp }}
 
Sonoff TH16.
Then remember to compensate for no reading when it inevitably fails so that it doesn’t boil over since you have no thermostat.

Hope you aren’t using it as the relay too, but at least then when it does there won’t be any power going through it.
 
To answer the question I wouldn’t bother with templates or anything of the sort.

Set the two different temperatures as your triggers with above and below values and give them trigger ID’s.

Then under actions use the trigger ID in a Choose action and set the time conditions accordingly.

If you had multiple time conditions in mind just add more actions for the same trigger ID with a different time condition.
 
Then remember to compensate for no reading when it inevitably fails so that it doesn’t boil over since you have no thermostat.

Hope you aren’t using it as the relay too, but at least then when it does there won’t be any power going through it.
No. The TH16 is only the source for the temperature. The geyser relay is a separate (on the DB) CBI smart breaker rated appropriately. And the geyser thermostat is still in the equation too but set significantly higher so it only acts as failsafe.
 
No. The TH16 is only the source for the temperature. The geyser relay is a separate (on the DB) CBI smart breaker rated appropriately. And the geyser thermostat is still in the equation too but set significantly higher so it only acts as failsafe.

How are you getting temperature out of it reliably then?
 
It's not exactly your use case but the structure should be similar using the temperature as a trigger rather than the time as in my case.

Code:
alias: Geyser
description: ""
trigger:
  - platform: sun
    event: sunset
    id: sunset
    enabled: false
  - platform: state
    entity_id:
      - switch.geyser
    to: "on"
    for:
      hours: 1
      minutes: 30
      seconds: 0
    id: manual_on
  - platform: time
    at: "18:30:00"
    id: geyser_off
  - platform: time
    at: "11:00:00"
    id: time_12
  - platform: numeric_state
    entity_id: sensor.battery_power
    for:
      hours: 0
      minutes: 15
      seconds: 0
    id: discharge_over_4000
    enabled: true
    below: -4000
  - platform: time
    at: "06:30:00"
    id: "630"
    enabled: false
  - platform: numeric_state
    entity_id: sensor.geyser_temperature
    above: 45
    id: temperature
  - platform: numeric_state
    entity_id: sensor.pv_power
    for:
      hours: 0
      minutes: 15
      seconds: 0
    above: 3000
    id: solar_3000
  - platform: numeric_state
    entity_id:
      - sensor.battery_soc
    id: "25"
    for:
      hours: 0
      minutes: 5
      seconds: 0
    below: 20
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: manual_on
          - condition: time
            before: "11:00:00"
            after: "18:30:00"
        sequence:
          - type: turn_off
            device_id: 95eb5623844ff148df676193f8664a43
            entity_id: switch.geyser
            domain: switch
      - conditions:
          - condition: trigger
            id: geyser_off
        sequence:
          - type: turn_off
            device_id: 95eb5623844ff148df676193f8664a43
            entity_id: switch.geyser
            domain: switch
      - conditions:
          - condition: trigger
            id: sunset
        sequence:
          - type: turn_off
            device_id: 95eb5623844ff148df676193f8664a43
            entity_id: switch.geyser
            domain: switch
      - conditions:
          - condition: trigger
            id: time_12
          - condition: numeric_state
            entity_id: sensor.grid_voltage
            above: 220
        sequence:
          - type: turn_on
            device_id: 95eb5623844ff148df676193f8664a43
            entity_id: switch.geyser
            domain: switch
      - conditions:
          - condition: trigger
            id:
              - discharge_over_4000
        sequence:
          - type: turn_on
            device_id: 95eb5623844ff148df676193f8664a43
            entity_id: switch.geyser
            domain: switch
      - conditions:
          - condition: trigger
            id:
              - "630"
          - condition: state
            entity_id: sensor.load_shedding_area_capetown_10_brackenfell
            state: "off"
        sequence:
          - type: turn_on
            device_id: 95eb5623844ff148df676193f8664a43
            entity_id: switch.geyser
            domain: switch
      - conditions:
          - condition: trigger
            id: temperature
          - condition: time
            before: "11:00:00"
            after: "18:30:00"
        sequence:
          - type: turn_off
            device_id: 95eb5623844ff148df676193f8664a43
            entity_id: switch.geyser
            domain: switch
      - conditions:
          - condition: trigger
            id:
              - solar_3000
          - condition: numeric_state
            entity_id: sensor.battery_soc
            above: 50
          - condition: numeric_state
            entity_id: sensor.grid_voltage
            above: 220
        sequence:
          - type: turn_on
            device_id: 95eb5623844ff148df676193f8664a43
            entity_id: 4d23e4a05872713f632d8c17eee17447
            domain: switch
      - conditions:
          - condition: trigger
            id:
              - "25"
        sequence:
          - type: turn_off
            device_id: 95eb5623844ff148df676193f8664a43
            entity_id: 4d23e4a05872713f632d8c17eee17447
            domain: switch
    default: []
mode: single
 
I find its reasonably reliable (or reliable enough) with the temp probe run into the secondary temp probe slot in my geyser?
Alright I don’t have one of those so that explains it.

Couldn’t get my thermostat and probe into this geyser at the same time, so I ended up just taping it to the thermostat which gives a reasonable reading to know if it’s hot or cold, but nothing exact.
 
Top
Sign up to the MyBroadband newsletter
X