# How to pass information from a sensor to my telegram bot

**URL:** <https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839>\
**Category:** General\
**Created:** [5 June 2020 16:19 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839 "2020-06-05T16:19:25Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)\
**Post date:** [5 June 2020 16:19 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/1 "2020-06-05T16:19:25Z")

</div>

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.

 ![flow1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/9/c90c6da7401cbefba77f7276a78a1560942da886.png) [FlowForo.json](https://discourse.nodered.org/uploads/short-url/qsvdu26U9SALUMmTk5bppd9MFs0.json) (1.7 KB)

Thank you

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [5 June 2020 17:00 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/2 "2020-06-05T17:00:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)\
**Post date:** [5 June 2020 17:17 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/3 "2020-06-05T17:17:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [5 June 2020 17:22 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/4 "2020-06-05T17:22:02Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [5 June 2020 17:31 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/5 "2020-06-05T17:31:28Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)\
**Post date:** [5 June 2020 17:53 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/6 "2020-06-05T17:53:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [5 June 2020 18:02 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/7 "2020-06-05T18:02:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)\
**Post date:** [5 June 2020 18:49 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/8 "2020-06-05T18:49:16Z")

</div>

in this first image you can see what comes from telegram

 ![RR1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/5/a5d644721f3e791d6185ab57e23ae6d80969440b.png)

---

<div class="post-metadata">

**Author:** ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)\
**Post date:** [5 June 2020 18:50 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/9 "2020-06-05T18:50:06Z")

</div>

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

 ![RR2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/c/6c221b1bf86ec908d8035b4ea90eab3255d6c1f8.png)

---

<div class="post-metadata">

**Author:** ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)\
**Post date:** [5 June 2020 18:53 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/10 "2020-06-05T18:53:17Z")

</div>

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

 ![RR3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/1/c186fa356977d3fd4c672e3cd63a66afe3968c8b.png)

---

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [5 June 2020 19:00 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/11 "2020-06-05T19:00:04Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [5 June 2020 19:01 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/12 "2020-06-05T19:01:52Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [5 June 2020 19:06 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/13 "2020-06-05T19:06:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [5 June 2020 19:09 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/14 "2020-06-05T19:09:16Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)\
**Post date:** [5 June 2020 19:27 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/15 "2020-06-05T19:27:08Z")

</div>

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

 ![RR6](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/4/54b211b4806ed8d47847d6bf0880b157d46ad04a.png)

---

<div class="post-metadata">

**Author:** ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)\
**Post date:** [5 June 2020 19:33 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/16 "2020-06-05T19:33:16Z")

</div>

if that leaves the node with /

 ![RR7](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/9/89b6c3d4c4a7d4a6c3c8d351f863ce98eb14e717.png)

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [5 June 2020 19:37 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/17 "2020-06-05T19:37:50Z")

</div>

> [@stefan24](#):
>
> Sorry, @ristomatti, that's not true.  
> He just has to change msg.payload to msg.payload.content (edited again!!) in his change node.

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.

---

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [5 June 2020 19:42 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/18 "2020-06-05T19:42:13Z")

</div>

> [@osancleca](#):
>
> still not sending 24 to telegram

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

---

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [5 June 2020 19:45 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/19 "2020-06-05T19:45:01Z")

</div>

> [@ristomatti](#):
>
> Please read the thread from the beginning

I did 😃  
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.

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [5 June 2020 19:45 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/20 "2020-06-05T19:45:04Z")

</div>

> [@stefan24](#):
>
> You did not write msg.payload.content, but msg.mesage.content, which is wrong! But it is the right place to change!!

No I didn't? 🙂

[Next page](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839.md?page=2)
