Passing an entity_id to a script and using it in a template

I am trying to pass the entity_id to a script so that the script and evaluate the state of that entity. The script has to evaluate the state because the script is waiting for that state to change.
The calling program:

alias: Call summons A Pump
sequence:

  • service: script.summons_a_pump
    data_template:
    cistern_to_empty_empty_sensor: binary_sensor.33sumpempty
    cistern_to_fill_full_sensor: binary_sensor.34lowerfull

The script doing its thing:

  - repeat:
      while:
        - condition: and
          conditions:
            - condition: template
              value_template: ->
                '{{ ( is_state(''cistern_to_empty_empty_sensor'',
                "off") )}}'
            - condition: template
              value_template: ->
                '{{ ( is_state(''cistern_to_fill_full_sensor'',
                "off") ) }}'
      sequence: []

The conditions evaluate to false.

I’ve been trying various combinations of single quote, 2 single quotes, double quotes, parenthesis, 2 parenthesis to no avail.

The strange thing is, it works here:

alias: Call Run A Pump
sequence:

  • service: script.run_a_pump
    data:
    pump: switch.33sump

alias: Run A Pump
sequence:

  • service: switch.turn_on
    target:
    entity_id: ‘{{ pump }}’
    data: {}

What’s the magic encantation?

I think your service call needs to use data and not data_template. data_template is if you use script.turn_on.

Then you should use {{ cistern_to_empty_empty_sensor }}.

It’s usually a good idea to setup the fields so you can test your script-as-service in the devtools. This part isn’t necessary, but it is good practice.

There’s no need to use an And condition when using two Template conditions since they can be combined in-template.

You use the id of the variable as-is in templates. While the template as a whole needs to be in quotes or nested under a multi-line quote, the variable itself should not be quoted.

- alias: Summons a Pump
  fields:
    cistern_to_empty_empty_sensor:
      name: Empty Sensor
      example: binary_sensor.33sumpempty
      selector:
        entity:
          domain: binary_sensor
    cistern_to_fill_full_sensor:
      name: Full Sensor
      example: binary_sensor.34lowerfull
      selector:
        entity:
          domain: binary_sensor
  sequence:
     - repeat:
          while:
            - condition: template
              value_template: >
                {{ is_state(cistern_to_empty_empty_sensor,
                "off") and is_state(cistern_to_fill_full_sensor, "off") }}
          sequence: 
            - service: X

I appreciate the response!