# Unable to get binary sensor status and send to telegram

**URL:** https://discourse.nodered.org/t/unable-to-get-binary-sensor-status-and-send-to-telegram/68559
**Category:** General
**Tags:** function-node, home-assistant
**Created:** [4 October 2022 15:28 UTC](https://discourse.nodered.org/t/unable-to-get-binary-sensor-status-and-send-to-telegram/68559 "2022-10-04T15:28:30Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![khnlelim](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/khnlelim/32/68659_2.png) [@khnlelim](https://discourse.nodered.org/u/khnlelim)
#### Post date: [4 October 2022 15:28 UTC](https://discourse.nodered.org/t/unable-to-get-binary-sensor-status-and-send-to-telegram/68559/1 "2022-10-04T15:28:30Z")

</div>

Hi Guys,

I am new to home assistant and NodeRed.

Currently I have having a door sensor installed,

Here is my flow. However I able to get pass to call service, but no message is send out. Able to assist me?

 ![Screenshot 2022-10-04 232014](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/8/5885008853b9ca5a6a80fd01dbfd570373ab397f.png)  
 ![Screenshot 2022-10-04 232059](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/e/fe9cbaea6cc487f77a26dae0ef47e67a1be1a852.png)

Secondly, I would like to send the status of the the currently binary sensor stat to telegram. Can advice on this?

Nothing is send to telegram....

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [4 October 2022 15:51 UTC](https://discourse.nodered.org/t/unable-to-get-binary-sensor-status-and-send-to-telegram/68559/2 "2022-10-04T15:51:20Z")

</div>

> [@khnlelim](#):
>
> but no message is send out.

does the msg contain a chat ID? (use a debug node after the function node)

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [4 October 2022 15:54 UTC](https://discourse.nodered.org/t/unable-to-get-binary-sensor-status-and-send-to-telegram/68559/3 "2022-10-04T15:54:41Z")

</div>

Also add a debug to the telegram node, set it to complete message. The telegram node has reasonable good error reporting.

---

<div class="post-metadata">

### Author: ![khnlelim](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/khnlelim/32/68659_2.png) [@khnlelim](https://discourse.nodered.org/u/khnlelim)
#### Post date: [5 October 2022 13:30 UTC](https://discourse.nodered.org/t/unable-to-get-binary-sensor-status-and-send-to-telegram/68559/4 "2022-10-05T13:30:13Z")

</div>

Hi,

I had added the debug node after the function and the telegram node.

 ![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/b/6bc1c428ae132fba140f6620647283a2404ad80e.png)

Here are the reply for the debug  
 ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/7/a7c2068f44330fbcb2389442883a6cda46e94289.png)  
It seems debug after telegram node does not show anything

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [5 October 2022 13:49 UTC](https://discourse.nodered.org/t/unable-to-get-binary-sensor-status-and-send-to-telegram/68559/5 "2022-10-05T13:49:25Z")

</div>

Add a debug node showing what is coming from the Both Gate Open node.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [5 October 2022 13:59 UTC](https://discourse.nodered.org/t/unable-to-get-binary-sensor-status-and-send-to-telegram/68559/6 "2022-10-05T13:59:30Z")

</div>

It would seem that msg.payload coming from the HA node is a string of value "off". So your function can not add object properties to a string.  
In your function before the lines that are trying to add properties to the payload string, add the line `msg.payload = {};` This will convert msg.payload to a object. If you require the value "off" move it to another variable to use later, if required.

---

<div class="post-metadata">

### Author: ![khnlelim](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/khnlelim/32/68659_2.png) [@khnlelim](https://discourse.nodered.org/u/khnlelim)
#### Post date: [5 October 2022 14:53 UTC](https://discourse.nodered.org/t/unable-to-get-binary-sensor-status-and-send-to-telegram/68559/7 "2022-10-05T14:53:24Z")

</div>

Hi, thanks for replying,

After adding msg.payload = {}, which the function node would be like this

msg.payload = {};  
msg.payload.content = "Gate is opening... Please wait a moment"  
msg.payload.type = 'message'

return [msg];

i get the following from the debug  
 ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/e/fe5f8aca5a4143c64303a31aa516b41a67b7282c.png)

---

<div class="post-metadata">

### Author: ![khnlelim](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/khnlelim/32/68659_2.png) [@khnlelim](https://discourse.nodered.org/u/khnlelim)
#### Post date: [5 October 2022 14:54 UTC](https://discourse.nodered.org/t/unable-to-get-binary-sensor-status-and-send-to-telegram/68559/8 "2022-10-05T14:54:45Z")

</div>

Hi i added the debug not into "Both gate open" Node, it came out "off"

 ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/9/190fa45dde49236a0ea8790beeb181cf69e89182.png)

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [5 October 2022 15:09 UTC](https://discourse.nodered.org/t/unable-to-get-binary-sensor-status-and-send-to-telegram/68559/9 "2022-10-05T15:09:59Z")

</div>

> [@Steve-Mcl](#):
>
> does the msg contain a chat ID? (use a debug node after the function node)

So the error from Telegram says no chat\_id, so all you need to do is add a chat\_id to the function node  
Here is how to find a chat\_id

> <https://stackoverflow.com/questions/32423837/telegram-bot-how-to-get-a-group-chat-id>

---

<div class="post-metadata">

### Author: ![khnlelim](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/khnlelim/32/68659_2.png) [@khnlelim](https://discourse.nodered.org/u/khnlelim)
#### Post date: [5 October 2022 15:45 UTC](https://discourse.nodered.org/t/unable-to-get-binary-sensor-status-and-send-to-telegram/68559/10 "2022-10-05T15:45:50Z")

</div>

Thanks for the advice and guidance, after adding the chatid, the fucntion node able to work

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [4 December 2022 15:46 UTC](https://discourse.nodered.org/t/unable-to-get-binary-sensor-status-and-send-to-telegram/68559/11 "2022-12-04T15:46:18Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
