For: minutes: as script variable?

I’m using a condition in a script to check if a light is on for X minutes. Default is 30;

- condition: state
  entity_id: light.light1
  state: on
  for:
    minutes: 30

Which works as expected. I am however looking for a solution to pass the minutes as variable, so I can call the script from multiple automations with different “minutes”.

- service: script.turn_on
  entity_id: script.light_test
  data:
    variables:
      minutes: 30

But I can’t figure out how I can include the variable correctly. Any tips on how I can solve this?

As stated in the documentation:

variables can be passed along to a script so they become available within templates in that script

However, for doesn’t accept a template so you can’t dynamically assign values to it.

1 Like

Thanks for the reply @123 :slight_smile: I was expecting it wouldn’t be possible this way, was hoping I was wrong… I solved it with some conditions at this moment as I only need to switch between 2 values (0 or 30). I would expect there are more elegant solutions for this case, but this was the first one on my mind (and it looks like it works after a short first test).

    - condition: or
      conditions:
        - condition: template
          value_template: "{{ minutes == 0 }}"                 
        - condition: and
          conditions:
            - condition: template
              value_template: "{{ minutes == 30 }}"                 
            - condition: state
              entity_id: light.light1
              state: on
              for:
                minutes: 30