# 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:** 3

<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:** [9 June 2020 15:59 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/41 "2020-06-09T15:59:56Z")

</div>

hello, the flow would stay like this, I have been trying things since this morning before asking and I am not able to solve it,

From telegram I ask for the temperature and the s7 node changed to content, but when making the swich I do not know how to configure it so that if I enter / Temperature it debuts me as content only the value of the temperature that I read from the PLC Please if you could show me an example, I would appreciate it

 ![RR20](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/5/f57b37a2814e520056f99b960715585754f19de5.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:** [9 June 2020 16:00 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/42 "2020-06-09T16:00:11Z")

</div>

![RR21](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/c/dc3e0b497720748813f743688423ac2298c6cc94.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:** [9 June 2020 16:02 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/43 "2020-06-09T16:02:27Z")

</div>

on the other hand, I would not know how to change the Home temperature msg to a content with the necessary fields to send it to telegram, the fields are those of the image content ,,

 ![RR22](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/9/0954e75e8ed0964796310a1e1aaa872488658c95.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:** [9 June 2020 16:56 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/44 "2020-06-09T16:56:19Z")

</div>

Previously there was a s7 node that also had an input but now it has changed to some other node I do not know either. The input would have allowed to trigger reading of the temperature when a message from Telegram arrives but now as there is no input on the HomeTemperature node, my previous example won't work.

I assume the HomeTemperature node is sending the temperature by itself by some interval? This would mean you would need to save the latest value somewhere. And that somewhere would be the flow context. You can read about it here: [https://nodered.org/docs/user-guide/context](https://nodered.org/docs/user-guide/context)

The idea would be to save the latest temperature in the flow context and then when a message requesting temperature arrives, you use a change node to set the `msg.payload.content` to the value you have stored in the flow context.

---

<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:** [9 June 2020 17:16 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/45 "2020-06-09T17:16:12Z")

</div>

I have also tried it, but it gives me an error when sending the telegram and I understand that it is because it does not have the structure of the message it is waiting for

 ![RR23](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/3/e38a30642ad99ea55c38b83096b2f1178c214e1c.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:** [9 June 2020 17:18 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/46 "2020-06-09T17:18:02Z")

</div>

this structure and I don't know how to create it ![RR24](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/0/50af741468e7fc681803080fe90867c253e2585e.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:** [9 June 2020 17:22 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/47 "2020-06-09T17:22:23Z")

</div>

Add a debug node after the s7 node to see what it outputs. It was only a guess previously that it would send the value as `msg.payload`. Then you will known where to move the value in the change node. As I don't know how the Telegram node you have works either, you need to read the instructions from the sidebar to know the data format.

If you still have problems, you can post a screenshot of what the s7 node output to debug is and also another screenshot of the Telegram Sender node instructions from the sidebar. Otherwise I would just be making guesswork.

---

<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:** [9 June 2020 17:24 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/48 "2020-06-09T17:24:51Z")

</div>

> [@osancleca](#):
>
> this structure and I don't know how to create it

You can set all the values in a change node. I doubt you need to have all that data filled. Check what the node instructions tell.

---

<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:** [9 June 2020 17:30 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/49 "2020-06-09T17:30:13Z")

</div>

S7 Node

 ![RR25](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/2/e2f2bf9987eedc7127bf8c3e3973a8672535d002.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:** [9 June 2020 17:33 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/50 "2020-06-09T17:33:23Z")

</div>

telegram message structure

 ![RR26](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/4/a40720c496828edcb0cc0ac9fd95995151750064.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:** [9 June 2020 17:35 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/51 "2020-06-09T17:35:23Z")

</div>

Ok so the value is stored as the first index of an array `msg.payload.value`. To read it in change node you would use `msg.payload.value[0]`. The temperature value looks like it would need a conversion to a human readable value though. Possibly @Steve-Mcl could help with interpreting that if needed(?)

---

<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:** [9 June 2020 17:37 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/52 "2020-06-09T17:37:36Z")

</div>

> [@osancleca](#):
>
> telegram message structure

You have sent this already. I was asking to send the help text you get on the sidebar info tab when you have the Telegram Sender node selected. It would likely help also if you could send a screenshot of its configuration (you can first erase any personal info if it has).

---

<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:** [9 June 2020 17:48 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/53 "2020-06-09T17:48:05Z")

</div>

does not put any relevant information in the help text

---

<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:** [9 June 2020 17:49 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/54 "2020-06-09T17:49:02Z")

</div>

telegram input node configuration

 ![RR27](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/0/50f79fc9021c3c46c62f96804d22c5177310bad5.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:** [9 June 2020 17:49 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/55 "2020-06-09T17:49:28Z")

</div>

telegram output node configuration

 ![RR28](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/5/05079405fcf93869fa88bca4cdc7019775907dc8.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:** [9 June 2020 18:00 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/56 "2020-06-09T18:00:42Z")

</div>

Ok. I wonder if the documentation it has here is everything there is then [https://flows.nodered.org/node/node-red-contrib-chatbot](https://flows.nodered.org/node/node-red-contrib-chatbot)? The example isn't very helpful.

Have you tried to create the simple 3 node example flow there? Did you get the message sent that way? If so, what you could do is add a debug node after the Message node and this will tell the format of the message to be sent. Or was the screenshot you sent earlier done like this already?

---

<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:** [9 June 2020 18:02 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/57 "2020-06-09T18:02:38Z")

</div>

yes I did but I implement it in a moment and I'll show it to you

---

<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:** [9 June 2020 18:10 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/58 "2020-06-09T18:10:38Z")

</div>

receiver

 ![RR29](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/4/d4dd7b9ae1f995057a51120f48c23a89fdeb101d.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:** [9 June 2020 18:12 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/59 "2020-06-09T18:12:35Z")

</div>

Sender

 ![RR30](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/e/6e0b54e919fd94e6ff9a742277c4d84547d40a07.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:** [9 June 2020 18:29 UTC](https://discourse.nodered.org/t/how-to-pass-information-from-a-sensor-to-my-telegram-bot/27839/60 "2020-06-09T18:29:16Z")

</div>

Maybe the easiest would be to add a Message node after your /Temperature node and then use change node to just change the `msg.payload.content`. Everything else would be filled in already. The problem is that if you would then pass it through the s7 node, it would replace the `payload`. This would not be a problem with the flow context approach I described earlier.

So you would have a flow:

```auto
Telegram Receiver - /Temperature - Message - Change node - Telegram Sender

```

In the change node you would replace `msg.payload.content` with the temperature value from a `flow` context where you would periodically update the latest temperature in a separate flow.

There would be multiple ways to accomplish the same but I'm too tired for the day to think of a better one. Hopefully someone else can chime in with their ideas. 🙂

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

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