Loop on a script

Hello,
I want to loop on a script while a bolean value is true
I will run a “light show” while a button on the panel is on
The variable on the panel is input_boolean.start_light_show_1
I will send a mqtt publish every second while the boolean is true.

Can any body guide me for the realisation of my first script ?

master:
 - condition: state
   entity_id: input_boolean.start_light_show_1
   state: 'on'
 - service: script.turn_on
   entity_id: script.rainbow1


rainbow1:
  sequence:
   - service: notify.pushbullet
     data:
        title: "Light show"
        message: "Rainbow1 in script"
        
   - service: mqtt.publish
     data:
          topic: "cmnd/b0704d58c57d3b4bbacadaf645505c4/color"
          payload: "effect: rainbow1"
   - delay: '00:01:30'
   - service: script.turn_on
     entity_id: script.master

Many thanks for your help and best regards

Thierry

Other than some formatting issues (you’ve got indents of two, three, and five spaces) the logic there is good.

If after you fix the formatting you’re having problems, please show us your code and explain the problem.

The indentation, although legal YAML, is not conventional. But I think the real problem is you forgot sequence: in the master script. Try:

master:
  sequence:
    - condition: state
      entity_id: input_boolean.start_light_show_1
      state: 'on'
    - service: script.turn_on
      entity_id: script.rainbow1

rainbow1:
  sequence:
    - service: notify.pushbullet
      data:
        title: "Light show"
        message: "Rainbow1 in script"
    - service: mqtt.publish
      data:
        topic: "cmnd/b0704d58c57d3b4bbacadaf645505c4/color"
        payload: "effect: rainbow1"
    - delay: '00:01:30'
    - service: script.turn_on
      entity_id: script.master

There is also the possibility that that you need at least a small delay in the master script between the existing two steps. But give the above a try first.

many thanks for your help !
Best regards
Thierry

1 Like

I would use an automation and a time_pattern trigger instead of a script:

- id: 'Cycle colors'
  alias: Cycle colors
  initial_state: true
  trigger:
    - platform: time_pattern
      seconds: '/1'
  condition:
    - condition: state
      entity_id: input_boolean.start_light_show_1
      state: 'on'
1 Like

Ouahhhhhh!
Many thanks for your help!
I will try it tomorrow!
Best regards!