Use input_select as variable in script but nothing happens

Hi,

The following automation runs a script that uses an input_select as variable:

action: call-service
  service: script.toggle_light
  service_data:
    light_brightness: 80
    light_kelvin: 6000
    light_scene_id: evening

And the script is the following:

alias: Toggle light
sequence:
  - choose:
      - conditions:
          - alias: Light was off, active a light mode
            condition: state
            entity_id: input_select.light_mode
            state: light_off
        sequence:
          - service: light.turn_on
            target:
              entity_id:
                - "{{light_in_living_room}}"
                - light.lights_bar
            data:
              brightness: "{{light_brightness}}"
              kelvin: "{{light_kelvin}}"
              transition: 2
          - service: input_select.select_option
            target:
              entity_id: input_select.light_mode
            data:
              option: "{{light_scene_id}}"
      - conditions:
          - alias: light mode is selected again, light is turned off
            condition: state
            entity_id: input_select.light_mode
            state: "{{light_scene_id}}"
        sequence:
          - service: light.turn_off
            target:
              entity_id:
                - "{{light_in_living_room}}"
                - light.lights_bar
          - service: input_select.select_option
            target:
              entity_id: input_select.light_mode
            data:
              option: light_off
    default:
      - alias: Another mode is selected
        service: light.turn_on
        target:
          entity_id:
            - "{{light_in_living_room}}"
            - light.lights_bar
        data:
          brightness: "{{light_brightness}}"
          kelvin: "{{light_kelvin}}"
          transition: 2
      - service: input_select.select_option
        target:
          entity_id: input_select.light_mode
        data:
          option: "{{light_scene_id}}"
mode: single
icon: mdi:lightbulb

If the lights are off, then it goes to the first condition, turns the lights on and changes input_select.light_mode to “evening”, everything is ok.

Now, running the automation another time leads to the second condition, and here nothing happens, state: “{{light_scene_id}}” doesn’t seem to work. If I replace it with state: “evening” then it works. How can I solve this issue?

I hope that my my problem is clear, otherwise please let me know.
Thanks for your help!

I don’t see a source for light_in_living_room… regarding light_scene_id, make sure the value being passed from the card is an exact match for the value of the Input Select’s state i.e. capitalization, punctuation, spelling.

Hi @Didgeridrew, you are right I removed it from the post as it is a long line not being useful for the question here. In my real script light_in_living_room is well defined and works well ! Below is the full automation:

action: call-service
  service: script.toggle_light
  service_data:
    light_in_living_room: |
      [[[
        if (states['input_boolean.baby_mode'].state == 'off')
         return "light.lights_living_room";
        return "light.lights_living_room_baby_mode";
      ]]]
    light_brightness: 80
    light_kelvin: 6000
    light_scene_id: evening

And for light_scene_id it is an exact match, do I really don’t understand…