Put delay on template

I want to have a delay between services is it possilbe? If yes could you help me with this?

- platform: template
  switches:
    mr_light_1:
      friendly_name: MR Light 1
      value_template: >
        {% if is_state('group.mainlightstat1', 'on') %}
          true
        {% else %}
          false
        {% endif %}
      turn_on:
        - service: switch.turn_on
          data:
            entity_id: switch.main_light
        - service: light.turn_on
          data:
            entity_id: 
              - light.ty65243476600194fc3752
              - light.ty65243476d8f15bca69a5
      turn_off:
        - service: light.turn_off
          data:
            entity_id: 
              - light.ty65243476600194fc3752
              - light.ty65243476d8f15bca69a5
        - service: switch.turn_off
          data:
            entity_id: switch.main_light
      icon_template: mdi:lightbulb-group-outline

So there are 2 services for light.turn_on and switch.turn_on however I want to add delay between these two services. Is it possible? Any help would be great. Thanks

Yes, you can add a delay between the services. The following example contains a 2 second delay.

- platform: template
  switches:
    mr_light_1:
      friendly_name: MR Light 1
      value_template: "{{ is_state('group.mainlightstat1', 'on') }}"
      turn_on:
        - service: switch.turn_on
          target:
            entity_id: switch.main_light
        - delay: '00:00:02'
        - service: light.turn_on
          target:
            entity_id: 
              - light.ty65243476600194fc3752
              - light.ty65243476d8f15bca69a5
      turn_off:
        - service: light.turn_off
          target:
            entity_id: 
              - light.ty65243476600194fc3752
              - light.ty65243476d8f15bca69a5
            entity_id: switch.main_light
        - delay: '00:00:02'
        - service: switch.turn_off
          target:
            entity_id: switch.main_light
      icon_template: mdi:lightbulb-group-outline

BTW, this:

value_template: "{{ is_state('group.mainlightstat1', 'on') }}"

functions the same as this:

value_template: >
  {% if is_state('group.mainlightstat1', 'on') %}
    true
  {% else %}
    false
  {% endif %}
1 Like

Thank you so very much…