En tant qu’utilisateur,
Je veux pouvoir savoir quel device/condition à déclencher une scène,
Afin de l’utiliser dans d’autres actions
Ex :
J’ai une scène ouverture de porte (avec le tag alarme ) et lorsque une porte s’ouvre, je récupère l’état de toutes les portes et j’envoie un message pour me dire regarde l’état des portes.
Moi ce que j’aurais voulu faire c’est simplement savoir quel porte déclenche la scène directement (c’est moins fastidieux que d’aller tout récupérer etc.)
Qu’en pensez vous?
Je te rejoints sur le besoin, mais avec une reflexion un peu plus globale.
Ma scene de detection des intrusions a la maison attends qu’une porte, fenetre ou un capteur de mouvement se declenche et m’envoie ensuite un message.
Sauf que le message est une liste de tous les peripheriques avec leur valeur (0 ou 1). Ce n’est pas super friendly.
Le mieux serais d’afficher « ouvert / fermé » par exemple dans le message. Et ajouter une variable par defaut avec les données du périphérique déclencheur de la scène ?
Je pense que cest une demande a part
Les portes pour moi cetait un exemple ^^
En gros si une scenes se declenche je veu identifier qui a declencher la scène.
Imagine,
j’ai une scene qui vérifie l’état de mes pneus, si la scene ce déclenche, la variable « deviceTrigger » est instancier avec le pneu qui a declencher la scene et ensuite je fais un message avec « {{ deviceTrigger est a changer »
C’est ce fonctionnement que je propose
Je pense que toi tu souhaites un mapping 0 fermer 1 ouvert pour les capteur d’ouverture ?
Je propose la même chose que toi je pense.
Mais en effet j’ai aussi proposé le mapping inverse pour passer de 0/1 à "ouvert / fermé”
Du coup je n’avais pas compris ^^
Bonsoir,
J’ai voté pour intégrer cette fonctionnalité
Je vais donner un exemple
Je créer une scène avec tout mes capteurs de température en déclencheur si on dépasse un certain seuil.
Si ce seuil est dépassé alors on envoi un message avec l’information du déclencheur de scène ainsi que la température associé à ce déclencher.
Je peux récupérer l’information de la température avec « Récupérer le dernier état » mais je ne peux pas avoir l’info de qui à déclencher la scène
En espérant que cette fonctionnalité arrivera vite dans Gladys
@prohand tu te lance dessus ?
Sa fait deux ans que tu l’attends ahah
Pardon je n’ai pas synchronisé l’état ici mais c’est bien déjà développé :
master ← claude/gladys-feature-request-clny6j
ouvert 07:14PM - 23 Jul 26 UTC
### Pull Request check-list
To ensure your Pull Request can be accepted as fast… as possible, make sure to review and check all of these items:
- [x] If your changes affect the code, did you write the tests?
- [x] Are server tests passing with coverage? (`cd server && npm run coverage`) — Codecov requires **100% coverage on lines changed in this PR** (full scene test suite passing locally: 229 tests, all branches of the new code are exercised)
- [ ] Did Cypress E2E tests pass? (`npm run cypress:run` from repo root, if UI changed)
- [x] Is the linter passing? (`npm run eslint` on both front/server)
- [x] Did you run prettier? (`npm run prettier` on both front/server)
- [x] If you are adding a new feature/service, did you run the integration comparator? (`npm run compare-translations` on front)
- [ ] Did you test this pull request in real life? With real devices? If this development is a big feature or a new service, we recommend that you provide a Docker image to the community ([forum](https://community.gladysassistant.com/)) for testing before merging. An AMD64 preview image is built automatically for non-draft PRs; for ARM64, comment `/build-arm64` on the PR.
- [ ] If your changes modify the API (REST or Node.js), did you modify the API documentation? (Documentation is based on comments in code)
- [ ] If you are adding a new features/services which needs explanation, did you modify the user documentation? See [the GitHub repo](https://github.com/GladysAssistant/v4-website) and the [website](https://gladysassistant.com).
- [ ] Did you add fake requests data for the demo mode (`front/src/config/demo.js`) so that the demo website is working without a backend? (if needed) See [https://demo.gladysassistant.com](https://demo.gladysassistant.com).
NOTE: these things are not required to open a PR and can be done afterwards / while the PR is open.
### Description of change
Implements the community feature request [Avoir la possibilité de récupérer qui a déclenché la scène](https://community.gladysassistant.com/t/avoir-la-possibilite-de-recuperer-qui-a-declencher-la-scene/8534).
When a scene is triggered by a device state change (`device.new-state`), scene actions can now use variables identifying the trigger in their texts (send message, SMS, HTTP request, MQTT, ask AI…):
- `{{triggerEvent.device.name}}` — name of the device that triggered the scene
- `{{triggerEvent.deviceFeature.name}}` — name of the device feature
- `{{triggerEvent.last_value}}` — the new value
- `{{triggerEvent.previous_value}}` — the previous value
Example: a single scene with several door sensors as triggers can now send "{{triggerEvent.device.name}} was just opened" instead of requiring one scene per door.
**Server** (`server/lib/scene/scene.checkTrigger.js`): when a `device.new-state` trigger fires, the trigger event injected into the scene scope is enriched with the related device & device feature (name + selector), looked up in RAM through the `stateManager` (no DB query, computed once per event). If the feature is not found in RAM, the event is passed through unchanged.
**Front** (`DeviceFeatureState.jsx`, `TriggerCard.jsx`): the device state trigger now exposes these variables in the scene editor variable picker, following the exact same pattern as the calendar trigger (`setVariablesTrigger`). They automatically appear in every action input using `TextWithVariablesInjected`.
**Translations**: added in English, French and German (`compare-translations` passing).
**Tests**: new end-to-end server test verifying that a scene triggered by a device state change renders the enriched variables in a sent message (`Garage door (Door state) = 1`).
---
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01QB1TD1R94bgsRT8qjnM2mv
---
_Generated by [Claude Code](https://claude.ai/code/session_01QB1TD1R94bgsRT8qjnM2mv)_
## Summary by CodeRabbit
* **New Features**
* Added scene variables for the triggering device, feature, current value, and previous value in device state-change actions.
* Added translated labels for these variables in English, French, and German.
* Device state-change variables are displayed consistently without duplicate trigger numbering.
* **Bug Fixes**
* Device state-change events now include relevant device and feature details when scenes run.
* Improved handling when device or feature information is unavailable while preserving event values.
Parfait
Merci @pierre-gilles
As tu des news sur ce sujet ?
J’essayais de voir si sa fonctionnais et… J’avais pas vu que c’étais pas encore merge
Salut tout le monde !
Ce sujet est désormais en cours de développement .
Une PR a été ouverte pour exposer, dans les actions d’une scène, le nom de l’appareil (et de la fonctionnalité) qui a déclenché un changement d’état :
master ← claude/funny-keller-5760sn
opened 06:03PM - 27 Nov 26 UTC
### Description
A scene started by a device state trigger can now say **which d… evice fired it**. One scene watching several doors sends "Garage door was just opened" instead of needing one scene per door.
The trigger hands four variables to the steps of the scene, usable wherever a variable is (messages, SMS, HTTP, MQTT, Ask AI, formulas…):
| Variable | Label in the editor | What it holds |
| --- | --- | --- |
| `{{triggerEvent.device.name}}` | Trigger device name | name of the device whose feature changed |
| `{{triggerEvent.deviceFeature.name}}` | Trigger feature name | name of that feature |
| `{{triggerEvent.last_value}}` | Trigger new value | the value which fired the trigger |
| `{{triggerEvent.previous_value}}` | Trigger previous value | the value just before |
This is a rewrite on top of the current `master` of https://github.com/GladysAssistant/Gladys/pull/2708, which was 401 commits behind and conflicting. It supersedes that pull request, which can be closed. The variable names are the same.
**What changed compared with the previous pull request**
- **Server**: `master` now lets the checker of a trigger return the trigger event the actions see (added for the triggers of external integrations). The device state checker uses that instead of a special case in `checkTrigger`: on a match it returns the event completed with `device` and `deviceFeature` (name + selector), both read in RAM. Nothing is computed for an event no scene matches, and the emitted event is not modified.
- **Front**: the trigger form declares its variables on mount, like the calendar and integration triggers. No change to `TextWithVariablesInjected`: `master` already lists a variable declared by several triggers once, and the stale-list fix of the previous pull request is not needed there (checked in the browser and by the new Cypress spec).
- **Labels**: every label names the trigger, following the last review comment on the previous pull request ("Nouvelle valeur" was too generic) — "Nouvelle valeur du déclencheur", "Valeur précédente du déclencheur", "Nom de l'appareil déclencheur", "Nom de la fonctionnalité déclencheuse". Translated in English, French, German and Spanish.
- **MCP**: the scene schema given to the assistant names the four variables, so a scene created through MCP can use them.
- **Spec**: new section C.8 in `docs/specs/scene-editor-mobile.md`.
Reviewing note: most of the diff of `server/lib/scene/scene.triggers.js` is the device state checker moving out of the `triggersFunc` object into a named function, so an indentation change. With whitespace hidden, the change is the 20 lines of `buildDeviceNewStateTriggerEvent`.
**Behavior worth knowing**
- With "for a duration", the scene starts when the timer ends: `last_value` is the value at that moment and `previous_value` the one which started the timer.
- `triggerEvent.deviceFeature.name` is the name stored on the feature, not the translated category the editor shows for a device with a single feature of a kind.
- The values are raw (`0` / `1` for a door): readable states ("open / closed"), asked in the same forum topic, are a separate subject.
### Related request
Forum: https://community.gladysassistant.com/t/avoir-la-possibilite-de-recuperer-qui-a-declencher-la-scene/8534
### Checklist
- [x] If a forum topic or GitHub issue exists, the description links it (`Forum: https://community.gladysassistant.com/t/...` or `Closes #...`)
- [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 — `npm run coverage` passes, `scene.triggers.js` has no uncovered line or branch. For Cypress, the nine scene specs were run locally (69 tests, the new `SceneTriggerVariables.cy.js` included), not the whole suite.
- [x] Linter and prettier pass on both front and server (`npm run eslint`, `npm run prettier`) — plus `compare-translations` and `npm run build` on the front
- [x] No undocumented breaking change
Also checked on a booted instance with a real state change (`device.saveState` on a seeded sensor): the message of the scene read "Test device / Test temperature sensor celsius: 20 -> 30". Not tested with physical devices.
---
_Generated by [Claude Code](https://claude.ai/code)_
N’hésitez pas à suivre la PR, à tester (optionnel, surtout pour les petites demandes) et à faire vos retours ici si besoin.