Good evening,
I don’t know how to « cast » the result which seems to be sent as a string, whereas a numeric value is expected in the following case:
Your help would be appreciated, thank you in advance,
Have a nice evening,
Jean
Hi @jean_bruder ![]()
Indeed, it’s not possible to do what you’re doing; you need to break down the calculation and the sending of the JSON.
Hello @pierre-gilles
I don’t know how to apply your answer to my scene: the value calculated to be sent via HTTP/POST comes from an operation on a value received via HTTP/GET to which a value is added/removed, and must be in numeric format. How can I use the calculated value of a device?
Thanks,
Jean
You can use a virtual device (MQTT integration) that serves as a « buffer » for the final value that you then send over HTTP.
Good evening @pierre-gilles ![]()
I’m taking advantage of the current good mood on the forum and the developers who keep innovating to dig up old requests I didn’t manage to complete … ![]()
Do you think it’s still impossible to apply a calculation to a sent value, because it could really simplify a lot of use cases: we could make a GET request, then a POST in interactive response ![]()
Looking forward to your reply,
Have a nice evening,
Jean
Hi @jean_bruder ![]()
Well, I’m going to answer you differently from what you expect: I don’t think we should add the calculation in the « HTTP Request » block, because everything you describe is already possible today ![]()
First, the « why not »: the body of an HTTP request is free text. It can be JSON, XML, form-urlencoded, anything. If we started evaluating calculations in it, Gladys would have to guess which part of the text is a formula and which part is content to be sent as-is, with the risk of breaking perfectly valid bodies in the process. That would mean inventing a special syntax, documenting it, maintaining it… whereas separating « I calculate » and « I send » remains clearer, and also allows you to reuse the calculated value elsewhere in the scene.
And above all: the GET then calculate then POST, you can already do it, without new functionality.
What was missing in your scene last year is simply that the response from an HTTP request is exposed as a scene variable. You do your GET, you click once on « Try » so that Gladys discovers the keys of the response, and you can then reinject them with {{ in all the following blocks, including in a second HTTP call. Concretely:
data.temperature{{ data.temperature }} + 2{{It works, and it even has a nice side effect: your calculated value becomes a real sensor, with history and graphs.
But I understand you, the buffer device is a bit heavy when the value is not meant to be historized.
So, good news: a new « Set a variable » action is coming ![]()
It will allow you to set a value once, either text or a calculation (Calculated tab, e.g. {{ data.temperature }} + 2), give it a name, and reuse it in all subsequent actions in the scene. No need to create a permanent MQTT device, no need for the « Retrieve the last state » block. Your scene will become:
{{ data.temperature }} + 2{{ to inject your variable in the bodyThree blocks, each with a clear role, and the calculation remains in the block intended for it. It’s exactly your use case ![]()
@pierre-gilles Thank you, thank you, thank you, thank you ![]()
Good evening @pierre-gilles,
No rush to reply ![]()
I have a question about the calculation and what it returns: is it indeed a numeric integer value that is the result of this calculation:
Because, in the log, I have this error:
Gladys | 2026-08-14T18:55:03+0200 scene.executeActions.js:42 (executeAction) Error: Parse error on line 1:
Gladys | …{{1.0.else.0.0.value}}}
Gladys | -----------------------^
Gladys | Expecting ‹ CLOSE ›, ‹ OPEN_SEXPR ›, ‹ ID ›, ‹ STRING ›, ‹ NUMBER ›, ‹ BOOLEAN ›, ‹ UNDEFINED ›, ‹ NULL ›, ‹ DATA ›, got ‹ CLOSE_UNESCAPED ›
Gladys | at Parser.parseError (/src/server/node_modules/handlebars/lib/handlebars/compiler/parser.js:199:11)
Gladys | at Parser.parse (/src/server/node_modules/handlebars/lib/handlebars/compiler/parser.js:251:22)
Gladys | at parseWithoutProcessing (/src/server/node_modules/handlebars/lib/handlebars/compiler/base.js:28:20)
Gladys | at HandlebarsEnvironment.parse (/src/server/node_modules/handlebars/lib/handlebars/compiler/base.js:34:13)
Gladys | at compileInput (/src/server/node_modules/handlebars/lib/handlebars/compiler/compiler.js:532:19)
Gladys | at ret (/src/server/node_modules/handlebars/lib/handlebars/compiler/compiler.js:546:18)
Gladys | at Object.http.request (/src/server/lib/scene/scene.actions.js:572:11)
Gladys | at executeAction (/src/server/lib/scene/scene.executeActions.js:34:37)
Gladys | at /src/server/lib/scene/scene.executeActions.js:75:15
Gladys | at tryCatcher (/src/server/node_modules/bluebird/js/release/util.js:16:23)
Gladys | at MappingPromiseArray._promiseFulfilled (/src/server/node_modules/bluebird/js/release/map.js:68:38)
Gladys | at MappingPromiseArray.PromiseArray._iterate (/src/server/node_modules/bluebird/js/release/promise_array.js:115:31)
Gladys | at MappingPromiseArray.init (/src/server/node_modules/bluebird/js/release/promise_array.js:79:10)
Gladys | at MappingPromiseArray._asyncInit (/src/server/node_modules/bluebird/js/release/map.js:37:10)
Gladys | at _drainQueueStep (/src/server/node_modules/bluebird/js/release/async.js:97:12)
Gladys | at _drainQueue (/src/server/node_modules/bluebird/js/release/async.js:86:9)
Gladys | at Async._drainQueues (/src/server/node_modules/bluebird/js/release/async.js:102:5)
Gladys | at Immediate.Async.drainQueues (/src/server/node_modules/bluebird/js/release/async.js:15:14)
Gladys | at processImmediate (node:internal/timers:534:21)
Additionally, during my HTTP call, I must have missed one of your instructions, as the format does not seem to be correct: it must be numeric.
Thanks for your feedback on this,
Have a nice evening,
Jean
Hi @jean_bruder ![]()
Good news: your calculation has nothing to do with the error ![]()
1. The error in the log comes from the body of your HTTP request, not the calculation.
Look closely at the end of the line: {{1.0.else.0.0.value}}} — there are three } in a row. The two curly braces close your variable, and the last one closes your JSON. Handlebars interprets these three curly braces as the closing of a « triple curly brace » {{{ }}}, and complains (got 'CLOSE_UNESCAPED').
Just don’t put them together. Instead of:
{"puissance": {{1.0.else.0.0.value}}}
write:
{
"puissance": {{1.0.else.0.0.value}}
}
(a simple space before the final curly brace is also enough: {"puissance": {{1.0.else.0.0.value}} }). Be careful, putting the space inside the variable doesn’t change anything: {{ 1.0.else.0.0.value }}} still crashes, it’s only right after the }} that you need space.
2. For the numeric format: definitely no quotes around the variable.
Gladys parses the body as JSON before sending it, so:
"puissance": "{{ma_variable}}" → sends "22.5", a string "puissance": {{ma_variable}} → sends 22.5, a real number 3. And yes, the calculation does return a number, but not necessarily an integer: if your original value is 20.5, {{ma_variable}} + 2 gives you 22.5. If your API expects an integer, you can round directly in the « Calculated » tab:
round({{ma_variable}} + 2) → 23round({{ma_variable}} + 2, 2) → two decimal placesGood evening @pierre-gilles,
Topic now closed, and multimedia button now fully functional for radio and music, thank you for your patience and your listening ![]()