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
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.