# Create nodes to interpret keypad input

**URL:** <https://discourse.nodered.org/t/create-nodes-to-interpret-keypad-input/56489>\
**Category:** Developing Nodes\
**Created:** [11 January 2022 21:27 UTC](https://discourse.nodered.org/t/create-nodes-to-interpret-keypad-input/56489 "2022-01-11T21:27:45Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![daknightuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daknightuk/32/54017_2.png) [@daknightuk](https://discourse.nodered.org/u/daknightuk)\
**Post date:** [11 January 2022 21:27 UTC](https://discourse.nodered.org/t/create-nodes-to-interpret-keypad-input/56489/1 "2022-01-11T21:27:45Z")

</div>

I have an ESP8266 with remote control and ESP-Home is programmed to recognise numbers 0-9 in HA  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/d/2d7482b37ba8bcae3831a38b68896082f565aa4d.png)

What I was looking to do was to pick up each number press state from off to on convert the on action to a number which I think in node-red is referred to as a message payload and then use the combine to put the pressed numbers together as a string of 4 for comparison to a "security code"

Sounds simple but not even getting any debug outputs so I'm not sure what I am doing wrong and I'm struggling to find any decent step by step guides to help me with the Entity Node.

---

<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:** [11 January 2022 21:40 UTC](https://discourse.nodered.org/t/create-nodes-to-interpret-keypad-input/56489/2 "2022-01-11T21:40:00Z")

</div>

There are not too many HA uses (that I know of) frequent this forum I'm afraid so you may fair better asking on the HA forum.

That said, doesn't esp-easy talk mqtt?

If you use MQTT nodes there will be plenty here who can help.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [11 January 2022 21:51 UTC](https://discourse.nodered.org/t/create-nodes-to-interpret-keypad-input/56489/3 "2022-01-11T21:51:18Z")

</div>

Hi @daknightuk

As mentioned above, NR has built in Nodes for MQTT.

if these entity nodes however, are not providing the expected values - the HA community will likely have answers - albeit the developer (assumingly in that community) should be able to advise.

If your getting into Node Red however, and want to combine payloads for concatenation.  
You can use the **join** node, to create an array of the payloads (set to trigger after 4) i.e a 4 digit pin.

then use a function node to concatenate the values to yield your pin code.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/0/d00c90f69f8fcefc5447329e93e329a6d9e53a94.png)

Your function node will have

```javascript
let PinCode;

for(let i = 0;i<msg.payload.length;i++)
{
    PinCode += msg.payload[i]
}
return {payload:PinCode}

```

---

<div class="post-metadata">

**Author:** ![daknightuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daknightuk/32/54017_2.png) [@daknightuk](https://discourse.nodered.org/u/daknightuk)\
**Post date:** [11 January 2022 22:19 UTC](https://discourse.nodered.org/t/create-nodes-to-interpret-keypad-input/56489/4 "2022-01-11T22:19:50Z")

</div>

@marcus-j-davies

From the information you provided and also from a video I found I worked out I needed to use the state change node and then when I pass the payload message I pass the "digit" being pressed.  
Now I just need to work out how I do something with the pincode.  
\*\*

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/8/78b8ed2b90e9548b5f62c0f6a28a314c516eeaa4.png)  
\*\*

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [11 January 2022 22:28 UTC](https://discourse.nodered.org/t/create-nodes-to-interpret-keypad-input/56489/5 "2022-01-11T22:28:12Z")

</div>

> [@daknightuk](#):
>
> Now I just need to work out how I do something with the pincode.

That's where you explore 😉

Pass the pin code around your flows, do this or that, turn on a relay, send it to a web service, send an email, send it to an MQTT broker, check if its of a certain value etc etc.

its best to keep whatever you are passing around under the key of **payload**

i.e  
`{payload: integer | string | array | object}`

the **payload** key is widely used and nodes built in or otherwise will use it by default.

Have fun - there is plenty of Node Red help here.

---

<div class="post-metadata">

**Author:** ![daknightuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daknightuk/32/54017_2.png) [@daknightuk](https://discourse.nodered.org/u/daknightuk)\
**Post date:** [12 January 2022 09:14 UTC](https://discourse.nodered.org/t/create-nodes-to-interpret-keypad-input/56489/6 "2022-01-12T09:14:26Z")

</div>

I did a debug on the pincode its coming out as undefined1234  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/d/ad8ef14f5e9fdb45f3eeb0ce58afbca98efb388d.png)  
@marcus-j-davies any idea's I spent several hours trying to work out a solution.

---

<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:** [12 January 2022 09:36 UTC](https://discourse.nodered.org/t/create-nodes-to-interpret-keypad-input/56489/7 "2022-01-12T09:36:21Z")

</div>

> [@daknightuk](#):
>
> its coming out as undefined1234  
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/d/ad8ef14f5e9fdb45f3eeb0ce58afbca98efb388d.png)  
> @marcus-j-davies any idea's

Very difficult to help with a single screen shot.

Can you export your flow and describe the operations you perform.

---

<div class="post-metadata">

**Author:** ![daknightuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daknightuk/32/54017_2.png) [@daknightuk](https://discourse.nodered.org/u/daknightuk)\
**Post date:** [12 January 2022 09:49 UTC](https://discourse.nodered.org/t/create-nodes-to-interpret-keypad-input/56489/8 "2022-01-12T09:49:41Z")

</div>

Here is the export

Basically I have an ESP8266 connected to ESP-Home which has an infrared reciever.  
I am looking to get the 4 digit code from the remote based on buttons pressed.  
Each button is a binary sensor which is why I have remote\_key\_0 to remote\_key\_9.  
Each button is a momentary action i.e On then Off.  
The msg.payload has been combined thanks to some code which marcus provided but I get undefined which I think is something to do with the Combine when it creates the array.  
Not sure if I need to "declare" the type for msg.payload?

```auto
[{"id":"d58407e6a1aa0fbd","type":"tab","label":"Get Security Code","disabled":false,"info":"","env":[]},{"id":"ec804da156ea6773","type":"server-state-changed","z":"d58407e6a1aa0fbd","name":"","server":"28d29ba7.5cc1e4","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.remote_key_0","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"1","forType":"num","forUnits":"milliseconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"0","valueType":"str"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":80,"wires":[["29427d651418fd7f"],[]]},{"id":"f476e28dad6f0906","type":"server-state-changed","z":"d58407e6a1aa0fbd","name":"","server":"28d29ba7.5cc1e4","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.remote_key_1","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"1","forType":"num","forUnits":"milliseconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"1","valueType":"str"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":140,"wires":[["29427d651418fd7f"],[]]},{"id":"931b6628b27fc0c9","type":"server-state-changed","z":"d58407e6a1aa0fbd","name":"","server":"28d29ba7.5cc1e4","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.remote_key_2","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"1","forType":"num","forUnits":"milliseconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"2","valueType":"str"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":200,"wires":[["29427d651418fd7f"],[]]},{"id":"c2962f54d6b0af4a","type":"server-state-changed","z":"d58407e6a1aa0fbd","name":"","server":"28d29ba7.5cc1e4","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.remote_key_3","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"1","forType":"num","forUnits":"milliseconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"3","valueType":"str"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":260,"wires":[["29427d651418fd7f"],[]]},{"id":"945f9df12d244d4d","type":"server-state-changed","z":"d58407e6a1aa0fbd","name":"","server":"28d29ba7.5cc1e4","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.remote_key_4","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"1","forType":"num","forUnits":"milliseconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"4","valueType":"str"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":320,"wires":[["29427d651418fd7f"],[]]},{"id":"d926c35ea391d6b6","type":"server-state-changed","z":"d58407e6a1aa0fbd","name":"","server":"28d29ba7.5cc1e4","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.remote_key_5","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"1","forType":"num","forUnits":"milliseconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"5","valueType":"str"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":380,"wires":[["29427d651418fd7f"],[]]},{"id":"47fd9ffc4ebe9630","type":"server-state-changed","z":"d58407e6a1aa0fbd","name":"","server":"28d29ba7.5cc1e4","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.remote_key_6","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"1","forType":"num","forUnits":"milliseconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"6","valueType":"str"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":440,"wires":[["29427d651418fd7f"],[]]},{"id":"24e77e3a72f0bdbc","type":"server-state-changed","z":"d58407e6a1aa0fbd","name":"","server":"28d29ba7.5cc1e4","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.remote_key_7","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"1","forType":"num","forUnits":"milliseconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"7","valueType":"str"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":500,"wires":[["29427d651418fd7f"],[]]},{"id":"239e9b7a4e52235e","type":"server-state-changed","z":"d58407e6a1aa0fbd","name":"","server":"28d29ba7.5cc1e4","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.remote_key_8","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"1","forType":"num","forUnits":"milliseconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"8","valueType":"str"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":560,"wires":[["29427d651418fd7f"],[]]},{"id":"5fd40fe50f1227f5","type":"server-state-changed","z":"d58407e6a1aa0fbd","name":"","server":"28d29ba7.5cc1e4","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.remote_key_9","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"1","forType":"num","forUnits":"milliseconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"9","valueType":"str"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":620,"wires":[["29427d651418fd7f"],[]]},{"id":"29427d651418fd7f","type":"join","z":"d58407e6a1aa0fbd","name":"Combine Digits","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":670,"y":320,"wires":[["8dcd5e79f9f8cda9"]]},{"id":"8dcd5e79f9f8cda9","type":"function","z":"d58407e6a1aa0fbd","name":"Get Pincode","func":"let PinCode;\n\nfor(let i = 0;i<msg.payload.length;i++)\n{\n PinCode += msg.payload[i]\n}\nreturn {payload:PinCode}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":850,"y":320,"wires":[["6858598e172efa7d"]]},{"id":"6858598e172efa7d","type":"debug","z":"d58407e6a1aa0fbd","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1070,"y":320,"wires":[]},{"id":"28d29ba7.5cc1e4","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

```

---

<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:** [12 January 2022 10:25 UTC](https://discourse.nodered.org/t/create-nodes-to-interpret-keypad-input/56489/9 "2022-01-12T10:25:58Z")

</div>

You didnt initialise the variable in your function to empty string.

![chrome_AoDQsXtAmH](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/b/6b308e5657c25ec38c4441bd2cb0141dd4bce5d1.gif)

This works...

```auto
[{"id":"7e01e6c58d6d88db","type":"join","z":"6ae4dd80c061dc7a","name":"Combine Digits","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1920,"y":180,"wires":[["ab4ad40b4df17a78"]]},{"id":"ab4ad40b4df17a78","type":"function","z":"6ae4dd80c061dc7a","name":"Get Pincode","func":"let pin = \"\";\nfor (let i = 0; i < msg.payload.length; i++) {\n pin += msg.payload[i];\n}\nreturn { payload: pin };\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1940,"y":220,"wires":[["02f1fafdc71e278d"]]},{"id":"02f1fafdc71e278d","type":"debug","z":"6ae4dd80c061dc7a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1960,"y":260,"wires":[]},{"id":"c35c0940fea7a360","type":"inject","z":"6ae4dd80c061dc7a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":1720,"y":100,"wires":[["7e01e6c58d6d88db"]]},{"id":"c626bc4e47eefb01","type":"inject","z":"6ae4dd80c061dc7a","name":"","props":[{"p":"payload"},{"p":"topic","v":"","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2","payloadType":"num","x":1720,"y":140,"wires":[["7e01e6c58d6d88db"]]},{"id":"b571908ae6b6b98e","type":"inject","z":"6ae4dd80c061dc7a","name":"","props":[{"p":"payload"},{"p":"topic","v":"","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"3","payloadType":"num","x":1720,"y":180,"wires":[["7e01e6c58d6d88db"]]},{"id":"4dcfef25aa1db067","type":"inject","z":"6ae4dd80c061dc7a","name":"","props":[{"p":"payload"},{"p":"topic","v":"","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"4","payloadType":"num","x":1720,"y":220,"wires":[["7e01e6c58d6d88db"]]},{"id":"43625c3421f6a390","type":"inject","z":"6ae4dd80c061dc7a","name":"","props":[{"p":"payload"},{"p":"topic","v":"","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"5","payloadType":"num","x":1720,"y":260,"wires":[["7e01e6c58d6d88db"]]}]

```

---

<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:** [12 January 2022 11:06 UTC](https://discourse.nodered.org/t/create-nodes-to-interpret-keypad-input/56489/10 "2022-01-12T11:06:02Z")

</div>

Just for info. You do not need the function if you join the payloads as a string.  
[edit] I would also add a timeout to the join so the password input resets after a few seconds. Then when you partly input code it will reset.

---

<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:** [12 January 2022 11:10 UTC](https://discourse.nodered.org/t/create-nodes-to-interpret-keypad-input/56489/11 "2022-01-12T11:10:08Z")

</div>

> [@E1cid](#):
>
> You do not need the function if you join the payloads as a string

Indeed. (I left the function there as the question was about getting undefined in his function)

@daknightuk as @E1cid rightly says, you can simplify this by changing the `join` to create a string

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/c/fc014ccbe761fbf7d279c6af524e572cc0041050.png)

![chrome_7YuiLnzb6j](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/5/f556b1172bd5ac74cd76b548eaecabe70baea03a.gif)

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [12 January 2022 11:41 UTC](https://discourse.nodered.org/t/create-nodes-to-interpret-keypad-input/56489/12 "2022-01-12T11:41:39Z")

</div>

2nd it!

I wasn't sure if the value of interest was in fact the payload - as apposed to something further down.  
If so - I think you can do that in the **Combine each** path anyway right?

---

<div class="post-metadata">

**Author:** ![daknightuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daknightuk/32/54017_2.png) [@daknightuk](https://discourse.nodered.org/u/daknightuk)\
**Post date:** [12 January 2022 11:50 UTC](https://discourse.nodered.org/t/create-nodes-to-interpret-keypad-input/56489/13 "2022-01-12T11:50:26Z")

</div>

Ah I see what you mean, yes it works the key is to remove the /n which is why the msg.payload looked like it had a load of "Carriage Returns"

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/7/3739a083d332d33c7c68b029a5f1489b5a0f60bb.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/8/28c0ab9dea86ad7b32b69a4d3d9bbffe103b24d3.png)

---

<div class="post-metadata">

**Author:** ![daknightuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daknightuk/32/54017_2.png) [@daknightuk](https://discourse.nodered.org/u/daknightuk)\
**Post date:** [12 January 2022 13:12 UTC](https://discourse.nodered.org/t/create-nodes-to-interpret-keypad-input/56489/14 "2022-01-12T13:12:54Z")

</div>

Final code for my keypad which links into HA manual alarm panel  
This is a disarm function only using the code "2222"  
I arm using voice control.

```auto
[{"id":"d58407e6a1aa0fbd","type":"tab","label":"Get Security Code","disabled":false,"info":"","env":[]},{"id":"ec804da156ea6773","type":"server-state-changed","z":"d58407e6a1aa0fbd","name":"","server":"28d29ba7.5cc1e4","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.remote_key_0","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"1","forType":"num","forUnits":"milliseconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"0","valueType":"str"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":80,"wires":[["7e01e6c58d6d88db"],[]]},{"id":"f476e28dad6f0906","type":"server-state-changed","z":"d58407e6a1aa0fbd","name":"","server":"28d29ba7.5cc1e4","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.remote_key_1","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"1","forType":"num","forUnits":"milliseconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"1","valueType":"str"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":140,"wires":[["7e01e6c58d6d88db"],[]]},{"id":"931b6628b27fc0c9","type":"server-state-changed","z":"d58407e6a1aa0fbd","name":"","server":"28d29ba7.5cc1e4","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.remote_key_2","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"1","forType":"num","forUnits":"milliseconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"2","valueType":"str"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":200,"wires":[["7e01e6c58d6d88db"],[]]},{"id":"c2962f54d6b0af4a","type":"server-state-changed","z":"d58407e6a1aa0fbd","name":"","server":"28d29ba7.5cc1e4","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.remote_key_3","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"1","forType":"num","forUnits":"milliseconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"3","valueType":"str"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":260,"wires":[["7e01e6c58d6d88db"],[]]},{"id":"945f9df12d244d4d","type":"server-state-changed","z":"d58407e6a1aa0fbd","name":"","server":"28d29ba7.5cc1e4","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.remote_key_4","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"1","forType":"num","forUnits":"milliseconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"4","valueType":"str"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":320,"wires":[["7e01e6c58d6d88db"],[]]},{"id":"d926c35ea391d6b6","type":"server-state-changed","z":"d58407e6a1aa0fbd","name":"","server":"28d29ba7.5cc1e4","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.remote_key_5","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"1","forType":"num","forUnits":"milliseconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"5","valueType":"str"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":380,"wires":[["7e01e6c58d6d88db"],[]]},{"id":"47fd9ffc4ebe9630","type":"server-state-changed","z":"d58407e6a1aa0fbd","name":"","server":"28d29ba7.5cc1e4","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.remote_key_6","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"1","forType":"num","forUnits":"milliseconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"6","valueType":"str"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":440,"wires":[["7e01e6c58d6d88db"],[]]},{"id":"24e77e3a72f0bdbc","type":"server-state-changed","z":"d58407e6a1aa0fbd","name":"","server":"28d29ba7.5cc1e4","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.remote_key_7","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"1","forType":"num","forUnits":"milliseconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"7","valueType":"str"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":500,"wires":[["7e01e6c58d6d88db"],[]]},{"id":"239e9b7a4e52235e","type":"server-state-changed","z":"d58407e6a1aa0fbd","name":"","server":"28d29ba7.5cc1e4","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.remote_key_8","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"1","forType":"num","forUnits":"milliseconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"8","valueType":"str"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":560,"wires":[["7e01e6c58d6d88db"],[]]},{"id":"5fd40fe50f1227f5","type":"server-state-changed","z":"d58407e6a1aa0fbd","name":"","server":"28d29ba7.5cc1e4","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.remote_key_9","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"1","forType":"num","forUnits":"milliseconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"9","valueType":"str"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":620,"wires":[["7e01e6c58d6d88db"],[]]},{"id":"7e01e6c58d6d88db","type":"join","z":"d58407e6a1aa0fbd","name":"Combine Digits","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"","joinerType":"str","accumulate":false,"timeout":"3","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":540,"y":80,"wires":[["475bcbd476515e89"]]},{"id":"475bcbd476515e89","type":"function","z":"d58407e6a1aa0fbd","name":"Check Pin","func":"var payload = msg.payload;\nif (msg.payload==\"2222\"){\n msg.payload = 1;\n} else {\n msg.payload = 0;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":700,"y":80,"wires":[["258f8ea6099ad45c"]]},{"id":"23edf12e78b1b735","type":"api-call-service","z":"d58407e6a1aa0fbd","name":"","server":"28d29ba7.5cc1e4","version":3,"debugenabled":false,"service_domain":"alarm_control_panel","service":"alarm_disarm","entityId":"alarm_control_panel.home_security_system","data":"{\"code\":2222}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":780,"y":340,"wires":[[]]},{"id":"258f8ea6099ad45c","type":"switch","z":"d58407e6a1aa0fbd","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":890,"y":80,"wires":[["23edf12e78b1b735"],[]]},{"id":"28d29ba7.5cc1e4","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

```

---

<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:** [12 January 2022 13:15 UTC](https://discourse.nodered.org/t/create-nodes-to-interpret-keypad-input/56489/15 "2022-01-12T13:15:33Z")

</div>

Hi, in order to make code more readable and importable it is important to surround your code with three backticks  
`````  
`like this`  
`````

You can edit and correct your post by clicking the pencil icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<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:** [26 January 2022 13:16 UTC](https://discourse.nodered.org/t/create-nodes-to-interpret-keypad-input/56489/16 "2022-01-26T13:16:28Z")

</div>

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