It is possible to have an automation repeat based on a condition but only once? I can use repeat until to repeat based on the condition. Or I can use repeat count (1) but I’m not sure how to combine the two.
The reason for doing this is sometimes my IKEA lights don’t transition to the correct brightness/colour - what this should do it is check the light attributes against an input number and run the automation again if the light does not have the right attributes. However I don’t want it running forever if the light just won’t update for whatever reason, so I want to put a hard stop on how many times it can repeat.
Below is my automation with only the repeat until element, how do I add a limit to how times it can repeat?
alias: Colour Brightness - State On - Lamps
description: ''
trigger:
- platform: state
entity_id: nook_lamp
to: 'on'
action:
- repeat:
until:
- condition: template
value_template: >-
'{{ (state_attr('light.nook_lamp','color_temp')|int ==
states('input_number.lamps_colour')|int) and
(state_attr('light.nook_lamp','brightness')|int ==
(states('input_number.lamps_brightness')|int*2.55)|int) }}'
sequence:
- service: light.turn_on
target:
entity_id: '{{ trigger.entity_id }}'
data:
transition: 1
color_temp: '{{ states(''input_number.lamps_colour'') | int }}'
- delay:
hours: 0
minutes: 0
seconds: 1
milliseconds: 0
- service: light.turn_on
target:
entity_id: '{{ trigger.entity_id }}'
data:
transition: 1
brightness_pct: '{{ states(''input_number.lamps_brightness'') | int }}'
mode: parallel
max: 10