I would like to have this automation trigger every 4 hours, but it is not passing validation. I suspect it is due to the repeat action I have.
- alias: 'switchbot updates'
trigger:
- platform: time
hours: '/4'
action:
- repeat:
count: "{{ state_attr('input_select.switchbot_updates', 'options') | count }}"
sequence:
- choose:
conditions: []
sequence:
- service: mqtt.publish
data:
topic: switchbotmqtt/requestInfo
payload: >-
{% set bot = state_attr('input_select.switchbot_updates', 'options')[repeat.index] %}
{"device":"{{ bot }}"}
- delay: 20
error:
Invalid config for [automation]: [hours] is an invalid option for [automation]. Check: automation->hours. (See /config/configuration.yaml, line 26).
The problem (or, at least, a problem) is the trigger itself. See Time Trigger and Time Pattern Trigger.
1 Like
I saw those pages and the answers were written all over the places, yet my eyes missed it.
- alias: 'switchbot updates'
trigger:
- platform: time_pattern
hours: '/4'
action:
- repeat:
count: "{{ state_attr('input_select.switchbot_updates', 'options') | count }}"
sequence:
- choose:
conditions: []
sequence:
- service: mqtt.publish
data:
topic: switchbotmqtt/requestInfo
payload: >-
{% set bot = state_attr('input_select.switchbot_updates', 'options')[repeat.index] %}
{"device":"{{ bot }}"}
- delay: 20
Does the trigger time starts at 00:00, 04:00, 06:00, etc or the time I created the automation?
Given the way you wrote the trigger it will fire when the hour is a multiple of 4 (0, 4, 8, … 20), and minutes & seconds are zero.
I have to ask, why does the automation action contain an effectively useless choose
statement? Why not just put the service call and delay directly in the repeat
's sequence
?
I am undecided if I will create a condition. If I do, I may not remember how to added later.
A condition for the automation? If so, that’s not how you do it.