For my part, for my heating system I need the outdoor temperature. Since I don’t have an outdoor temperature sensor (for the moment), I use Node-RED to make a request to the OpenWeatherMap API (the same API as Gladys) to retrieve the temperature and send it to a fake MQTT device.
If we could do it directly in Gladys that would be cool!
It would also be nice to be able to fix the problem with variables in requests
@cicoub13 proposed a PR but I don’t know if he has finished his tests
The PR is ready. If someone can review ![]()
Thanks for the PR @cicoub13 !
I have a question, where did you find this solution? Was it recommended by the library to do it this way?
Because it still looks very much like a bug in the library we use, and forcing an order is kind of a hack, isn’t it?
By the way, does the order you set change the dropdown’s display order?
In my head ![]()
No, I admit I didn’t look for the source beyond the file’s code. It might be a bad handling of lists.
The problem is that we’re trying to replace tags in a text that are present in multiple forms:
Text
Hello, at night, the cats are gray and the dragonflies are grays.
Tags to replace
gray, grays
Result
Hello, at night, the cats are
grayand the dragonflies aregrays.
Replacing the tag « gray » also replaces the word « grays »
The solution I propose indeed seems like a hack.
Text
Hello, at night, the cats are gray and the dragonflies are grays.
Tags to replace
grays, gray (sorted from longest to shortest)
Result
Hello, at night, the cats are
grayand the dragonflies aregrays.
Replacing the tag « gray » only replaces the word « gray » because the replacement for the « grays » tag took place first.
No, the order is preserved. Only the search-and-replace operation is affected.
Are you sure?
I tested your PR, and I get this:
Before:
After:
The boxes are mixed afterwards, which makes it really difficult to use.
Aren’t these two different issues related to the ticket?
Here we only want to pass variables to the HTTP request block.
This feature has already been developed
(Already available on the Docker dev tag, and will be present in the next prod release)
What really prevents me from closing this request is the second part of the request about the « Control a device » block — I have no idea how to handle it in terms of design; it might even be a different block to develop.
Great! ![]()
See above:
Hi, I was wondering how you’d picture it when you imagine a possible different block to control a device with a variable.
I tried something by reusing the component that already existed for inserting variables. If the value is a number, we save the new value in value as usual; otherwise it is saved as a string. In my trial I added a database field evaluate_value. Since we also have a request to do calculations on variables I thought that would allow doing both.
When the scene runs, if we encounter evaluate_value fields as the value of « control a device » actions, we replace the variables with their values and run the calculation (I was thinking of using the simple-evaluate package).
On the validation side I added on the evaluate_value field a @hapi/joi validation with a regex allowing only numbers, operators and {{variables}} (a complete formula — if the user enters "{{variable…}} + " without a second value it won’t save).
What do you think? What was your vision for how it should work?
That’s not a bad idea!
Several points to manage:
- So we’ll need to remove the selector (slider, color picker, etc.) in the case where the value is « computed »; in the UI we might make two tabs like « Select | Compute »
- I think we can find a more robust, and above all more complete, library. If we handle both topics in one (doing calculations + variable injection), we need to think everything through in advance if we implement this « calculation engine », because once it’s implemented we’ll be locked into the technology we’ve chosen, especially if there are « custom » functions. For example, for me it’s essential to have a « Round » function in this field, because calculations will inevitably produce numbers like 87.33333 which can cause some devices to crash
While searching I found this lib that looks pretty good: https://www.npmjs.com/package/mathjs. We need to ask the community which mathematical functions are essential and have an exhaustive list. We must be sure that the library we choose will do the job in the long term 
- I agree that validation is super important!
Since in both cases we have an input field, I thought to do that « automatically »: if the input is not of integer type we hide the selection module.
Edit: I only had the numeric control in mind, not colors… I’ll think about it
I had seen mathjs but one thing made me doubt about this lib math.js | an extensive math library for JavaScript and Node.js. Knowing that we need the evaluate function to get the result of a calculation, we have a potential security issue. This is because most math libs that do this kind of thing use or rewrite eval eval() - JavaScript | MDN and therefore potentially injected JavaScript into Gladys. Then, knowing that « normally » it’s the user who chooses what they want to put there, maybe I’m worrying for nothing (I put « normally » in quotes because if the user places the response of an API there, could there be an unwanted input
?)
In fact their explanation is rather reassuring; they clearly state that they did not use eval to evaluate operations, and that they implemented their own evaluator. They warn about the risks!
Their example is actually very good — it is possible to disable functions:
In our case, in my opinion we should make a list of the functions we want to support, and then harden the unit tests to verify that it is indeed only those functions that are supported.
We could ask the community what is useful here, for example:
Oh, I just mentioned this library earlier in another post, without realizing you’d mentioned it here!
It looks pretty interesting in any case.
As I pointed out in the other post, when a variable is injected via POST, it seems that the braces are preserved in the API call (which breaks the MathJS API).
Hello,
I’m following up on the topic of the variable to control devices.
A use case that would be very handy: Controler un appareil avec une valeur variable - #5 par Hizo
It would be possible to group several scenes into a single, simpler one.
The topic is moving forward (PR + test image), I mentioned it here
This feature is available in Gladys Assistant 4.23 !



