Script condition to turn on lights if input bool true

i use an automation to fire off a script. script turns on lights in sequence with delay. i wanna be able to have input_boolean switches made with ui helper, so that if i randomly decide ‘hey i dont want this light on for the next few days’ i dont have to change the on/off script via notepad. i understand in scripts they dont move forward if a standard conditional statement is in the sequence. is there a better way to do this? I know a lot of changes to the templating and scripting jinja has been applied over the last year and any google searches gives me outdated info, to my belief atleast. Any suggestions are welcome, but if im not mistaken i basically have to turn these into automations if i want the condition based off the inputboolean

current lights on automation:

automation:
- id: 'veg_lights_on'
  alias: 'veglights_on'
  description: turn veg lights on at the right time
  trigger:
  - platform: time
    at: input_datetime.veg_lights_on
  condition: []
  action:
  - service: script.veg_lights_cycle_on
    data: {}
  mode: single

current script:

script:
  veg_lights_cycle_on:
      alias: 'veg_lights_cycle on'
      sequence:
      - service: switch.turn_on
        entity_id: switch.tasmota2
      - delay:
          minutes: 1  
      - service: switch.turn_on
        data: {}
        entity_id: switch.tasmota3
      - delay:
          minutes: 1
      - service: switch.turn_on
        data: {}
        entity_id: switch.tasmota

      mode: single

what id think id want:

script:
  veg_lights_cycle_on:
      alias: 'veg_lights_cycle on'
      sequence:
      - condition: template
        value_template: "{{ is_state('input_boolean.veg_315_1', 'on') }}"
        - service: switch.turn_on
          entity_id: switch.tasmota2
        - delay:
            minutes: 1  
      - condition: template
        value_template: "{{ is_state('input_boolean.veg_315_2', 'on') }}"
        - service: switch.turn_on
          entity_id: switch.tasmota3
        - delay:
            minutes: 1              
      - condition: template
        value_template: "{{ is_state('input_boolean.veg_315_3', 'on') }}"
        - service: switch.turn_on
          entity_id: switch.tasmota
        - delay:
            minutes: 1     

and in so, if the switch was set to true, the delay would still take place between each switch being turned on, and so forth.

i feel like i could have figured this out with the time taken to explain it, but after days of letting this linger in my head, i give up and am reaching out.

love you homeassistant community. :kissing_heart:

Yes. Use the Choose action.

1 Like

attempt 1 resulted in:

Invalid config for [script]: [choose] is an invalid option for [script]. Check: script->choose
script:
  veg_lights_new_cycle_on:
      alias: 'veg_lights_new_cycle on'
      choose:
      - conditions:
        - condition: state
          entity_id: input_boolean.veg_315_1
          state: "on"      
        sequence:
        - service: switch.turn_on
          entity_id: switch.tasmota2
        - delay:
            minutes: 1
      - service: switch.turn_on
        entity_id: switch.tasmota3
      - delay:
          minutes: 1
      - service: switch.turn_on
        entity_id: switch.tasmota

attempt 2 resulted in:

Invalid config for [script]: [choose] is an invalid option for [script]. Check: script->choose. (See /config/configuration.yaml, line 37).
Invalid config for [script]: [service] is an invalid option for [script]. Check: script->sequence->0->choose->1->service. (See /config/configuration.yaml, line 37).
script:
  veg_lights_new_cycle_on:
      alias: 'veg_lights_new_cycle on'
      sequence:
      - choose:
        - conditions:
          - condition: state
            entity_id: input_boolean.veg_315_1
            state: "on"      
          sequence:
          - service: switch.turn_on
            entity_id: switch.tasmota2
          - delay:
              minutes: 1
        - service: switch.turn_on
          entity_id: switch.tasmota3
        - delay:
            minutes: 1
        - service: switch.turn_on
          entity_id: switch.tasmota

I could try this all night and all but been there done that.

any corrections are more than welcome again as usual.

It will if you use three separate choose actions.

1 Like
If you are composing the script in the scripts.yaml file then you don’t include script: on the first line.

im not, i actually just included it for any “true” new person that may misread or misunderstand somewhere. I for sure remember the nightmares of some of this. And when tom_i responded with choose commands from an automation, and not a script, I was a little in fear, but due to moderator status, chose to just continue to add in to emphasize, however I appreciate the tip. This was something I struggled with when breaking out of configuration.yaml into seperate files and not knowing why of all the errors. that was like week 2 issues. im on like year 2-3.

now, let me try this choose thing out real fast…

And this throws no errors. Bout to fire her up n see what happens

*also, this is the first script in my file, so the ‘script:’ header is actually being used fwiw.

script:
  veg_lights_new_cycle_on:
      alias: 'veg_lights_new_cycle on'
      sequence:
      - choose:
        - conditions:
          - condition: state
            entity_id: input_boolean.veg_315_1
            state: "on"      
          sequence:
          - service: switch.turn_on
            entity_id: switch.tasmota2
          - delay:
              minutes: 1
      - choose:
        - conditions:
          - condition: state
            entity_id: input_boolean.veg_315_2
            state: "on"      
          sequence:
          - service: switch.turn_on
            entity_id: switch.tasmota3
          - delay:
              minutes: 1
      - choose:
        - conditions:
          - condition: state
            entity_id: input_boolean.veg_315_3
            state: "on"      
          sequence:
          - service: switch.turn_on
            entity_id: switch.tasmota
          - delay:
              minutes: 1  
      - choose:
        - conditions:
          - condition: state
            entity_id: input_boolean.veg_315_4
            state: "on"      
          sequence:
          - service: switch.turn_on
            entity_id: switch.423001182cf4326d3fcf_4
          - delay:
              minutes: 1   

*updated: this is the working solution to use ‘if’ conditions in a scipt sequence.

And it works.

Furthermore, either one of you know where or what I should do to contribute to the popup menu being too small, even on a large desktop screen?

menu

because that is not cool.

You can open an issue here:

Search first and make sure there isn’t an existing one open.

1 Like