# Trigger Scene

**URL:** <https://community.gladysassistant.com/t/scene-declencheur/8448>\
**Category:** Configuration\
**Tags:** scene\
**Created:** [November 1, 2023, 8:30pm UTC](https://community.gladysassistant.com/t/scene-declencheur/8448 "2023-11-01T20:30:38Z")\
**Posts on this page:** 1\
**Showing post:** 40

<div class="post-metadata">

**Author:** ![cce66](https://gladys-assistant-community.b-cdn.net/letter_avatar_proxy/v4/letter/c/8797f3/32.png) [@cce66](https://community.gladysassistant.com/u/cce66)\
**Post date:** [November 4, 2023, 10:38pm UTC](https://community.gladysassistant.com/t/scene-declencheur/8448/40 "2023-11-04T22:38:17Z")

</div>

> [@guim31](#):
>
> So in the end we almost completely agree.

Totally agree with you (aside from the click, exactly the same thing)

As for the rest, I made a request to meet my need and I was told it’s not possible or you have to do it differently; because that’s frustrating I made other proposals around that might work as a workaround until @_Will_71 suggested a solution that works (thanks again 👍). So yes, my thinking did evolve depending on the answers given and what I understood along the way with the answers (who said there’s a Macron supporter in the room? 🤣 «&nbsp;Only the Sith are so absolute.&nbsp;» 🤪)

Besides, that’s the purpose of a forum… and sometimes you have to persevere; otherwise I wouldn’t have managed to connect Gladys to my IPX800V5 via Node-RED and control my roller shutters (VR) based on the sun’s position. I found how to do it and shared my experience through mini-tutorials 🙂 whereas initially I had made requests to @pierre-gilles (or on the forum in the feature requests, I don’t quite remember) and the answer at the time was that it wasn’t possible. During discussions (because I hadn’t understood that the MQTT syntax isn’t standard) with @pierre-gilles among others, I understood how Gladys worked and thus how to do it via Node-RED. Same for the sun position: I had requested that; I was told it wasn’t possible for now, I worked around it with Node-RED and now I can control the roller shutters in Gladys taking into account the sun’s position!  
My approach is «&nbsp;I want to do something; if I can do it through the door then fine, but let’s try to see if I can do it through the window&nbsp;» and if I succeed I share it with others!

> [@Mini Tuto - Interaction Gladys - IPX800V5 via node-red](https://community.gladysassistant.com/t/mini-tuto-interaction-gladys-ipx800v5-via-node-red/6917):
>
> Le but de ce tuto est de montrer comment piloter des relais de la plate-forme domotique IPX800V5 de GCE avec Gladys Allez dans l’onglet « Système » [image] Cliquez sur « MQTT » [image] Paramétrez comme suit, avec pour « Serveur: " l’ip du broker mosquito (IP du raspberry ou du Nuc sur lequel est installé Gladys, en « Client ID » le nom que vous voudrez (j’ai mis ici IPX800V5 c’est important pour les paramétrage des Topic dans Node-red) [image] Ensuite on va dans l’onglet « Liens » [image…

> [@Mini-tuto Sun-Position Nore-red Mqtt pour piloter les volets en fonction de la position du soleil et des mois](https://community.gladysassistant.com/t/mini-tuto-sun-position-nore-red-mqtt-pour-piloter-les-volets-en-fonction-de-la-position-du-soleil-et-des-mois/8028):
>
> Bonjour, Voici un flow node-red pour injecter la position du soleil dans Gladys via Node-red (azimuth et altitude) [{ "id": "dbd46647b51191ed", "type": "tab", "label": "Sun-Position", "disabled": false, "info": "", "env": [] }, { "id": "a0d0e562.7ad1d8", "type": "debug", "z": "dbd46647b51191ed", "name": "debug 1", "active": false, "tosidebar": true, "console": false, "to…

> [@guim31](#):
>
> if adding a simple text `AND`

I don’t understand your remark there: internally it’s not the same logic. On one side we have  
OR in the scene which detects if **ONE** detector is **OPEN**

 ![image](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/d/d7974e7a2672930f428111f3bdae55ae1847420e.png)

and on the other an AND in my 2nd scene which detects if **ALL** my sensors are **CLOSED** ; that changes the internal processing logic — it’s not just adding text

 ![image](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/3/3734eeb0ad4e23f2018215ad6ca895828b3e540a.png)

To change how the blocks are interpreted you’d need the choice with a toggle to switch from an «&nbsp;OR&nbsp;» logic to an «&nbsp;AND&nbsp;» logic

 ![image](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/3/3b15043ce10ef5b117ececb63108b49432b438ad.png)

in the 1st case OR in algorithm  
FOR EACH BLOCK  
IF CONDITION MET THEN EXIT-SCENE  
UNTIL NUMBER-OF-BLOCKS

in the 2nd AND in algorithm  
TESTED-BLOCKS=0  
FOR EACH BLOCK  
IF CONDITION MET INCREMENT TESTED-BLOCKS  
UNTIL NUMBER-OF-BLOCKS  
IF TESTED-BLOCKS \<\> NUMBER-OF-BLOCKS THEN EXIT-SCENE

To test I asked ChatGPT  
«&nbsp;write me with comments with in the second loop the possibility between a serial or parallel processing according to a toggle called SceneSerieParallele in the UI the following program&nbsp;» and I put the code from the GitHub  
[Gladys/server/lib/scene at master · GladysAssistant/Gladys · GitHub](https://github.com/GladysAssistant/Gladys/tree/master/server/lib/scene) (at least by searching the GitHub code it seems to me that’s where it happens)

It returned this (thanks ChatGPT 🙂 ) I’m stunned! After, not sure that it would be usable as-is nor feasible in Gladys (true that there’s related database structure) but it allows me to discover and understand the code (this language is not my cup of tea 🤢) and, honestly, seeing what ChatGPT manages to do for me who grew up watching black-and-white TV and had to get off my butt to choose between channel 1 and 2 is striking even if it was part of my dreams («&nbsp;Forbidden Planet&nbsp;»!)

> const Promise = require(‹&nbsp;bluebird&nbsp;›);  
> const { actionsFunc } = require(‹&nbsp;./scene.actions&nbsp;›);  
> const { EVENTS, WEBSOCKET\_MESSAGE\_TYPES } = require(‹&nbsp;../../utils/constants&nbsp;›);  
> const { AbortScene } = require(‹&nbsp;../../utils/coreErrors&nbsp;›);  
> const logger = require(‹&nbsp;../../utils/logger&nbsp;›);
> 
> /\*\*
> 
> - @description Execute one action.
> - @param {object} self - Reference to the SceneManager.
> - @param {object} action - An Action from the db.
> - @param {object} scope - The scope passed to all actions.
> - @param {number} [columnIndex] - The X index of the action in the array of actions.
> - @param {number} [rowIndex] - The Y index of the action in the array of actions.
> - @returns {Promise} Resolve if the action was executed with success.
> - @example
> - executeAction(this, action, {});  
> \*/  
> async function executeAction(self, action, scope, columnIndex, rowIndex) {  
> // Check if the action type is supported  
> if (!actionsFunc[action.type]) {  
> throw new Error(`Action type "${action.type}" does not exist.`);  
> }
> 
> // Send a message to inform the UI that the action is being executed  
> if (columnIndex !== undefined && rowIndex !== undefined) {  
> self.event.emit(EVENTS.WEBSOCKET.SEND\_ALL, {  
> type: WEBSOCKET\_MESSAGE\_TYPES.SCENE.EXECUTING\_ACTION,  
> payload: { columnIndex, rowIndex },  
> });  
> }  
> try {  
> // Execute the action  
> await actionsFunc[action.type](self, action, scope, columnIndex, rowIndex);  
> } catch (e) {  
> if (e instanceof AbortScene) {  
> throw e;  
> } else {  
> logger.warn(e);  
> }  
> }
> 
> // Send a message to inform the UI that the action has finished being executed  
> if (columnIndex !== undefined && rowIndex !== undefined) {  
> self.event.emit(EVENTS.WEBSOCKET.SEND\_ALL, {  
> type: WEBSOCKET\_MESSAGE\_TYPES.SCENE.FINISHED\_EXECUTING\_ACTION,  
> payload: { columnIndex, rowIndex },  
> });  
> }
> 
> return null;  
> }
> 
> /\*\*
> 
> - @description Execute an array of array of action.
> - @param {object} self - Reference to the SceneManager.
> - @param {object} actions - An array of array of actions from the db.
> - @param {object} scope - The scope passed to all actions.
> - @param {boolean} isParallel - Whether to execute actions in parallel or series based on the UI toggle.
> - @returns {Promise} Resolve if the action was executed with success.
> - @example
> - executeActions(this, actions, {}, true);  
> \*/  
> async function executeActions(self, actions, scope, isParallel = true) {  
> // First level of the array should be executed in series  
> await Promise.mapSeries(actions, async (parallelActions, columnIndex) =\> {  
> // Then, the second level is executed based on the value of isParallel  
> if (isParallel) {  
> // Execute actions in parallel  
> await Promise.map(parallelActions, async (action, rowIndex) =\> {  
> await executeAction(self, action, scope, columnIndex, rowIndex);  
> });  
> } else {  
> // Execute actions in series  
> for (const [rowIndex, action] of parallelActions.entries()) {  
> await executeAction(self, action, scope, columnIndex, rowIndex);  
> }  
> }  
> });  
> return null;  
> }
> 
> module.exports = {  
> executeAction,  
> executeActions,  
> };

A bit long but if some people learn something from reading this post that’s good, it’s always that much gained! 🙂

---

_[View the full topic](https://community.gladysassistant.com/t/scene-declencheur/8448)._
