Time Pattern vs. Template Trigger

I would like to update my two Google Maps Travel Time sensors every 15 minutes between 6am and 10pm and every 30 minutes between 10pm and 6am. This should keep me below the free 5000 calls per month:

((2 updates per hour x 8 hours)+(4 x 16)) x 31 days = 2480 updates per sensor per month

Now I’m struggling to write a compact automation for this. Unfortunately, the “time pattern trigger” does not support ranges (Feature Request Time Pattern needs to support ranges). I could write two automations, with the times as “condition”, but that doesn’t seem elegant to me. I have little experience with template triggers, could something like this work?

{{ (6 <= now().hour % 12 <= 22 and now().minute % 15 == 0) or now().minute % 30 == 0 }}

I’ve become a bit cautious - I already paid 50 EUR to Google last month because I miscalculated the number of updates and hadn’t configured a quota :innocent:

Just use the time pattern trigger with a condition.

  triggers:
    - trigger: time_pattern
      minutes: "/15"
  conditions:
  - condition: time
    after: "10:00:00"
    before: "06:00:00"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri

Yes, that is possible, but then I need two automations, right?

No, you can use 2 in a single automation using trigger id’s. You’ll have a very hard time getting this to work properly with a template trigger without using a similar process.

Hmm. Something like this?

description: ""
mode: single
triggers:
  - trigger: time_pattern
    minutes: /15
    id: quarter-hourly
  - trigger: time_pattern
    minutes: /30
    id: half-hourly
conditions:
  - condition: and
    conditions:
      - condition: trigger
        id:
          - quarter-hourly
      - condition: time
        after: "06:00:00"
        before: "21:59:59"
  - condition: and
    conditions:
      - condition: trigger
        id:
          - half-hourly
      - condition: time
        after: "22:00:00"
        before: "05:59:59"
actions:
  - action: homeassistant.update_entity
    metadata: {}
    data:
      entity_id:
        - sensor.travel_work
        - sensor.travel_del

You’ll need a top level or condition, but yes

Ooops, you’re right. Thanks!

alias: "Update \"Google Maps Travel Time\" "
description: ""
triggers:
  - trigger: time_pattern
    minutes: /15
    id: quarter-hourly
  - trigger: time_pattern
    minutes: /30
    id: half-hourly
conditions:
  - condition: or
    conditions:
      - condition: and
        conditions:
          - condition: trigger
            id:
              - half-hourly
          - condition: time
            after: "22:00:00"
            before: "05:59:59"
      - condition: and
        conditions:
          - condition: trigger
            id:
              - quarter-hourly
          - condition: time
            after: "06:00:00"
            before: "21:59:59"
actions:
  - action: homeassistant.update_entity
    metadata: {}
    data:
      entity_id:
        - sensor.travel_work
        - sensor.travel_del
mode: single