"time_pattern" trigger: support templates for "hours", "minutes", "seconds"

In blueprints it would be useful to have a possibility to define templated values for “time_pattern” components.
Consider this faulty automation:

image

description: ""
mode: single
trigger:
  - platform: time_pattern
    minutes: >-
      {{ "/1" }}
condition: []
action:
  - service: notify.persistent_notification
    data:
      message: xxx

Use case: using helpers to define a time_pattern.

You can do this with template triggers.

trigger_variables:
  entity_id: !input some_entity_selector
trigger:
- platform: template
  value_template: "{{ now().minute % states(entity_id) | int }}"
1 Like

Thank you, this is what I do now (not exactly this code, a similar one).
Just wanted to propose some more flexibility…

   {{ (now().timestamp()|int(default=0) % (MINUTES|int * 60) == 0)  }}

Yeah, this method won’t work for seconds. But then again, even if we add templates to seconds, it still won’t work for seconds because there’s nothing in templates that automatically creates a per-second resolution.

yes, and time_pattern trigger seems to support seconds (never tested myself).

I still cannot get past this. My automation won’t run based on the input I set:

blueprint:
  name: Time Pattern Notification
  description: Sends a notification at a variable time interval defined within the blueprint.
  domain: automation
  input:
    time_interval_minutes:
      name: Time Interval (minutes)
      description: The interval in minutes for the notification to trigger.
      default: 15
      selector:
        number:
          min: 1
          max: 60
          unit_of_measurement: minutes
    target_device:
      name: Target iPhone Device
      description: The mobile device to send the notification to.
      selector:
        device:
          integration: mobile_app

trigger_variables:
  interval: !input time_interval_minutes
trigger:
- platform: template
  value_template: "{{ now().minute % states(interval) | int }}"

actions:
  - data:
      message: test
    action: notify.mobile_app_iphone_X

What’s wrong??

Removes states() | int from your template and keep just interval.

Still doesn’t trigger, this is the blueprint code:

blueprint:
  name: Time Pattern Notification
  description: Sends a notification at a variable time interval defined within the blueprint.
  domain: automation
  input:
    time_interval_minutes:
      name: Time Interval (minutes)
      description: The interval in minutes for the notification to trigger.
      default: 15
      selector:
        number:
          min: 1
          max: 60
          unit_of_measurement: minutes
    target_device:
      name: Target iPhone Device
      description: The mobile device to send the notification to.
      selector:
        device:
          integration: mobile_app

trigger_variables:
  interval: !input time_interval_minutes
trigger:
- platform: template
  value_template: "{{ now().minute % interval }}"

actions:
  - data:
      message: test
    action: notify.mobile_app_iphone_di_filippo

and this is the actual BP config:

Fixed:

variables:
  interval: !input time_interval_minutes

value_template: >
      {{ (now().minute % interval | int) == 0 }}

time_interval_minutes is of course declared at the beginning of the blueprint:

 input:

    time_interval_minutes:
      name: Time Interval (minutes)
      description: The interval in minutes for the automation to trigger
      default: 15
      selector:
        number:
          min: 1
          max: 60
          unit_of_measurement: minutes