#Dynamic values in time_pattern trigger and delay action

1 messages · Page 1 of 1 (latest)

viral badger
#

Hi, is there any way to have dynamic values for the time_pattern trigger and the delay action in the following automation?

alias: Inline ventilator, toggle (every 10 min)
description: ""
triggers:
  - minutes: /10
    trigger: time_pattern
actions:
  - data: {}
    action: switch.turn_on
    target:
      device_id: 64d5bd0912402dc24f77de858a01cac5
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - data: {}
    action: switch.turn_off
    target:
      device_id: 64d5bd0912402dc24f77de858a01cac5
mode: single

I have two input_number helper that I want to read the values from in best case scenario:

  • input_number.inline_ventilator_trigger_timepattern
  • input_number.inline_ventilator_delay_in_minutes

Any input is appreciated.
TIA!

plush sigil
viral badger
#

Nice, good to know about the delay template. Any idea what I could use instead for the time pattern?

plush sigil
#

what's the goal, to trigger every X minutes, where X is an input_number?

viral badger
#

Basically, trigger every X minutes for Y minutes - where both X and Y is an input_number helper.

#

I tried something like this, but it didn't seem to work

triggers:
  - value_template: >-
      {{ now().minutes %
      states('input_number.inline_ventilator_trigger_timepattern')|int(2) == 0 }}
    trigger: template
plush sigil
#

it's now().minute

flint flame
#

template triggers need to resolve false before resolving true in order to trigger 🎉

plush sigil
#

As long as the pattern is > 1 it should be fine?

flint flame
#

probably yes

plush sigil
#

Also "every N minutes" would more accurately be something like

{{ (now()|as_timestamp / 60) | int % N }}
#

using now().minute % 45 will not trigger every 45 minutes, but once per hour at XX:45

flint flame
#

Yeah, I usually use midnight myself

#
{{ ((now() - today_at()).total_seconds() // 60) % N }}
#

FYI if you use //, it makes an int

#

it's called int division

hollow storm
#

for a trigger you could use
{{ not ((now() - today_at()).total_seconds() // 60) % N }}
or just
{{ ((now() - today_at()).total_seconds() // 60) % N == 0 }}

#

otherwise it will trigger every minute besides the one you want 🙂

flint flame
#

@plush sigil looks like JS does not have int division

#

have to use math.floor

#

I commonly use it in python, seems odd not to have it. 🤷‍♂️

plush sigil
#

Interesting JS:

> ~~(10/3)
3
> (10/3) | 0
3
viral badger
#

Okay, will try this now and let you know in about 10 minutes if it worked :)

alias: Inline ventilator, toggle
description: ""
triggers:
  - value_template: >-
      {{ ((now() - today_at()).total_seconds() // 60) %
      (states('input_number.inline_ventilator_trigger_time_pattern')|int) == 0
      }}
    trigger: template
actions:
  - data: {}
    action: switch.turn_on
    target:
      device_id: 64d5bd0912402dc24f77de858a01cac5
  - delay: >-
      {{ (states('input_number.inline_ventilator_delay_in_minutes') | int) * 60
      }}
  - data: {}
    action: switch.turn_off
    target:
      device_id: 64d5bd0912402dc24f77de858a01cac5
mode: restart
#

Works like a charm, thanks for the input @plush sigil @flint flame and @hollow storm