NEWS
Script and Telegram
-
dear Iobrokers,
I'm trying to command from Telegram.
I'd made 4 scripts thaht allow me to :- Open blind
- Close Blind
- Light ON and OFF
- Have return of temperature in differents room
In the beginning of each script I send to Telegram a keybord to choose the action to made
sendTo('telegram.0', { text: 'Que voulez-vous faire ?', reply_markup: { keyboard: [ ['Allumer/Eteindre'], ['Ouvrir'], ['Fermer'], ['Température'] ], resize_keyboard: true, one_time_keyboard: true } });
And after, following the choice... I send what I wanted to do with another keyboard.
Everything works individually, but once I made the choice of 1 action, the script stay in this action and I can't go back to the first menu.
I tryed to exit script but nothing...
I can add a button on the keybord to exit or restart the script already made but I don't know how to do it.some screen capture here under :
the different scripts :
And how it's in one script (each time the same), the only things, I've put in javascript to be more easy for you, but this is in blockly.
var action, Allumer; // Décrivez cette fonction... async function Choix_action() { sendTo('telegram.0', { text: 'Que voulez-vous faire ?', reply_markup: { keyboard: [ ['Allumer/Eteindre'], ['Ouvrir'], ['Fermer'], ['Température'] ], resize_keyboard: true, one_time_keyboard: true } }); } // Décrivez cette fonction... async function Choix_allumer() { sendTo('telegram.0', { text: 'Que voulez-vous allumer ?', reply_markup: { keyboard: [ ['Salon','SAM','Cuisine','Table cuisine'], ['Meuble cuisine','Evier','Fauteuil','Mur télé'], ['Buanderie','Bureau','Hall','Escalier'], ['Devant','Terrasse','Ext Buanderie','HDN'], ['Salle de jeux','Chambre papa','Chambre Manon','Chambre Hugo'], ['Salle de bain','Miroir','Toilettes','Quitter'] ], resize_keyboard: true, one_time_keyboard: true } }); } // Décrivez cette fonction... async function quitter() { } await Choix_action(); on({id: [].concat(['telegram.0.communicate.request']), change: "any"}, async function (obj) { var value = obj.state.val; var oldValue = obj.oldState.val; action = (obj.state ? obj.state.val : "").slice(8, (obj.state ? obj.state.val : "").lastIndexOf('') + 1); if (action == 'Allumer/Eteindre') { await Choix_allumer(); on({id: [].concat(['telegram.0.communicate.request']), change: "any"}, async function (obj) { var value = obj.state.val; var oldValue = obj.oldState.val; Allumer = (obj.state ? obj.state.val : "").slice(8, (obj.state ? obj.state.val : "").lastIndexOf('') + 1); if (Allumer == 'Salon') { setStateDelayed('s7.0.DBs.DB1.INT_Salon', true, false, parseInt(((0) || "").toString(), 10), false); } else if (Allumer == 'SAM') { setStateDelayed('s7.0.DBs.DB1.INT_SAM', true, false, parseInt(((0) || "").toString(), 10), false); } else if (Allumer == 'Cuisine') { setStateDelayed('s7.0.DBs.DB1.INT_cuisine_principa', true, false, parseInt(((0) || "").toString(), 10), false); } else if (Allumer == 'Table cuisine') { setStateDelayed('s7.0.DBs.DB1.INT_Cuisine_Table', true, false, parseInt(((0) || "").toString(), 10), false); } else if (Allumer == 'Meuble cuisine') { setStateDelayed('s7.0.DBs.DB1.INT_cuisine_meuble', true, false, parseInt(((0) || "").toString(), 10), false); } else if (Allumer == 'Evier') { setStateDelayed('s7.0.DBs.DB1.INT_Cuisine_Evier', true, false, parseInt(((0) || "").toString(), 10), false); } else if (Allumer == 'Fauteuil') { setStateDelayed('s7.0.DBs.DB1.INT_Applique', true, false, parseInt(((0) || "").toString(), 10), false); } else if (Allumer == 'Mur télé') { setStateDelayed('s7.0.DBs.DB1.INT_Applique_direct', true, false, parseInt(((0) || "").toString(), 10), false); } else if (Allumer == 'Buanderie') { setStateDelayed('s7.0.DBs.DB1.INT_Buanderie', true, false, parseInt(((0) || "").toString(), 10), false); } else if (Allumer == 'Bureau') { setStateDelayed('s7.0.DBs.DB1.INT_Bureau', true, false, parseInt(((0) || "").toString(), 10), false); } else if (Allumer == 'Hall') { setStateDelayed('s7.0.DBs.DB1.INT_Hall_bas', true, false, parseInt(((0) || "").toString(), 10), false); } else if (Allumer == 'Escalier') { setStateDelayed('s7.0.DBs.DB1.INT_Escalier', true, false, parseInt(((0) || "").toString(), 10), false); } else if (Allumer == 'Devant') { setStateDelayed('s7.0.DBs.DB1.INT_Ext_dvt', true, false, parseInt(((0) || "").toString(), 10), false); } else if (Allumer == 'Terrasse') { setStateDelayed('s7.0.DBs.DB1.Ext_terrasse', true, false, parseInt(((0) || "").toString(), 10), false); } else if (Allumer == 'Ext Buanderie') { setStateDelayed('s7.0.DBs.DB1.INT_Ext_buanderie', true, false, parseInt(((0) || "").toString(), 10), false); } else if (Allumer == 'HDN') { setStateDelayed('s7.0.DBs.DB1.INT_HDN_Haut', true, false, parseInt(((0) || "").toString(), 10), false); } else if (Allumer == 'Salle de jeux') { setStateDelayed('s7.0.DBs.DB1.INT_SDJ', true, false, parseInt(((0) || "").toString(), 10), false); } else if (Allumer == 'Chambre papa') { setStateDelayed('s7.0.DBs.DB1.INT_Papa', true, false, parseInt(((0) || "").toString(), 10), false); } else if (Allumer == 'Chambre Manon') { setStateDelayed('s7.0.DBs.DB1.INT_Manon', true, false, parseInt(((0) || "").toString(), 10), false); } else if (Allumer == 'Chambre Hugo') { setStateDelayed('s7.0.DBs.DB1.INT_Hugo', true, false, parseInt(((0) || "").toString(), 10), false); } else if (Allumer == 'Salle de bain') { setStateDelayed('s7.1.DBs.DB1.INT_SDB', true, false, parseInt(((0) || "").toString(), 10), false); } else if (Allumer == 'Miroir') { setStateDelayed('s7.1.DBs.DB1.INT_Meuble_SDB', true, false, parseInt(((0) || "").toString(), 10), false); } else if (Allumer == 'Toilettes') { setStateDelayed('s7.0.DBs.DB1.INT_WC', true, false, parseInt(((0) || "").toString(), 10), false); } else if (Allumer == 'Quitter') { } else { } }); console.log(Allumer); } });
in pictures :
Thanks for your help.
-
@tiger I am afraid that I cannot fully follow what you intend to do, BUT
What you are effectively doing is adding triggers which you are not removing.
The construct
on (...) { if (condition) { on (...) } }
generates a trigger which remains in memory as written once the "condition" has been true once. As such it will parse the response to the telegram message until you terminate the script.
The idea to solve this is
- Generate a variable "MenuState"
- Assign a value to said variable which lets you identify which menu you are in
- use the code
on({id: [].concat(['telegram.0.communicate.request']), change: "any"}, async function (obj) { var value = obj.state.val; var oldValue = obj.oldState.val; action = (obj.state ? obj.state.val : "").slice(8, (obj.state ? obj.state.val : "").lastIndexOf('') + 1);
to identify the action sent from telegram and combine that with the MenuState for the respective action. If you have a tree like menu it makes sense to keep the menu names in a structured form so you can "rewind".
An example would be
'main' for the main menu
'main.Allumer'
'main.Allumer.Salon'
...I hope this makes sense.
A.
p.s.
If you can ensure that the various telegram menu items are unique, you can even work without any variable and just put one parser into the trigger which reacts to the telegram message.
In your example, this is the case. -
@asgothian said in Script and Telegram:
generates a trigger which remains in memory as written once the "condition" has been true once. As such it will parse the response to the telegram message until you terminate the script.
Dear,
thanks for your answer.I understood that I din't end the script once the condition is true, for that no problem.
But I ddn't understand your proposal.In the code you wrote it's the same as mine, and I didn't understand what I've to do, just that you mentionned to write on the variable "MAIN" the text send by Telegram.
There is no command to exit a script once on of the conditions are true?
Presently, it works but without the first Menu, If y send the text corresponding to an action, Iobroker send me back all the differents objet that I would like to light-on,-off or open/close.
But I thing that in some case, Iobroker send always the command to my blind, as If I ask to Alexa to open the blind that was closed by Telegram... is start to open and after some seconds motor change is rotation and the blind stay closed.
It's difficult to explain exactly my problem so I understand that it is difficult to help me...
Tiger
-
@tiger Attached is a simple blockly example.
I hope this explains how I would do this.
A.
p.s. I don't speak French, so any translation errors are in there for your amusement. I also still am unsure about the exact setup, so some combinations of main menu selection and sub menu selection may not make sense. Those cases wouldn't need to be explicitly listed either.