How to pass information from a sensor to my telegram bot

I have communication with my telegram bot, if I write / help or / Temperature on the channel, it returns the same.
what I really want to do is that every time I type in the chat / Temperature the bot answers me through Red Node with the temperature value that I am going to read from a plc, this part of the plc here in the image gives an error by that the s7 node is not connected but I have tried that and it works for me, the problem is that I am not able to return by telegram the value of the temperature read, someone could help me.

FlowForo.json (1.7 KB)

Thank you

If you add an inject node before and a debug node after the s7 node, what does the s7 node output on the sidebar debug window? I'm asking just to know the format of the data you want to send through Telegram.

Thanks for answering,
node s7 is not connected since I don't have the plc, it is for a class practice and the physical plc I don't have it at home,
the data that node s7 will send will be a variable with an integer value, such as 24 for example

since I don't have the PLC I would like to know how to supply that node to test for a constant value that is continuously sending an integer value like 24 to the function node

Ok, so basically it could be replaced for now with a change node that sets msg.payload to number 24 (assuming the s7 node would write the value in the common payload property). The problem left would be how to get it sent with the "/temperature" command?

I checked the function node from your flow (I don't have the others) but is there a chance it could work just by adding this change node (that playes the role of the s7 node) between the chatbot "/Temperature" node and the "Telegram Sender" node? Skipping the function node.

Or did I misunderstand the problem?

I'm going to try it,
The function node I did to know that it is entering me from telegram, I did it to separate since in the future I want to integrate more sensors, the idea is that if I enter / Temperature from telegram, send the bot to chat 24, I do not know yes I have explained

I think you could also use a switch node instead of the function to split the incoming message by its topic. I believe that was what you were trying to do inside the function.

in this first image you can see what comes from telegram

In this second image I have put the change node and still it does not work for me

anyway the value of 24 when it has the plc is going to be dynamic since it will be the value of a temperature probe and it will come from node s7 that's what i mean

I use the Node-RED node node-red-contrib-telegrambot (icons and color both differ from your nodes, so I assume you have another telegram node installed) and there I have to change msg.payload.content to get the desired answer.

EDIT: I just saw on your second picture, that your msg object looks like mine and "/Temperature" is also in msg.payload.content! So you have to change msg.payload.content instead of msg.payload!

The idea with the change node was just to simulate what could come out of the s7 node.

Also you have configured the change node differently than I said. You should SET msg.payload, not CHANGE.

Another question - have tried you put a debug node after the "/Temperature" node? Does the message come through when you send the message/command to your bot?

What @stefan24 said seems likely, so to simulate a scenario with the sensor, you would add another change node after the one that sets msg.payload to 24. The second change node should MOVE msg.payload to msg.payload.content.

It sounds silly but we imagine the first change node to be the s7 node. The s7 node likely doesn't set the value to msg.payload.content unless it has a configuration option for this.

Sorry, @ristomatti, that's not true.
He just has to change msg.payload to msg.payload.content (edited again!!) in his change node.
So the input "/Temperature" will switch to "24" as output back to Telegram.
Either the input FROM telegram as the output TO telegram expect the message in msg.payload.content!
Just as we can see on the debug screen.

Later he sure will have to change the hardcoded "24" to the output of his S7 node, but that's not the problem for now!

still not sending 24 to telegram, I don't know if you were referring to the change that is seen in the image of the change node

if that leaves the node with /

Please read the thread from the beginning. As the PLC is not yet available, we use a change node in its place. I'll create a flow to try to explain what I mean. It will take a moment though as I need to do it on my tablet which is slow.

You did not write msg.payload.content, but msg.mesage.content, which is wrong! But it is the right place to change!!

I did :smiley:
But I use the same change node with my own Telegram input/output nodes here and I know what he is trying to achieve in the first place.

No I didn't? :slightly_smiling_face: