Como usuario,
Quiero poder saber qué dispositivo/condición ha activado una escena,
Para poder usarlo en otras acciones
Ejemplo:
Tengo una escena de apertura de puerta (con la etiqueta alarma ) y cuando una puerta se abre, obtengo el estado de todas las puertas y envío un mensaje para decirme que revise el estado de las puertas.
Lo que yo habría querido hacer es simplemente saber qué puerta activó la escena directamente (es menos tedioso que tener que recuperar todo, etc.)
¿Qué opinan?
Estoy de acuerdo contigo, pero con una reflexión un poco más global.
Mi escena de detección de intrusiones en casa espera a que una puerta, ventana o un sensor de movimiento se active y luego me envía un mensaje.
Pero el mensaje es una lista de todos los periféricos con su valor (0 o 1). No es muy amigable.
Lo ideal sería mostrar « abierto / cerrado » por ejemplo en el mensaje. ¿Y añadir una variable por defecto con los datos del periférico que desencadenó la escena?
Creo que es una solicitud aparte
Las puertas para mí eran un ejemplo ^^
En resumen, si se activa una escena, quiero identificar qué ha activado la escena.
Imagina,
Tengo una escena que verifica el estado de mis neumáticos, si la escena se activa, la variable « deviceTrigger » se instancia con el neumático que ha activado la escena y luego envío un mensaje con « {{ deviceTrigger debe ser cambiado}} »
Esa es la funcionalidad que propongo
Creo que tú quieres un mapeo 0 cerrado 1 abierto para los sensores de apertura?
Creo que propongo lo mismo que tú.
Pero sí, también propuse el mapeo inverso para pasar de 0/1 a « abierto / cerrado ».
Pues no lo había entendido ^^
Buenas noches,
He votado por integrar esta funcionalidad
Voy a dar un ejemplo
Creo una escena con todos mis sensores de temperatura como disparadores si se supera un cierto umbral.
Si se supera este umbral, se envía un mensaje con la información del disparador de la escena y la temperatura asociada a este disparador.
Puedo recuperar la información de la temperatura con « Obtener el último estado » pero no puedo obtener la información de quién ha disparado la escena
Espero que esta funcionalidad llegue pronto a Gladys
@prohand ¿te lanzas?
Llevas dos años esperándolo jajaja
Perdón, no he sincronizado el estado aquí, pero ya está desarrollado:
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.
Perfecto
Gracias @pierre-gilles
¿Tienes noticias sobre este tema?
prohand
8 Septiembre, 2026 18:36
13
Intentaba ver si funcionaba y… No me había dado cuenta de que aún no se había fusionado
¡Hola a todos!
Este tema ahora está en desarrollo .
Se ha abierto una PR para exponer, en las acciones de una escena, el nombre del dispositivo (y de la funcionalidad) que ha desencadenado un cambio de estado:
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)_
No duden en seguir la PR, probar (opcional, especialmente para pequeñas solicitudes) y dar sus comentarios aquí si es necesario.