How to pass information from a sensor to my telegram bot

Import this example flow if it helps to understand what I tried to say. :slightly_smiling_face:

[{"id":"6c6d0d34.e473e4","type":"inject","z":"9bcda218.23d61","name":"Mock /Temperature","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":60,"wires":[["4d3d08a7.a3a778"]]},{"id":"4d3d08a7.a3a778","type":"change","z":"9bcda218.23d61","name":"Mock s7 node","rules":[{"t":"set","p":"payload","pt":"msg","to":"24","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":200,"y":120,"wires":[["f5017d3a.61af"]]},{"id":"f5017d3a.61af","type":"change","z":"9bcda218.23d61","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.content","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":250,"y":180,"wires":[["8d0ba250.c420a"]]},{"id":"8d0ba250.c420a","type":"debug","z":"9bcda218.23d61","name":"Mock Telegram Sender","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":380,"y":240,"wires":[]}]

I quoted @osancleca :wink:

Sorry! Shouldn't be posting after a few Friday drinks. :stuck_out_tongue_winking_eye:

I have tested the flow as you can see in the image when I write from telegram / Temperature reaches the red node it makes the change to 24 but it does not get to return 24 to telegram

Telegram App

I have also changed it to test but that change has not worked for me

@osancleca Just change the text "mesage.content" to "payload.content" in the change node in your post #14 and it WILL send the message "24" to Telegram. You can just send another screenshot after your change!

Have you been able to get any message sent by your bot? Which Telegram node are you using? It might be that you have some configuration missing from the Telegram Sender node. Or it might require certain fields to be in the msg sent to it. I don't have the node installed so I can't check what it's documentation on the sidebar says...

Sorry for not answering before but I am new to the forum and I was temporarily blocked because I had a limit of messages in one day

It has worked like this, the problem was that in the change node when the change is made to 24 it has to put you in the form of a string, if you change it to number it did not work there was the problem

Tomorrow I will have the plc and I will be able to connect node s7 to read the real temperature

Now what I am trying is when I send from telegram / Temperature that it returns 24 but simulating that I have node s7 connected, but I am not able to make the code to detect the entry of 2 variables in the final node of function and make a if that if Temperature enters me it returns the value of the second variable, in this case 24

I was thinking of using a join node like in this example to capture the 2 variables and in the function node to do an if (msg == Temperature)
return the value of the second variable, the problem I have is that in this example the variables do arrive with a name and are not a container, I am a bit blocked, any suggestion please

FlowJoin.json (1.5 KB)

Based on your screenshots and explanation I think you are over complicating this. How I would imagine this to work is a flow like:

/Temperature from Telegram -> s7 node -> change node to move temperature from msg.payload to msg.payload.content -> Telegram Sender

So a direct flow with no branches and no function nodes.

I understand that from what you tell me this would be the flow

Anyway, I would like to know how to make a function node with several input variables and to be able to make a code in which, depending on the input that I want to generate an output, it is more than anything because I see Red Node as super interesting. And I think that at some point whether or not I am in this project, I will have to face this.

Could you give a practical example what you would like to achieve (on a higher level)? Based on that it's simpler to give hints.

Note that while you can do pretty much anything in function nodes, the idea with Node-RED's system is to use the various building blocks to create a flow. In many cases you can achieve an easier to follow flow if you utilise the other core nodes instead of using function nodes. Of course they have their place when other nodes would be unpractical.

Let's say you would have a simple Telegram input node. You would receive whatever you typed to your bot in msg.payload.content. You could then use a switch node to route the msg to multiple outouts based on what's in msg.payload.content. Then you could redirect the outputs to either do something like turn on a light or read data from a sensor like you're trying to do now.

ok, i get it, to be able to do if everything can be done through the nodes is interesting since it simplifies life a lot, tomorrow i will have the plc i will try it and tell you, greetings and thanks