Boolean toggle

I tried making my own toggle helper switch to detect manual change of a light entity, based on this blueprint.
This is my automation:

alias: ES Manual Control Status Tracker
description: ""
triggers:
  - trigger: state
    entity_id:
      - light.keuken
    from: "off"
    to: "on"
    id: t1
  - trigger: state
    entity_id:
      - light.keuken
    from: "on"
    to: "off"
    id: t2
  - trigger: state
    entity_id: 
      - light.keuken
    attribute: brightness_pct
    not_from: 101
    id: t3
  - trigger: state
    entity_id: 
      - light.keuken
    attribute: kelvin
    not_from: 2
    id: t4
conditions:
  - condition: or
    conditions:
      - condition: and
        conditions:
          - condition: template
            value_template: >-
              {{ trigger.id == 't1' and trigger.to_state.context.parent_id is
              none }}
      - condition: and
        conditions:
          - condition: template
            value_template: >-
              {{ trigger.id == 't2' and trigger.to_state.context.parent_id is
              none }}
      - condition: and
        conditions:
          - condition: template
            value_template: >-
              {{ trigger.id == 't3' and trigger.to_state.context.parent_id is
              none }}
      - condition: and
        conditions:
          - condition: template
            value_template: >-
              {{ trigger.id == 't4' and trigger.to_state.context.parent_id is
              none }}
actions:
  - choose:
      - conditions:
          - condition: trigger
            id: t1
        sequence:
          - action: homeassistant.turn_on
            target:
              entity_id: input_boolean.manual_override
            data: {}
          - choose:
              - conditions:
                  - condition: template
                    value_template: "{{ include_auto_off == 'enable_all_auto_off' }}"
                sequence:
                  - delay:
                      minutes: 0
                  - action: homeassistant.turn_off
                    target:
                      entity_id: "{{ target_entities_on }}"
                  - action: homeassistant.turn_off
                    metadata: {}
                    data: {}
                    target:
                      entity_id: input_boolean.manual_override
              - conditions:
                  - condition: template
                    value_template: >-
                      {{ include_auto_off == 'enable_manual_tracking_auto_off'
                      }}
                sequence:
                  - delay:
                      minutes: 0
                  - action: homeassistant.turn_off
                    metadata: {}
                    data: {}
                    target:
                      entity_id: input_boolean.manual_override
      - conditions:
          - condition: trigger
            id: t2
        sequence:
          - action: homeassistant.turn_off
            target:
              entity_id: input_boolean.manual_override
            data: {}
      - conditions:
          - condition: trigger
            id:
              - t3
        sequence:
          - action: homeassistant.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.manual_override
      - conditions:
          - condition: trigger
            id:
              - t4
        sequence:
          - action: homeassistant.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.manual_override

However, the toggle only turns ON when I manually turned the light on. Not when I also turn it OFF, change the brightness or the color temperature.
I want to use this helper as a condition in an ‘until loop’ for gradually dimming the lights until the loop is repeated X times (defined by template) or if the toggle helper is turned ON (meaning I manually changed the light state).
What am I missing here?

Your code contains soooo much unnecessary cruft that serves no purpose/doesn’t do anything. Just with some spring cleaning I cut it down from 120 lines to 50ish lines without really changing any of the logic.

What the remaining initial condition (trigger.to_state.context.parent_id is none) is supposed to achieve I really have no idea, so those two lines can probably just as well be deleted too…

alias: ES Manual Control Status Tracker
triggers:
  - trigger: state
    entity_id: light.keuken
    to: "on"
    id: "on"
  - trigger: state
    entity_id: light.keuken
    to: "off"
    id: "off"
  - trigger: state
    entity_id: light.keuken
    attribute: brightness
    id: "off"
  - trigger: state
    entity_id: light.keuken
    attribute: color_temp_kelvin
    id: "off"
conditions:
  - "{{ trigger.to_state.context.parent_id is none }}"
actions:
  - choose:
      - conditions:
          - condition: trigger
            id: "on"
        sequence:
          - action: homeassistant.turn_on
            target:
              entity_id: input_boolean.manual_override
          - choose:
              - conditions: "{{ include_auto_off == 'enable_all_auto_off' }}"
                sequence:
                  - action: homeassistant.turn_off
                    target:
                      entity_id: "{{ target_entities_on }}"
                  - action: homeassistant.turn_off
                    target:
                      entity_id: input_boolean.manual_override
              - conditions: "{{ include_auto_off == 'enable_manual_tracking_auto_off' }}"
                sequence:
                  - action: homeassistant.turn_off
                    target:
                      entity_id: input_boolean.manual_override
      - conditions:
          - condition: trigger
            id: "off"
        sequence:
          - action: homeassistant.turn_off
            target:
              entity_id: input_boolean.manual_override

Now we can much more easily tell what is going on. Immediate question marks are your conditions of the inner choose. Not sure where you got those conditions from, but in both of them you are attempting to make comparisons against a nonexistent variable include_auto_off.

In the resulting sequence of the first condition (which will never trigger though, as the condition will never evaluate to true) you are then attempting to turn off a switch where the entity id is generated by a template containing another nonexistent variable target_entities_on.

Wow thank you so much.
I copy-pasted most of the script and it’s based on a blueprint. That’s why the unused variables (include_auto_off) are there.
You helped me understand what I’m doing. Thanks a lot!
For completeness sake, here’s my current automation:

alias: ES Manual Control Status Tracker
description: Toggle 'input.boolean' helper when a manual change is made to the lights
triggers:
  - trigger: state
    entity_id: light.keuken
    to: "on"
    id: "On"
  - trigger: state
    entity_id:
      - light.keuken
    to: "off"
    id: "Off"
  - trigger: state
    entity_id:
      - light.keuken
    id: Temp
    attribute: color_temp_kelvin
  - trigger: state
    entity_id:
      - light.keuken
    attribute: brightness
    id: Bright
conditions:
  - condition: template
    value_template: "{{ trigger.to_state.context.parent_id is none }}"
actions:
  - if:
      - condition: trigger
        id:
          - "On"
          - "Off"
          - Temp
          - Bright
    then:
      - action: input_boolean.turn_on
        metadata: {}
        data: {}
        target:
          entity_id: input_boolean.manual_override

Well… though I’m really happy I finally got something to work in HA, it turns out it doesn’t work the way I want it to.
I changed the script above to reset after time has passed (5 seconds currently for testing purposes, but want to change to 10 minutes).

My automations, triggered by time or template, are not generating a parent_id. I’m thinking of using some workaround:
After the loop starts, wait for 2 seconds until the input_boolean.manual_override changes from “off” to “on”.
The state change is to ensure the helper was not on “on” before the condition started, meaning it was manually triggered.

Do you think this should work? Or is there a better way?

You are asking for a solution without describing the problem. An XY problem as many of the regulars here describe it. This particular automation toggles an input_boolean, but you’ve never told us what its purpose is. Describe what your entire set of automations are supposed to accomplish. Also include the code for any other automations intended to work together.

My end goal is to get something like the Adaptive Lighting integration, but multiple time stamps. So it starts 5 minutes before my alarm, gradually changes the lights fom 50% to 85% and 3500K to 5000K in 10 minutes.
Then I want the lights to dim back to 60% and 3500K in 55 minutes.
Then back to 5000K and 80% in 4 hours
Then 3500K and 50% in 4 hours
Then 2800K and 30% in 4 hours
Then 2500K and 10% in 3 hours
Then 2200K and 1% in 1 hour.

It should start at the (approximate) right settings when I get home based on the time (range), and when I manually change the light settings, wait for 20 minutes until I receive a notification on my phone that asks me if I want to resume the light routine.

I want to take this step by step, so I started with a script that gradually turns on the light 5 minues before my alarm and stops after 10 mintes:

sequence:
  - target:
      area_id:
        - keuken
    data:
      brightness_pct: 50
      color_temp_kelvin: 3500
    action: light.turn_on
  - variables:
      start_kelvin: 3500
      stop_kelvin: 5000
      start_bright: 50
      stop_bright: 85
      duration: 600
      intervals: "{{ duration * 2 }}"
      step_kelvin: "{{ ((stop_kelvin - start_kelvin) / intervals) }}"
      step_bright: "{{ ((stop_bright - start_bright) / intervals) }}"
      current_bright: "{{ state_attr('light.keuken', 'brightness') }}"
      current_temp: "{{ state_attr('light.keuken', 'color_temp_kelvin') }}"
  - repeat:
      sequence:
        - delay:
            seconds: 6
        - condition: state
          entity_id: input_boolean.manual_override
          state: "off"
        - action: light.turn_on
          metadata: {}
          data:
            brightness_pct: "{{ (start_bright + (step_bright * repeat.index)) | round }}"
            color_temp_kelvin: "{{ (start_kelvin + (step_kelvin * repeat.index)) | round }}"
          target:
            entity_id: light.keuken
        - delay:
            seconds: 1
      until:
        - condition: or
          conditions:
            - condition: template
              value_template: "{{ repeat.index == intervals }}"
            - condition: state
              entity_id: automation.es2_manual_control_status_tracker
              state: "on"
alias: 00. Wake-up
description: ""

Only, when this script is triggered, my input_boolean is also turned on, which causes the script to stop brightening the lights.