Automating a Geyser based on temperature and time

Hi,

I am new to HA. I am trying to do the following to control my geyser:

  1. If temp below 30 degrees then turn geyser on but only between 6.30 and 7.30 am.
  2. If time is 7:30 am turn geyser off.

I have a Sonoff TH16R2 that is connected to EweLink. I have integrated both into HA and can switch the geyser on and off from HA. I can also read the temperature.

I have tried various solutions but the automation does not work. I want to read the temperature during the time window and if below the trigger point, switch on the geyser.

I think I am failing because I am looking for the temperature to be below a value but HA seems to only trigger if it passes a value. If the value it passes is outside my time window it does not trigger. I am somewhat confused as to how to set this up.

Thanks for your help

In the following example, change the entity_ids (sensor.outdoor_temperature and switch.geyser) to match the switch and sensor in your system.

alias: Control Geyser
trigger:
  - id: 'on'
    platform: time
    at: '06:30:00'
    variables:
      is_true: "{{ states('sensor.outdoor_temperature') | int(0) < 30 }}"
  - id: 'off'
    platform: time
    at: '07:30:00'
    variables:
      is_true: "{{ true }}"
  - id: 'on'
    platform: numeric_state
    entity_id: sensor.outdoor_temperature
    below: 30
    variables:
      is_true: "{{ (6,30) <= (now().hour, now().minute) < (7,30) }}"
condition:
  - condition: template
    value_template: "{{ is_true }}"
action:
  - service: "switch.turn_{{ trigger.id }}"
    target:
      entity_id: switch.geyser

Let me know if you would like me to explain how it works.

Thank you very much for the help. Yes, please explain how it works.

Summary

  • It turns on the switch at 06:30 only if the temperature is below 30.
  • It turns off the switch at 07:30.
  • It turns on the switch when the temperature decreases below 30 but only if that happens between 06:30 and 07:30.

Details

  • The automation can be triggered by:
    – Time
    At two times: 06:30 and 07:30.
    – Temperature decrease
    At the moment when the temperature decreases below 30.

  • In all three cases when triggered, it creates a variable named is_true and, using a template, sets its value to either boolean true or boolean false.

  • In addition, each trigger has an id property whose value is set to either on or off. This value will be used in the automation’s action to either turn the switch on or off.

  • At 06:30 it checks if the temperature is below 30 and if it is it sets is_true to true. If not, it’s set to false. The automation’s condition checks if the value of is_true is true. If it is, it proceeds to execute the action and turn on the switch. if it’s not, the automation ends immediately.

  • At 07:30, the value of is_true is simply set to true. That ensures the condition is fulfilled and the automation proceeds to execute the action and turn off the switch.

  • Let’s assume that at 06:30 the temperature was not below 30, therefore the switch was not turned on. However, at a later time the temperature decreases below 30. That will trigger the Numeric State Trigger. It will set the value of is_true to true only if the current time is between 06:30 and 07:30. Let’s assume the temperature decreased at 06:50 so is_true is set to true. The automation’s condition is fulfilled and it proceeds to turn on the switch.

Fantastic, thank you very much. I will implement it today. Great support…

1 Like

After you have tested it, report back with the results. I’ll help you fix any problems or make any desired modifications to its operation.

I tested your solution and got it working to get the geyser to switch on. I am battling to get it to switch off. I have been playing around trying to action on template when it is false. There is only action on template when it is true.

It is not working yet.

This is what I have:

alias: Test
description: ""
trigger:
  - id: "on"
    platform: time
    at: "15:55:00"
    variables:
      is_true: "{{ states('sensor.sonoff_1000beb2e9_temperature') | int(0) < 52 }}"
  - id: "off"
    platform: time
    at: "16:00:00"
    variables:
      is_true: "{{ true }}"
  - id: "on"
    platform: numeric_state
    entity_id: sensor.sonoff_1000beb2e9_temperature
    below: 52
    variables:
      is_true: "{{ (15,55) <= (now().hour, now().minute) < (16,00) }}"
condition:
  - condition: template
    value_template: "{{ is_true }}"
action:
  - choose:
      - conditions:
          - condition: template
            value_template: template
        sequence:
          - type: turn_on
            device_id: f87c5830cbd79957b7d3686d81220335
            entity_id: a2427c982ed3f4c4dd199f22893f9e96
            domain: switch
      - conditions:
          - condition: template
            value_template: "false"
        sequence:
          - type: turn_off
            device_id: f87c5830cbd79957b7d3686d81220335
            entity_id: a2427c982ed3f4c4dd199f22893f9e96
            domain: switch
  - service: notify.mobile_app_nokia_x20
    metadata: {}
    data:
      message: >-
        Geyser switched: {{ states("sensor.sonoff_1000beb2e9_temperature") }}
        °C.
      title: >-
        Geyser Switched [{{ states("sensor.sonoff_1000beb2e9_temperature") }}
        °C]
mode: single

Ignore the times and temps as I used them for testing. My 6:30 to 7:30am with a temp lower than 30 degrees is still the goal.

Do you know of a beginners tutorial series I could follow?

Many thanks.

The action in the example you posted is not what I had suggested. Your example has a choose statement employing invalid conditions.

I recommend you use what I had suggested. It employs a templated service call that turns the switch on or off depending on the trigger’s id value.

action:
  - service: "switch.turn_{{ trigger.id }}"
    target:
      entity_id: switch.geyser

Thank you Taras for your help.

My final solution is as follows:

alias: Geyser Control
description: ""
trigger:
  - id: "on"
    platform: time
    at: "06:30:00"
    variables:
      is_true: "{{ states('sensor.sonoff_1000beb2e9_temperature') | int(0) < 40 }}"
  - id: "on"
    type: temperature
    platform: device
    device_id: f87c5830cbd79957b7d3686d81220335
    entity_id: e742e7b6421924ce742fcb52d5c122b6
    domain: sensor
    below: 40
    variables:
      is_true: "{{ (6,30) <= (now().hour, now().minute) < (7,30) }}"
  - id: "off"
    platform: time
    at: "07:30:00"
    variables:
      is_true: "{{ true }}"
condition:
  - condition: template
    value_template: "{{ is_true }}"
action:
  - service: switch.turn_{{ trigger.id }}
    metadata: {}
    data: {}
    target:
      entity_id: switch.sonoff_1000beb2e9
  - service: notify.mobile_app_nokia_x20
    metadata: {}
    data:
      title: >-
        Geyser Control [{{ trigger.id }}]: {{
        states('sensor.sonoff_1000beb2e9_temperature') }} °C
      message: >-
        Geyser control [{{ trigger.id }}]: {{
        states('sensor.sonoff_1000beb2e9_temperature') }} °C