Discussed here: Associer un bouton +/- au slider de couleur ou luminosité - #16 par lmilcent
Description
Allow, in a scene, repeating an action until one or more criteria are met.
Example
Allow pressing a button to increase a bulb’s brightness step by step.
While : action = « brightness_move_up » and brightness < 100
Then:
I’m resending this request because it’s exactly what I need for my IKEA buttons
Since it’s the most requested feature, I’ve started working on Fable 5!
His proposal:
Docker image:
ghcr.io/gladysassistant/gladys-preview:claude-scenes-controlled-loops-sceu7j
The PR:
master ← claude/scenes-controlled-loops-sceu7j
ouvert 09:16AM - 02 Aug 26 UTC
### Description
This PR adds a new "while loop" action (`ACTIONS.CONDITION.WHIL… E`) to the scene automation system, enabling users to repeatedly execute a block of actions as long as specified conditions remain true.
**Key features:**
- Conditions are re-evaluated before each iteration
- Safety limits: default max 1000 iterations, absolute max 10000 (configurable)
- Minimum 100ms per iteration to prevent CPU-intensive tight loops
- Loop aborts if conditions are empty (prevents infinite loops)
- Full error handling and propagation from condition evaluation
**Changes include:**
- Backend action handler in `scene.actions.js` with iteration logic and safety guards
- Frontend UI component (`ConditionWhile.jsx`) with collapsible repeat section and max iterations input
- Comprehensive unit tests covering: normal execution, condition re-evaluation, max iterations limit, empty conditions error, and error handling
- i18n translations for English, French, and German
- Schema validation in MCP and Joi models
- Integration with scene variable tracking and action card rendering
### Checklist
- [x] Tests pass: Added comprehensive unit tests in `scene.action.conditionWhile.test.js` covering all scenarios (5 test cases with 100% coverage of new code)
- [x] Linter and prettier pass on both front and server
- [x] No breaking changes
https://claude.ai/code/session_01EAhGR17j5RnYsLsVU5CdWu
## Summary by CodeRabbit
* **New Features**
* Added a **While** condition action for scenes.
* Configure conditions, repeated actions, and a maximum of 10,000 iterations.
* Conditions are re-evaluated during execution, and actions run sequentially.
* Added English, German, and French translations.
* **Bug Fixes**
* Improved validation and handling of nested While actions.
* Added safeguards against invalid or unbounded loop configurations.
* While loops stop when conditions fail, execution is aborted, or the iteration limit is reached.
What do you think?
I haven’t looked at the PR, but is the case « the condition is never met » handled? To avoid zombie scenes
There is a maximum number of iterations defined by the user (you can see it on the screenshot, by the way!)
Nice that you’re starting this dev
I suggest moving the ‹ max number of iterations › parameter to the top of the structure, so it doesn’t end up too far away if the ‹ repeat › block is a bit long…
very well: but I see that in the triggering conditions there is the « OR », but we would especially need the « AND » (ex: pressing a button AND brightness < 100%)
To make « AND » conditions, just add a condition!
Indeed, I just found out that you can do ANDs on conditions! Thanks
We should make that clear in the docs!
Great feedback, I’m improving the block:
Perfect: at least it’s very clear and you can’t miss it!
Tested and approved, development will be included in the next version of Gladys
I’m closing this post as the feature is available in Gladys Assistant 4.86:
Hi everyone!
Super excited to release Gladys Assistant 4.86.
It’s simple, it’s the biggest version since the start of the project, with 68 PRs merged in one week
It’s just incredible, and it shows the new pace we can keep with AI.
The goal is now clear: catch up with and surpass Home Assistant
I’ll talk about these 68 new features here:
Thanks to all the contributors!!