# Scènes : un déclencheur « Plages horaires »

**URL:** <https://community.gladysassistant.com/t/scenes-un-declencheur-plages-horaires/10712>\
**Category:** Développement\
**Tags:** scene\
**Created:** [Août 26, 2026, 9:40 UTC](https://community.gladysassistant.com/t/scenes-un-declencheur-plages-horaires/10712 "2026-08-26T21:40:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Will\_71](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/will_71/32/9582_2.png) [@Will\_71](https://community.gladysassistant.com/u/Will_71)\
**Post date:** [Août 26, 2026, 9:40 UTC](https://community.gladysassistant.com/t/scenes-un-declencheur-plages-horaires/10712/1 "2026-08-26T21:40:05Z")

</div>

Aujourd’hui, pour piloter un équipement sur un planning, il faut deux scènes :  
une qui allume, une qui éteint, chacune avec son déclencheur programmé, et  
c’est à vous de les garder cohérentes. Si vous ajoutez une plage le week-end,  
il faut penser à la reporter des deux côtés.

Cette PR ajoute un nouveau type de déclencheur programmé, **« Plages  
horaires » **, qui permet de mettre tout un planning dans** une seule scène**.

> <https://github.com/GladysAssistant/Gladys/pull/3015>
>
> \## Scenes: add a "time ranges" scheduled trigger
> 
> Today, driving a device from… a weekly planning requires two scenes: one to
> turn it on, one to turn it off, each with its own scheduled trigger, kept in
> sync by hand. This PR adds a \`time-range\` scheduler type so a whole planning
> lives in a single scene.
> 
> \### The trigger
> 
> A new \*\*Time ranges\*\* option in the scheduled trigger. You configure a list of
> ranges (\`start\` → \`end\`, "HH:mm") and the days of the week they apply to. The
> scene runs at the \*\*start\*\* and at the \*\*end\*\* of every range, and the trigger
> tells the scene which boundary fired.
> 
> \- A range is active from its start (included) to its end (excluded), so two
> consecutive ranges (\`10:00 → 12:00\` then \`12:00 → 14:00\`) never report the
> same minute twice.
> \- Ranges crossing midnight are supported (\`22:00 → 06:00\`). The days of the
> week always apply to the \*\*start\*\* of the range: configured on monday, that
> range runs from monday 22:00 to tuesday 06:00.
> \- A range whose start equals its end covers nothing and is never scheduled.
> \- Ranges are sorted in the editor, and a new one is no longer pre-filled.
> 
> \### The condition
> 
> A new \*\*\`scene.in-time-range\`\*\* action, meant to sit in an \`If… Then… Else\`
> block: "then" is the inside of the planning, "else" is the outside. One scene,
> one device, on at the start of every range and off at the end.
> 
> When the scene was started by one of its own time-range jobs, the condition
> trusts the boundary carried by the trigger instead of re-computing it — a job
> firing exactly at the end of a range could otherwise still be seen as "inside"
> a few milliseconds later. Started any other way (manually, by another trigger,
> by another scene), the state is computed from the ranges of the scene's
> time-range triggers. The scene selector check matters here: \`scene.start\` hands
> a child scene a clone of the scope, so without it a called scene would answer
> for the ranges of its caller.
> 
> \### Resume on startup
> 
> Jobs are scheduled for the future only, so a boundary crossed while Gladys was
> down is never replayed: a pool pump stopped by a power cut would stay off for
> the rest of the range, and one left on would keep running long after the range
> ended.
> 
> With the optional \*\*resume on startup\*\* checkbox, the scene is executed once at
> startup with \`range\_event = 'resume'\` and \`in\_range\` telling whether we are
> currently inside the planning. The scene re-applies the wanted state itself —
> Gladys does not know which device it drives, so re-applying is both simpler and
> safer than guessing. The resume runs \*\*once per boot\*\*: \`init()\` also runs when
> the user changes the timezone in the settings, and re-applying the planning
> then would run these scenes again for no reason.
> 
> \<img width="1133" height="638" alt="image" src="https://github.com/user-attachments/assets/3d12f634-aed8-4af5-ba82-05beea28a6be" /\>
> 
> \<img width="1142" height="271" alt="image" src="https://github.com/user-attachments/assets/01455b56-2074-4d08-b5d8-e01e4cf366a4" /\>
> 
> \### Checklist
> 
> \- \[x\] Tests pass: \`cd server && npm run coverage\` (Codecov requires 100% coverage on changed lines) and Cypress (\`npm run cypress:run\`) if the UI changed
> \- \[x\] Linter and prettier pass on both front and server (\`npm run eslint\`, \`npm run prettier\`)
> \- \[x\] No undocumented breaking change
> 
> 
> 
> 
> 
> \## Summary by CodeRabbit
> 
> \* \*\*New Features\*\*
> \* Added time-range scheduling for scenes, with configurable start/end times, weekdays, overnight ranges, and optional startup resumption.
> \* Added an “In time range” scene condition for running actions based on the current schedule.
> \* Added localized English, German, and French labels and guidance.
> 
> \* \*\*Bug Fixes\*\*
> \* Incomplete time ranges are removed before saving, preventing invalid scene configurations.
> \* Improved validation for invalid times, empty schedules, and duplicate start/end times.

### Comment ça marche

Dans le déclencheur, vous ajoutez autant de plages que vous voulez (une heure  
de début, une heure de fin) et vous choisissez les jours de la semaine  
concernés. La scène est exécutée **au début et à la fin de chaque plage**.

Ensuite, vous ajoutez l’action **« Planning horaire »** dans un bloc  
« Si… Alors… Sinon » :

- **Alors** → on est dans une plage : vous allumez
- **Sinon** → on est en dehors : vous éteignez

Une scène, un équipement, et le planning que vous voulez.

**La reprise après une coupure.** C’est le point que je trouve le plus utile.  
Les tâches sont planifiées pour le futur uniquement : si Gladys est arrêté au  
moment où une plage commence ou se termine, ce moment n’est jamais rattrapé.  
Concrètement, une pompe de piscine coupée par une panne de courant resterait  
éteinte jusqu’à la fin de la plage — ou pire, une pompe restée allumée  
continuerait de tourner longtemps après la fin.

Il y a donc une case **« Réévaluer au démarrage »**. Si elle est cochée, la  
scène est exécutée une fois au démarrage de Gladys avec l’état réel du  
planning (dans une plage ou pas), et c’est la scène qui remet l’équipement  
dans le bon état. Gladys ne sait pas quel équipement vous pilotez : plutôt que  
de deviner, il vous redonne la main.

### Exemples d’usage

- Pompe de piscine : plusieurs créneaux dans la journée, différents l’été et  
l’hiver, et l’état est remis correctement après une coupure de courant
- Chauffage : `06:00 → 08:30` et `18:00 → 23:00` en semaine, plage large le  
week-end
- Éclairage extérieur : `22:00 → 06:00`, une plage qui passe minuit

 ![image](https://gladys-assistant-community.b-cdn.net/uploads/default/original/3X/6/9/69615f0896726f997b536f5dbae46362d3961afe.png)

 ![image](https://gladys-assistant-community.b-cdn.net/uploads/default/original/3X/2/4/248828046bfab4d997ca7b9f6e7f18bf62f20edf.png)
