# Mathematische Operation mit einer „Szene-Variablen“ durchführen

**URL:** <https://community.gladysassistant.com/t/faire-une-operation-mathematique-sur-une-variable-de-scene/7030>\
**Category:** Demandes livrées\
**Tags:** feature-core, scene, scene-action\
**Created:** [7. März 2022 um 20:44 UTC](https://community.gladysassistant.com/t/faire-une-operation-mathematique-sur-une-variable-de-scene/7030 "2022-03-07T20:44:49Z")\
**Posts on this page:** 20\
**Page:** 4

<div class="post-metadata">

**Author:** ![Tlse-vins](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/tlse-vins/32/6054_2.png) [@Tlse-vins](https://community.gladysassistant.com/u/Tlse-vins)\
**Post date:** [21. Dezember 2022 um 09:08 UTC](https://community.gladysassistant.com/t/faire-une-operation-mathematique-sur-une-variable-de-scene/7030/61 "2022-12-21T09:08:58Z")

</div>

Warum nicht den Vergleich von 2 Werten?  
Ich weiß nicht, ob das relevant ist.  
Zum Beispiel den Vergleich des Sollwerts der Temperatur mit dem Wert der Raumtemperatur.  
Dann, wenn die beiden Werte gleich sind, schaltet man die Heizung aus.  
Ich weiß nicht, ob das umsetzbar ist.

---

<div class="post-metadata">

**Author:** ![Einstein8854](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/einstein8854/32/9474_2.png) [@Einstein8854](https://community.gladysassistant.com/u/Einstein8854)\
**Post date:** [21. Dezember 2022 um 09:29 UTC](https://community.gladysassistant.com/t/faire-une-operation-mathematique-sur-une-variable-de-scene/7030/62 "2022-12-21T09:29:53Z")

</div>

vielleicht auch die Rundung und der Modulo?

---

<div class="post-metadata">

**Author:** ![bertrandda](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/bertrandda/32/5929_2.png) [@bertrandda](https://community.gladysassistant.com/u/bertrandda)\
**Post date:** [4. Januar 2023 um 19:03 UTC](https://community.gladysassistant.com/t/faire-une-operation-mathematique-sur-une-variable-de-scene/7030/63 "2023-01-04T19:03:55Z")

</div>

> [@lmilcent](#):
>
> Die Klammern nicht vergessen, natürlich!

Ja, in der Tat

> [@Tlse-vins](#):
>
> Warum nicht den Vergleich von 2 Werten.  
> Ich weiß nicht, ob das relevant ist.  
> Zum Beispiel den Vergleich des Sollwerts der Temperatur und des Temperaturwerts im Raum.

Ich weiß nicht, ob du im Screenshot gesehen hast, ich habe in dieser PR die Möglichkeit vorgesehen, Variablen in den Wert des Blocks „Nur fortsetzen, wenn“ einzufügen, ist das nicht das, was du verlangst?

> [@Einstein8854](#):
>
> vielleicht auch die Rundung und den Modulo?

Ja, man kann auf die nächste Zahl runden, auf die nächste ganze Zahl aufrunden und auf die nächste ganze Zahl abrunden, es kann interessant sein, alle drei zu haben. Guter Hinweis zum Modulo, ich notiere.

---

<div class="post-metadata">

**Author:** ![Tlse-vins](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/tlse-vins/32/6054_2.png) [@Tlse-vins](https://community.gladysassistant.com/u/Tlse-vins)\
**Post date:** [4. Januar 2023 um 22:43 UTC](https://community.gladysassistant.com/t/faire-une-operation-mathematique-sur-une-variable-de-scene/7030/64 "2023-01-04T22:43:32Z")

</div>

> [@bertrandda](#):
>
> "Nur fortfahren, wenn ", ist das nicht das, was du verlangst?

Das ist nicht unbedingt eine Anfrage für mich, aber das «&nbsp;Nur fortfahren, wenn&nbsp;» ist gut.

---

<div class="post-metadata">

**Author:** ![bertrandda](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/bertrandda/32/5929_2.png) [@bertrandda](https://community.gladysassistant.com/u/bertrandda)\
**Post date:** [8. Januar 2023 um 21:08 UTC](https://community.gladysassistant.com/t/faire-une-operation-mathematique-sur-une-variable-de-scene/7030/65 "2023-01-08T21:08:06Z")

</div>

Um die Bedingungen zu ergänzen, gibt es die bedingten Operatoren in mathjs `?` `:` wie die ternären Operatoren in JS, damit können pseudomäßige if…else-Anweisungen in einer Aktion erstellt werden.

Allgemeiner gesagt, bei der Hinzufügung von Berechnungen in Szenen denke ich, dass wir alle Operatoren zulassen und die mathjs-Funktionen (die mit Klammern und Parametern aufgerufen werden, dort können Sicherheitsprobleme auftreten) einschränken sollten.

---

<div class="post-metadata">

**Author:** ![bertrandda](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/bertrandda/32/5929_2.png) [@bertrandda](https://community.gladysassistant.com/u/bertrandda)\
**Post date:** [19. April 2023 um 20:17 UTC](https://community.gladysassistant.com/t/faire-une-operation-mathematique-sur-une-variable-de-scene/7030/66 "2023-04-19T20:17:37Z")

</div>

Die PR ist da

> <https://github.com/GladysAssistant/Gladys/pull/1742>
>
> \### Pull Request check-list
> 
> To ensure your Pull Request can be accepted as fa…st as possible, make sure to review and check all of these items:
> 
> \- \[x\] If your changes affects code, did your write the tests?
> \- \[x\] Are tests passing? (\`npm test\` on both front/server)
> \- \[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 features/services, did you run integration comparator? (\`npm run compare-translations\` on front)
> \- \[x\] 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\](https://community.gladysassistant.com/) for testing before merging.
> \- \[\] 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).
> 
> NOTE: these things are not required to open a PR and can be done afterwards / while the PR is open.
> 
> \### Description of change
> 
> Please provide a description of the change here. It's always best with screenshots, so don't hesitate to add some!
> 
> I added calculation in scene conditions and control device box
> Use string evaluation allow also to use device value in calculation and control device
> 
> !\[image\](https://user-images.githubusercontent.com/18148265/232593703-1a4ee942-d495-42dd-8efa-33e873a7c374.png)

Der Code ermöglicht die Verwendung von Variablen und Berechnungen in Szenen auf Ebene der Blöcke „Nur fortsetzen, wenn“ und „Gerät steuern“ (siehe Screenshots etwas weiter oben)

Wenn ihr testen wollt, ist ein Image hier verfügbar `bertrandda/gladys:scene-var-eval`

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [21. April 2023 um 07:33 UTC](https://community.gladysassistant.com/t/faire-une-operation-mathematique-sur-une-variable-de-scene/7030/67 "2023-04-21T07:33:43Z")

</div>

Danke für die Arbeit @bertrandda 👏 Das ist wirklich toll!

Ich habe dir ein paar Rückmeldungen zur PR gegeben: [Add calcul and use device value in scene by bertrandda · Pull Request #1742 · GladysAssistant/Gladys · GitHub](https://github.com/GladysAssistant/Gladys/pull/1742#pullrequestreview-1395209378)

---

<div class="post-metadata">

**Author:** ![bertrandda](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/bertrandda/32/5929_2.png) [@bertrandda](https://community.gladysassistant.com/u/bertrandda)\
**Post date:** [23. April 2023 um 21:09 UTC](https://community.gladysassistant.com/t/faire-une-operation-mathematique-sur-une-variable-de-scene/7030/68 "2023-04-23T21:09:57Z")

</div>

Es ist erledigt  
Das Bild `bertrandda/gladys:scene-var-eval` ist aktuell

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [4. Mai 2023 um 08:52 UTC](https://community.gladysassistant.com/t/faire-une-operation-mathematique-sur-une-variable-de-scene/7030/69 "2023-05-04T08:52:11Z")

</div>

@bertrandda Ich weiß nicht, ob du mein Feedback gesehen hast? 🙂

> <https://github.com/GladysAssistant/Gladys/pull/1742#pullrequestreview-1405208871>
>
> \### Pull Request check-list
> 
> To ensure your Pull Request can be accepted as fa…st as possible, make sure to review and check all of these items:
> 
> \- \[x\] If your changes affects code, did your write the tests?
> \- \[x\] Are tests passing? (\`npm test\` on both front/server)
> \- \[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 features/services, did you run integration comparator? (\`npm run compare-translations\` on front)
> \- \[x\] 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\](https://community.gladysassistant.com/) for testing before merging.
> \- \[\] 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).
> 
> NOTE: these things are not required to open a PR and can be done afterwards / while the PR is open.
> 
> \### Description of change
> 
> Please provide a description of the change here. It's always best with screenshots, so don't hesitate to add some!
> 
> I added calculation in scene conditions and control device box
> Use string evaluation allow also to use device value in calculation and control device
> 
> !\[image\](https://user-images.githubusercontent.com/18148265/232593703-1a4ee942-d495-42dd-8efa-33e873a7c374.png)

---

<div class="post-metadata">

**Author:** ![bertrandda](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/bertrandda/32/5929_2.png) [@bertrandda](https://community.gladysassistant.com/u/bertrandda)\
**Post date:** [4. Mai 2023 um 10:55 UTC](https://community.gladysassistant.com/t/faire-une-operation-mathematique-sur-une-variable-de-scene/7030/70 "2023-05-04T10:55:48Z")

</div>

Ja, ich habe es gesehen, aber ich hatte noch keine Zeit, das alles zu regeln. Ich werde es heute Abend versuchen.

---

<div class="post-metadata">

**Author:** ![bertrandda](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/bertrandda/32/5929_2.png) [@bertrandda](https://community.gladysassistant.com/u/bertrandda)\
**Post date:** [4. Mai 2023 um 19:29 UTC](https://community.gladysassistant.com/t/faire-une-operation-mathematique-sur-une-variable-de-scene/7030/71 "2023-05-04T19:29:30Z")

</div>

Alles klar, deine Rückmeldungen sind eingestellt und das Docker-Image ist aktuell.

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [5. Mai 2023 um 04:25 UTC](https://community.gladysassistant.com/t/faire-une-operation-mathematique-sur-une-variable-de-scene/7030/72 "2023-05-05T04:25:31Z")

</div>

@bertrandda Danke für das Feedback, so ist es perfekt 🙂 Tolle Arbeit, es ist sehr klar und funktioniert super! Ich habe es in der Praxis getestet und keine Fehler gefunden 🙌

Es ist in master gemerged und wird in der nächsten Version von Gladys veröffentlicht.

 ![Screenshot 2023-05-05 at 11.23.56](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/6/69bcbb6ad567798ff12205b77ac989ac06d8586a.png)

 ![Screenshot 2023-05-05 at 11.24.25](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/d/d4a6d60d2aa1dbe3a657913c4de5f7a997ccddd3.png)

---

<div class="post-metadata">

**Author:** ![guim31](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/guim31/32/4840_2.png) [@guim31](https://community.gladysassistant.com/u/guim31)\
**Post date:** [5. Mai 2023 um 06:17 UTC](https://community.gladysassistant.com/t/faire-une-operation-mathematique-sur-une-variable-de-scene/7030/73 "2023-05-05T06:17:33Z")

</div>

Super das !! 😁

---

<div class="post-metadata">

**Author:** ![spenceur](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/spenceur/32/1961_2.png) [@spenceur](https://community.gladysassistant.com/u/spenceur)\
**Post date:** [5. Mai 2023 um 07:35 UTC](https://community.gladysassistant.com/t/faire-une-operation-mathematique-sur-une-variable-de-scene/7030/74 "2023-05-05T07:35:49Z")

</div>

Schließlich hatte ich nur Ärger, weil mein Anruf bei mathjs in meinen Szenen jedes Mal fehlschlug, wenn mein Co sprang!

---

<div class="post-metadata">

**Author:** ![GBoulvin](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/gboulvin/32/10006_2.png) [@GBoulvin](https://community.gladysassistant.com/u/GBoulvin)\
**Post date:** [5. Mai 2023 um 07:54 UTC](https://community.gladysassistant.com/t/faire-une-operation-mathematique-sur-une-variable-de-scene/7030/75 "2023-05-05T07:54:59Z")

</div>

Kleine Frage:  
Kann das Ergebnis verwendet werden, um ein Gerät zu steuern?

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [5. Mai 2023 um 07:58 UTC](https://community.gladysassistant.com/t/faire-une-operation-mathematique-sur-une-variable-de-scene/7030/76 "2023-05-05T07:58:39Z")

</div>

> [@GBoulvin](#):
>
> Kann das Ergebnis verwendet werden, um ein Gerät zu steuern?

Ja 🙂 Siehe mein Screenshot oben

---

<div class="post-metadata">

**Author:** ![gaelbillon](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/gaelbillon/32/12185_2.png) [@gaelbillon](https://community.gladysassistant.com/u/gaelbillon)\
**Post date:** [5. Mai 2023 um 17:59 UTC](https://community.gladysassistant.com/t/faire-une-operation-mathematique-sur-une-variable-de-scene/7030/77 "2023-05-05T17:59:26Z")

</div>

Hallo,  
Toll, alles das! Kann es kaum erwarten, es zu testen. Es sollte mir bei der Heizungssteuerung helfen, auch wenn es im Moment weniger aktuell ist ☀😎.  
@bertrandda Ist es möglich, die Operationen auf 2 Variablen durchzuführen?

Danke für die Entwicklung

---

<div class="post-metadata">

**Author:** ![bertrandda](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/bertrandda/32/5929_2.png) [@bertrandda](https://community.gladysassistant.com/u/bertrandda)\
**Post date:** [7. Mai 2023 um 16:47 UTC](https://community.gladysassistant.com/t/faire-une-operation-mathematique-sur-une-variable-de-scene/7030/78 "2023-05-07T16:47:50Z")

</div>

Ja, du kannst mehrere Variablen in dieselbe Berechnung einbeziehen, solange deine Variable weiter oben in der Szene deklariert ist (über eine Anfrage oder einen Block zum Abrufen eines Werts).

---

<div class="post-metadata">

**Author:** ![guim31](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/guim31/32/4840_2.png) [@guim31](https://community.gladysassistant.com/u/guim31)\
**Post date:** [7. Mai 2023 um 17:23 UTC](https://community.gladysassistant.com/t/faire-une-operation-mathematique-sur-une-variable-de-scene/7030/79 "2023-05-07T17:23:54Z")

</div>

Ich habe ein Anwendungsfall-Szenario für Berechnungen, das ich im Moment für unmöglich halte.  
Ich möchte, dass die Pumpe meines Pools für x Stunden (in Stunden) läuft.

In diesem Fall: `x = Wassertemperatur / 2`

Ist es technisch in Zukunft möglich, das Ergebnis dieser Berechnungen in anderen Arten von Blöcken zu verwenden?  
Zum Beispiel ganz einfach:

- Pumpe einschalten
- X Stunden warten
- Pumpe ausschalten

?

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [8. Mai 2023 um 06:26 UTC](https://community.gladysassistant.com/t/faire-une-operation-mathematique-sur-une-variable-de-scene/7030/80 "2023-05-08T06:26:27Z")

</div>

@bertrandda Für Info, @AlexTrovato hat einen Rückschritt in dieser Funktion gefunden. Falls die Steuerung eines Geräts einen Wert von 0 sendete (sehr wahrscheinlich, da 0 für alle Geräte „AUS“ bedeutet), stoppte die Szene 😬

 ![Screenshot 2023-05-08 at 13.24.18](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/4/4316a043c4a14ba22421c610ad7e677a0c566526.png)

Glücklicherweise ist das nicht in die Produktion gegangen und er hat mir rechtzeitig einen PR gemacht! 😃 Danke @AlexTrovato!

Der Fix: [Fix zero as a number by atrovato · Pull Request #1773 · GladysAssistant/Gladys · GitHub](https://github.com/GladysAssistant/Gladys/pull/1773)

[Vorherige Seite](https://community.gladysassistant.com/t/faire-une-operation-mathematique-sur-une-variable-de-scene/7030.md?page=3)

[Nächste Seite](https://community.gladysassistant.com/t/faire-une-operation-mathematique-sur-une-variable-de-scene/7030.md?page=5)
