Quand in utilise une variable dans une action, il y a un espace qui vient se mettre à la fin de la variable :
Lorsque que ce message sert à envoyer une commande (dans un topic MQTT ou Z2M par exemple), le message est erroné à cause de cet espace →
z2m: Invalid message 'undefined', skipping...
Il faut donc obligatoirement supprimer cet espace entre la variable et la virgule et là tout fonctionne correctement.
Serait-il possible de pouvoir insérer une variable SANS espace juste après ? Merci
Salut tout le monde !
Ce sujet est désormais en cours de développement .
Une PR a été ouverte pour ne plus forcer d’espace après l’insertion d’une variable dans un texte de scène :
master ← claude/scene-variable-no-trailing-space
ouvert 02:14AM - 25 Aug 26 UTC
Implements feature request: https://community.gladysassistant.com/t/scenes-suppr… imer-lespace-insere-automatiquement-apres-lappel-dune-variable/10683
### Description
When a variable is inserted in a scene action text (`TextWithVariablesInjected`, used by the MQTT, Zigbee2mqtt, notification, SMS, HTTP request, set variable, delay, condition… actions), Tagify appends a non-breaking space right after the injected tag. That space ends up in the text saved in the scene, so a payload typed as `{"state":"ON","brightness":{{1.0.last_value}}}` is actually stored as `{"state":"ON","brightness":{{1.0.last_value}} }`, and Zigbee2mqtt rejects it with `z2m: Invalid message 'undefined', skipping...`. Users currently have to delete that space by hand after every variable insertion.
**What changed** (a single file, `front/src/components/scene/TextWithVariablesInjected.jsx`):
1. `mixMode.insertAfterTag` is set to a zero-width space (``) instead of Tagify's default non-breaking space (` `, see `DEFAULTS.mixMode` in Tagify 4.5.0).
2. `parseText` strips zero-width spaces, and normalizes any remaining non-breaking space into a regular space, before the text is handed back to the action.
**Why a zero-width space rather than removing the inserted node entirely (`insertAfterTag: ''`)?** In Tagify 4.5.0, a variable picked in the dropdown goes through `prefixedTextToTag`, which ends with `var elm = this.insertAfterTag(tagElm) || tagElm; this.placeCaretAfterNode(elm)`. `placeCaretAfterNode` does `range.setStartBefore(node.nextSibling || node)`, so it relies on a real text node existing after the tag to anchor the caret — with an empty `insertAfterTag` the caret can land *before* the tag whenever that sibling is missing (for instance when the tag is appended instead of replacing typed text). Keeping a zero-width text node preserves exactly today's DOM shape and caret behaviour (Tagify itself uses `` as a caret anchor in `fixFirefoxLastTagNoCaret`), it is simply invisible and stripped when the text is read back. The result: typing right after a variable produces no space, and typing a space produces exactly one regular space — so `Il fait {{temp}} degrés` is still perfectly typeable.
The non-breaking space normalization also repairs scenes saved with previous versions of Gladys (the injected NBSP becomes a regular space, which keeps a JSON payload valid) and the non-breaking spaces browsers insert into `contenteditable` elements, without gluing words together (deliberately never deleting a space the user may have wanted).
This PR was produced by an automated run.
## Forum
Forum: https://community.gladysassistant.com/t/scenes-supprimer-lespace-insere-automatiquement-apres-lappel-dune-variable/10683
### Checklist
- [ ] 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
Notes on the checklist: no server code is touched, so `server` tests are unaffected; `npm run eslint` in `front` reports 0 errors (only pre-existing warnings) and `prettier --check` passes on the changed file. Cypress was not run in this environment (the Cypress binary could not be downloaded), and the caret behaviour was reviewed against the Tagify 4.5.0 sources rather than verified in a real browser, so a quick manual check in the scene editor is welcome. The text normalization was verified with a standalone simulation of `parseText` covering: variable followed by nothing, variable followed by a typed space, and legacy texts containing the previously injected non-breaking space.
---
_Generated by [Claude Code](https://claude.ai/code/session_01Mf5kSG9xiBoF41gdY8N1gJ)_
N’hésitez pas à suivre la PR, à tester (optionnel, surtout pour les petites demandes) et à faire vos retours ici si besoin.