How to blink gateway light 10 times?

I want to blink gateway light in red color 10 times when something press button (doorbell)

I’ve wrote script:

flash_gateway1:
  alias: Flash Gateway On
  sequence:
    - service: light.turn_on
      data:
        entity_id: light.gateway_light_34ce008d4fd0
        color_name: red
        brightness: 255
    - delay:
        milliseconds: 600
    - service: light.turn_off
      data:
        entity_id: light.gateway_light_34ce008d4fd0
    - delay:
        milliseconds: 600

But how to repeat this 10 times and stop?

There may be a fancier way to do this, but one way is to create another script that calls this one ten times, waiting for it to finish between calls:

flash_gateway10:
  alias: Flash Gateway On 10 times
  sequence:
    - service: script.flash_gateway1
    - wait_template: "{{ is_state('script.flash_gateway1', 'off') }}"
    - service: script.flash_gateway1
    - wait_template: "{{ is_state('script.flash_gateway1', 'off') }}"
    - service: script.flash_gateway1
    - wait_template: "{{ is_state('script.flash_gateway1', 'off') }}"
    - service: script.flash_gateway1
    - wait_template: "{{ is_state('script.flash_gateway1', 'off') }}"
    - service: script.flash_gateway1
    - wait_template: "{{ is_state('script.flash_gateway1', 'off') }}"
    - service: script.flash_gateway1
    - wait_template: "{{ is_state('script.flash_gateway1', 'off') }}"
    - service: script.flash_gateway1
    - wait_template: "{{ is_state('script.flash_gateway1', 'off') }}"
    - service: script.flash_gateway1
    - wait_template: "{{ is_state('script.flash_gateway1', 'off') }}"
    - service: script.flash_gateway1
    - wait_template: "{{ is_state('script.flash_gateway1', 'off') }}"
    - service: script.flash_gateway1
1 Like

Thank You. It’s simply works. Is there any way to make a loop or something for this?

1 Like

Making a loop is a bitch. You need to use a counter and 2 scripts that call each other. One script would have a condition based on the count of the counter. @pnbruckner’s solution is the easiest solution by far.

2 Likes

had been looking for this indeed but this cookbook @Tinkerer linked kept me from it:

we really should have a repeat_template…

I’m thinking we just need a new action/script object type. Something like - delay inside a script. It could be named loop contain 2 attributes: count and sequence:

sequence:
  - delay:
    minutes: 4
  - loop:
    count: 10
    sequence:
     - service: light.turn_on
       entity_id: light.mylight
     - delay:
       seconds: 10
     - service: light.turn_off
       entity_id: light.mylight
4 Likes

exactly, count and sequence.
How to, proceed and realize…? A feature request maybe?

btw, ive made this and tried to have the script show an action_name, but with or without that, it shows a toggle??

19

script.call_flash_kist:
  action_name: 'Flash'
  templates:
    icon: >
      if (state === 'on') return 'mdi:flashlight';
      return 'mdi:flashlight-off';
    icon_color: >
      if (state === 'on') return 'rgb(251, 210, 41)';
      return 'rgb(54, 95, 140)';

also, this seems to be a burden on the system, it doesnt really flash regularly, and timing is rather off. Must be a better way to do this, maybe directly on the Hub (Hue or tradfri in my setting) and call a script activating that.

This is a great idea. If it were implemented count should support templates.

Another variant could be until, which could use condition syntax.

I would try creating a script that just blinks in a continuous loop. Then you can just use another script to turn on that blinking script for 1 minutes (or x blinks based on time) and then turn off that script. I use time as the counter

blink script

  • turn on light
  • wait 1 sec
  • turn off light
  • wait 1 sec
  • run blink script

to run the blinker

– turn on blink script
– wait x seconds for x blinks
– turn off blink script

Except this won’t work as I understand it, because a script that is already running can’t be started. So in your suggestion, when you get to the last line of your script it will fail because the script is already running. You would have to do this with at least two different scripts.

How about an automation that triggers on time (every 10 secs ) and turns light on and off?

We could then turn on and off the automation for a given period of time.

exactly, my thoughts.
need a for: in the action part and be done with it.

As i see it now, we’re beter of buying a strobe light you turn on and after some time off. This script at hand is really unreliable, and no more than an irregular on/off switch, no matter the delay.

Nice for an exercise in automating and scripting but not of great really life value imho.

must be the response time of the hub, and the timing on the Hassio instance.
leaving that to a dedicated light is far preferable.

I don’t think you need a for: in the automation. You just need to turn on the automation for x minutes using a delay.

If it take 2 minutes for 10 blinks you can do it by

  • turn on blink automation
  • wait 2 minutes
  • turn off blink automation

The blink automation will just blink every 10 secs using a time trigger.

Trigger

  • every 10 second

Action

  • turn on light
  • wait 5 secs
  • turn off light

Lol thats not blinking, that’s fading :wink:

Was thinking more like 4 times per second for a flash signal …

Nevertheless, I like what your saying and see good use for that too.

I see we have similar thoughts on a new loop feature for animations and scripts. Please give your vote to this feature request if you are still interested in this: Add easier solution for loops in automations/scripts