Script field is not resolving to its value

Hi

I have a script that is supposed to set my Eddi water heater to one of two modes: Stopped or Normal. Because the Eddi API is unreliable, I want to retry a number of times; and I’m using a script to code this logic in one place for use by various automations.

However when I run the script (from the script editor or from the developer console), I get this error message:

Option {{ mode }} is not valid for entity select.myenergi_eddi_23301706_operating_mode, valid options are: Stopped, Normal.

The script is:

description: Change Eddi mode, with repeats as API is unreliable
fields:
  mode:
    selector:
      text: null
    name: mode
    required: true
    description: Stopped or Normal
sequence:
  - repeat:
      sequence:
        - device_id: ffc71174946331c0d6ea28c07d6fb3cc
          domain: select
          entity_id: 91b92249e73a5088e645961ddc3d822d
          type: select_option
          option: "{{ mode }}"
        - delay:
            hours: 0
            minutes: 1
            seconds: 0
            milliseconds: 0
      while:
        - condition: not
          conditions:
            - condition: state
              entity_id: select.myenergi_eddi_23301706_operating_mode
              state: "{{ mode }}"

I was expecting {{ mode }} to resolve to Stopped or Normal, depending on what I set it to, but instead it remains unresolved.

I’ve tried calling the field other things but it makes no difference.

What am I doing wrong?

I should say that the script works OK if I hardcode “Stopped” in place of “{{ mode }}” so the basic script is correct.

Don’t use device actions, afaik they generally do not support templates. Use a select.select_option action instead. These do allow templates.

There are many reasons to avoid device actions:

Thanks! That was spot on.

My completed script is as follows, in case anyone finds it useful. The 30s delay is to reduce the risk of exiting the loop without getting a refresh from the Eddi itself (otherwise I seem to just pick up the local change to the state that I just made).

Thanks again.

description: Change Eddi mode, with repeats as API is unreliable
fields:
  eddi_mode:
    selector:
      text: null
    name: Eddi mode
    required: true
    description: Stopped or Normal
sequence:
  - variables:
      loop_counter: 0
  - repeat:
      while:
        - condition: template
          value_template: >-
            {{ states("select.myenergi_eddi_23301706_operating_mode") !=
            eddi_mode }}
        - condition: template
          value_template: "{{ loop_counter <= 10 }}"
      sequence:
        - action: select.select_option
          metadata: {}
          data:
            option: "{{ eddi_mode }}"
          target:
            entity_id: select.myenergi_eddi_23301706_operating_mode
        - delay:
            hours: 0
            minutes: 0
            seconds: 30
            milliseconds: 0
        - variables:
            loop_counter: "{{ loop_counter + 1 }}"
        - wait_template: >-
            {{ states("select.myenergi_eddi_23301706_operating_mode") ==
            eddi_mode }}
          continue_on_timeout: true
          timeout: "00:00:30"
  - if:
      - condition: template
        value_template: |2
                      {{ states("select.myenergi_eddi_23301706_operating_mode") !=
                      eddi_mode }}
    then:
      - action: notify.notify
        metadata: {}
        data:
          message: "WARNING: The EDDIseems to have not chenged to \"{{ eddi_mode }}\""
alias: Change Eddi Mode
mode: restart

Steve

1 Like