Sensor that grabs entity state when turned on

Hello, I am trying to create a sensor that grabs the state of another sensor when it is turned on and holds it even though the value of the second sensor is dynamic. However, when the sensor is turned on, it continues to update the state of the sensor instead of keeping it static at the time it was activated. Does anyone have any recommendations on how to do this or is it impossible. Here is the code I have so far.

{% if states('input_boolean.irrigation_manual_timer') == 'on' %}
{{ states('sensor.irrigation_end_time') }}
{% endif %}

The problem is every time I turn on “irrigation manual timer” on, it continuously updates the output of irrigation_end_time instead of just grabbing what the output was at the time it was activated.

Any help would be greatly appreciated!

Could you post the full sensor definitions/configs (for both)?

If you trigger the update only when the input is set to on, you shouldn’t have subsequent updates, so there must be something you have configured that we can’t see here.

You should also use the built-in is_state function.

Maybe you can use a trigger based template sensor (added to configuration.yaml)?

template:
  - trigger:
      - platform: state
        entity_id: input_boolean.irrigation_manual_timer
        to: 'on'
    sensor:
      - name: "name_of_irrigation_end_this_turn"
        state: "{{ states('sensor.irrigation_end_time') }}

This will create a sensor which is filled with states('sensor.irrigation_end_time') when input_boolean.irrigation_manual_timer turns on and remains as long the input_boolean is turned off and on again.