Faire une opération mathématique sur une “variable de scène”

Why not compare two values?
I don’t know if it’s relevant.
For example, compare the setpoint temperature value and the temperature value in the room.
Then if the two values are equal we stop the heating.
I don’t know if it’s feasible.

4 Likes

Maybe also rounding and modulo?

2 Likes

Yes indeed

I don’t know if you saw in the screenshot, I planned to add in this PR the ability to put variables in the value of the « Continue only if » block, isn’t that what you’re asking for?

Yes, we can add round to nearest, round up and round down — it could be useful to have all three. Good point about modulo, I’ll note it

1 Like

It’s not necessarily a request for me, but the « continue only if » is correct.

To expand on conditions, there are the conditional expression operators in mathjs ? : like the ternary in JS — this will allow making pseudo if…else within an action.

More broadly, regarding adding calculations into scenes, I think we should allow all operators and limit the mathjs functions (the ones we call with parentheses and parameters; that’s where security issues can appear)

The PR is here

The code allows using variables and performing calculations in scenes for the « continue only if » and « control a device » blocks (see screenshots a bit above)

If you want to run tests, an image is available here bertrandda/gladys:scene-var-eval

5 Likes

Thank you for the work @bertrandda :clap: It’s really great!

I’ve left you some feedback on the PR : https://github.com/GladysAssistant/Gladys/pull/1742#pullrequestreview-1395209378

It’s fixed
The image bertrandda/gladys:scene-var-eval is up to date

1 Like

@bertrandda I don’t know if you had seen my feedback? :slight_smile:

Yes, I saw it, but I haven’t had time to sort all that out yet; I’ll try to do it tonight.

2 Likes

All good, your feedback has been addressed and the Docker image is up to date.

1 Like

@bertrandda Thanks for the feedback, it’s perfect like this :slight_smile: Great job, it’s very clear and it works great! I tested it live, I didn’t find any bugs :raised_hands:

It’s merged into master and it will be included in the next Gladys release.

4 Likes

Awesome!! :grin:

1 Like

I was fed up that every time my connection dropped, my call to mathjs would fail in my scenes!

Quick question:
Could the result be used to ‹ control a device ›?

Yes :slight_smile: Look at my screenshot above

1 Like

Good evening,

Great — can’t wait to test it, it should help me with heating management, even if it’s less relevant for the moment :sun::smiling_face_with_sunglasses:.
@bertrandda Is it possible to perform the operations on 2 variables?

Thanks for this dev

Yes, you can include multiple variables in the same calculation, provided that your variable is declared earlier in the scene (via a request or a « get value » block).

For my part, I have a calculation use case that I imagine is impossible at the moment.
I would like my pool pump to run for x time (in hours).

In this case: x = température eau / 2

Would it be technically possible in the future to use the result of these calculations in other types of blocks?
Simply put:

  • turn on the pump
  • wait X hours
  • turn off the pump

@bertrandda For info, @AlexTrovato found a regression in this feature — if a device control ever sent a value equal to 0 (very likely, because 0 is « OFF » for all devices), the scene would stop :grimacing:

Fortunately it didn’t make it to production and he made me a PR in time! :smiley: Thanks @AlexTrovato!

The fix: Fix zero as a number by atrovato · Pull Request #1773 · GladysAssistant/Gladys · GitHub

2 Likes