Cannot get script condition to trigger true

I’m trying ot create a ‘counter’ script. The script gets passed a counter entity, a value ‘up’ or ‘down’ and a delay to set the counting speed.

I’m having trouble getting it to trigger however. It seems that the templates that compare the state of count_up_or_down are never set to true.

Any help is welcome, below is the full yaml:

counter:
  alias: Counter
  mode: parallel
  icon: mdi:counter
  fields:
    counter:
      name: Counter
      description: The counter entity you want to manipulate
      selector:
        target:
          entity:
            domain: counter
      required: true
    count_up_or_down:
      name: Count up or down
      description: Do you want to count up or down?
      selector:
        select:
          mode: dropdown
          options:
          - up
          - down
      required: true
    counting_speed:
      name: Counting speed
      description: How much time between each counting step
      selector:
        duration:
      required: true
  sequence:
  - choose:
    - conditions:
      - condition: template
        value_template: "{{ is_state('count_up_or_down', 'up') }}"
      sequence:
      - repeat:
          until:
          - condition: template
            value_template: "{{ states(counter) == state_attr('counter', 'maximum')}}"
          sequence:
          - service: counter.increment
            data: {}
            target: "{{ counter }}"
          - delay: "{{ counting_speed }}"
    - conditions:
      - condition: template
        value_template: "{{ is_state('count_up_or_down', 'down') }}"
      sequence:
      - repeat:
          until:
          - condition: template
            value_template: "{{ states(counter) == state_attr('counter', 'maximum')}}"
          sequence:
          - service: counter.decrement
            data: {}
            target: "{{ counter }}"
          - delay: "{{ counting_speed }}"
          

The is_state() function expects an entity ID and state value string as arguments, not a string and a state value string.

You are using a target selector to input both targets and entity IDs… those are not interchangeable.

The “Down” branch should repeat until the minimum is reached… it won’t ever reach maximum.

counter:
  alias: Counter
  mode: parallel
  icon: mdi:counter
  fields:
    counter:
      name: Counter
      description: The counter entity you want to manipulate
      selector:
        entity:
          filter:
            - domain: counter
      required: true
    count_up_or_down:
      name: Count up or down
      description: Do you want to count up or down?
      selector:
        select:
          mode: dropdown
          options:
            - up
            - down
      required: true
    counting_speed:
      name: Counting speed
      description: How much time between each counting step
      selector:
        duration:
      required: true
  sequence:
  - choose:
    - conditions:
        - condition: template
          value_template: "{{ count_up_or_down == 'up') }}"
      sequence:
        - repeat:
            until:
            - condition: template
              value_template: "{{ states(counter) == state_attr(counter, 'maximum')}}"
            sequence:
            - service: counter.increment
              data: {}
              target: 
                entity_id: "{{ counter }}"
            - delay: "{{ counting_speed }}"
    - conditions:
        - condition: template
          value_template: "{{ count_up_or_down == 'down') }}"
      sequence:
        - repeat:
            until:
            - condition: template
              value_template: "{{ states(counter) == state_attr(counter, 'minimum')}}"
            sequence:
            - service: counter.decrement
              data: {}
              target: 
                entity_id:  "{{ counter }}"
            - delay: "{{ counting_speed }}"

EDIT: Fixed a couple single quotes missed in first edit

1 Like