I need help with script parameter

Hi,
Im trying to use one script (toggle) many climate devices.
For example tap action:

tap_action:
  action: call-service
  service: script.toggle_heater
  data:
    tentity: climate.f1a1

and script:

toggle_heater:
  alias: toggle_heater
  sequence:
  - if:
    - condition: and
      conditions:
      - condition: template
        value_template: >-
            {% set device = '{{ tentity }}' %}
            {{ is_state('climate.f1a1', 'heat') }}
    then:
    - service: climate.turn_off
      data:
         entity_id: '{{ tentity }}'

But without success (else condition missing but they are similar) :frowning:
I need help what I’m doing wrong ?
Is it possible to send parameter in this way?

Thank you in advance :slight_smile:

toggle_heater:
  alias: toggle_heater
  sequence:
    - condition: template
      value_template: "{{ is_state(tentity, 'heat') }}"
    - service: climate.turn_off
      target:
        entity_id: '{{ tentity }}'

Hi,
Cannot determine status in if condition.
Current status from developer tools for this device is “heat”
But result in script is false:

Result:
result: false
condition: template
value_template: '{{ is_state(tentity, ''heat'') }}'

Still not working.

Thank you for suggestion :slight_smile:

If the script didn’t receive a value of climate.f1a1 in the tentity variable then there may be an issue with how tap_action is configured.

Try this version:

tap_action:
  action: call-service
  service: script.toggle_heater
  service_data:
    tentity: 'climate.f1a1'
toggle_heater:
  alias: toggle_heater
  sequence:
    - variables:
        t: "{{ tentity | default('climate.f1a1', true) }}"
    - condition: template
      value_template: "{{ is_state(t, 'heat') }}"
    - service: climate.turn_off
      target:
        entity_id: '{{ t }}'

When I try to toggle f1a2 device

tap_action:
  action: call-service
  service: script.toggle_heater
  data:
    tentity: climate.f1a2
double_tap_action:
  action: more-info

Device f1a1 going to turn off.

I designed the script to use climate.f1a1 by default if it doesn’t receive a value for tentity.

The results of your test prove that the script is not receiving a value for tentity.

I suggest you try the version I had suggested which uses service_data instead of data.

tap_action:
  action: call-service
  service: script.toggle_heater
  service_data:
    tentity: climate.f1a2
double_tap_action:
  action: more-info

Yeeee now working as expected.
Thank you :sunglasses:

Now second question how to make else ?

You will need to provide more details about what you want to do because “make else” isn’t sufficiently clear.

toggle_heater:
  alias: toggle_heater
  sequence:
    variables:
      t: "{{ tentity | default('climate.f1a1', true) }}"
    if:
        - condition: template
          value_template: "{{ is_state(t, 'heat') }}"
        - service: climate.turn_off
          target:
            entity_id: '{{ t }}'
    else:
    - service: climate.set_temperature
      data:
        temperature: input_number.default_climate_themperature
    	hvac_mode: heat
      target:
          entity_id: '{{ t }}'

Something similar like this but this not working :frowning:

toggle_heater:
  alias: toggle_heater
  sequence:
    - variables:
       t: "{{ tentity | default('climate.f1a1', true) }}"
    - if:
        - condition: template
          value_template: "{{ is_state(t, 'heat') }}"
      then:
        - service: climate.turn_off
          target:
            entity_id: '{{ t }}'
      else:
        - service: climate.set_temperature
          data:
            temperature: "{{ states('input_number.default_climate_themperature') }}"
            hvac_mode: heat
          target:
            entity_id: '{{ t }}'

EDIT

Correction. Overlooked to include hyphens.

For something reason script is not loaded:
Script is unavailable
Actions: extra keys not allowed @ data[0][‘if’]

toggle_heater:
  alias: toggle_heater
  sequence:
    - variables:
        t: "{{ tentity | default('climate.f1a1', true) }}"
    - if:
      - condition: template
        value_template: "{{ is_state(t, 'heat') }}"
      then:
        - service: climate.turn_off
          target:
              entity_id: '{{ t }}'
      else:
          - service: climate.set_temperature
            data:
              temperature: "{{ states('input_number.default_climate_themperature') }}"
              hvac_mode: heat
            target:
              entity_id: '{{ t }}'

This work as expected :sunglasses:
Thank you very much " 123Taras"

That’s due to my mistake. I have corrected the example posted above.

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.