Pass variable to if else structure

I have 4 buttons with the same script. I want to pass a variable… but how can I check in the script for the variable ?

                tap_action:
                  action: call-service
                  service: script.audio_ruimte1_play
                  service_data:
                    option: optie1

                tap_action:
                  action: call-service
                  service: script.audio_ruimte1_play
                  service_data:
                    option: optie2

...

At least I don’t understand what you’re asking for, exactly :wink:

I want to know if it is possible to make 1 script for 4 buttons… Bu giving a variabele to the script and then use an if else structure ?

Yes it is possible. See https://www.home-assistant.io/integrations/script/#passing-variables-to-scripts

1 Like

Thanks mate, but I don’t have a clue…

I’ve made a tapaction

                tap_action:
                  action: call-service
                  service: script.audio_ruimte1_play
                  service_data:
                    option: optie1

and made a field “option” in my script.

Then I think I have to test a value template. But how do I check that ?

Hi tom,

can you give me a hint ?

When I press a button I want to pass a value to a script. In that script I want to test what value it is by if else structure

if value is "optie1 " then…
if value is “optie2” then…

Script variables:

Script if-then-else:

1 Like

Now I have this in my script…

service: climate.turn_on
metadata: {}
data: {}
target:
  entity_id: climate.ruimte1

is it possible to give the entity_id the name : climate.FIELD ?

i was thinking like climate.{{option}} because my field is named option, but that does not work

Please post the full script

alias: airco
sequence:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{option == 'ruimte1.verwarmen'}}"
            alias: verwarmen
        sequence: []
        alias: verwarmen
      - conditions:
          - condition: template
            value_template: "{{option == 'ruimte1.koelen'}}"
        sequence: []
        alias: koelen
      - conditions:
          - condition: template
            value_template: "{{option == 'ruimte1.airco'}}"
        sequence:
          - if:
              - condition: state
                entity_id: climate.ruimte1
                state: "off"
            then:
              - service: climate.set_temperature
                data:
                  temperature: "{{ states('input_number.aline_airco')| float(0) }}"
                target:
                  entity_id: climate.ruimte1
              - service: climate.set_swing_mode
                metadata: {}
                data:
                  swing_mode: Horizontal
                target:
                  entity_id: climate.ruimte1
              - service: climate.set_fan_mode
                metadata: {}
                data:
                  fan_mode: Auto
              - service: climate.turn_on
                metadata: {}
                data: {}
                target:
                  entity_id: climate.ruimte1
            else:
              - service: climate.turn_off
                metadata: {}
                data: {}
                target:
                  entity_id: climate.ruimte1
        alias: Ruimte 1
description: ""
fields:
  option:
    name: option

where it is climate.ruimte1 i want to change it in the fieldsnamevalue…

Not sure where you got that from. Reread the documentation about variables I posted

in fact, that is working

i was thinking something like this :

value_template: "{{ is_state("climate.{{"option"}}", 'off') }}"