Using a flag or similar to monitor automation state

Hi,

I have the following automation that monitors my water temperature. If it is low at 6:30AM geyser will be switched on for an hour.

I always get the notification that the geyser has been switched off irrespective of wether it was switched on or not. How can I modify the script so that I get the “OFF” notitification only if it was previously switched on?

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

Thanks.

Does anyone know how to do this… Using a boolean flag?

Instead of modifying the actions, just add an additional condition so that the automation does not run at all if the state of the pump/geyser is already what it should be.

Add a condition:

  - condition: template
    value_template: "{{ states('switch.sonoff_1000beb2e9') != trigger.id }}"

The action (including notification) will only run if the switch is going to be changed.

EDIT: beaten to it by Magnus.

Thank you very much.