Automation Time Trigger every X base on hleper

looking for an Automation that Trigger based on Time X

I try this but not work

Log Details (ERROR)
Logger: homeassistant.config
Source: config.py:454
First occurred: 3:57:34 am (1 occurrences)
Last logged: 3:57:34 am

Invalid config for [automation]: invalid time_pattern value for dictionary value @ data['hours']. Got None. (See /config/configuration.yaml, line 21).
- id: '1652484915824'
  alias: Home Water Pump Up
  description: ''
  trigger:
  - platform: time_pattern
    hours: "{{ states('input_number.home_water_pump_up_trigger') }}"
  condition: []
  action:
  - service: script.water_pump_up_on
    data: {}
  mode: single
  home_water_pump_up_trigger:
    name: Home Water Pump Up Trigger
    icon: mdi:timer-sync-outline
    unit_of_measurement: "h"
#    initial: 30
    min: 1
    max: 168
    step: 1
    mode: box

maybe it works with template Trigger, I don’t have idea how I setup :thinking:

Unless an option specifically states it supports templates, then it doesn’t. The time pattern trigger doesn’t.

You can use a template trigger:

trigger:
  platform: template
  template: "{{ now().hour % states('input_number.home_water_pump_up_trigger')|int(1) == 0 }}"

The modulo arithmetic operator a % b returns the remainder of the division of a by b. If it is zero then it is a whole multiple of your input number. Basically equivalent to the time pattern trigger.

So templates aren’t accepted in time pattern triggers but also that’s the wrong type of trigger. Time pattern is only for when you want something to trigger at a specific time each day (or whenever the time matches a pattern every day). But your input number starts at 30 hours and can go as high as a week. That’s not a time pattern trigger.

In your case it seems like you want something like this:

- id: '1652484915824'
  alias: Home Water Pump Up
  description: ''
  trigger:
  - platform: template
    value_template: >-
      {{ now() - timedelta(hours=states('input_number.home_water_pump_up_trigger') | int)
          > state_attr('automation.home_water_pump_up', 'last_triggered') }}
  condition: []
  action:
  - service: script.water_pump_up_on
    data: {}
  mode: single

So when the current time minus the number of hours in your number is greater than the last time this automation triggered it’ll trigger again. Believe that should get you what you want.

1 Like

Hi @tom_l , @CentralCommand

Sorry for the delay replay I put both templates in the test

home_water_pump_up_trigger = 1

for @tom_l template never triggered

- id: '1652510460420'
  alias: Home Main Pump
  description: ''
  trigger:
  - platform: template
    value_template: '"{{ now().hour % states(''input_number.home_water_pump_up_trigger'')|int(1)
      == 0 }}"'
  condition: []
  action:
  - service: notify.mobile_app_ali_mobile
    data:
      message: template 1
  mode: single

for @CentralCommand template

- id: '1652511463914'
  alias: New Automation test
  description: ''
  trigger:
  - platform: template
    value_template: '{{ now() - timedelta(hours=states(''input_number.home_water_pump_up_trigger'')
      | int) > state_attr(''automation.new_automation_test'', ''last_triggered'')
      }}'
  condition: []
  action:
  - service: notify.mobile_app_ali_mobile
    data:
      message: template 2
  mode: single

this is the result!

Yes because I did not look at your input number values as explained by Mike here:

yes I see thanks
thanks