# Help Writing My First Function

**URL:** <https://discourse.nodered.org/t/help-writing-my-first-function/14918>\
**Category:** General\
**Created:** [29 August 2019 16:29 UTC](https://discourse.nodered.org/t/help-writing-my-first-function/14918 "2019-08-29T16:29:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![MNiehaus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mniehaus/32/11436_2.png) [@MNiehaus](https://discourse.nodered.org/u/MNiehaus)\
**Post date:** [29 August 2019 16:29 UTC](https://discourse.nodered.org/t/help-writing-my-first-function/14918/1 "2019-08-29T16:29:20Z")

</div>

I could use some help getting my function to operate correctly. Here is my setup so far: rpi gpio node set up as a button pin input, looking for 1 or 0...This is linked to the email node. You push the button and get an email. Email is sent successfully, but it sends a 1 or 0 depending on the state of the pin.  
What I would like is a function node between my rpi gpio node and my email node. If button pin is HIGH/1, than send an email...If button pin is LOW/0, than do nothing.

Im really pretty good w/ Arduino IDE and coding, but rpi and Node-RED are very new to me. Im learning, but could use some help w/ this first example.

I appreciate any help you guys can give.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [29 August 2019 16:33 UTC](https://discourse.nodered.org/t/help-writing-my-first-function/14918/2 "2019-08-29T16:33:51Z")

</div>

often you may not need a function... look at the switch node...

---

<div class="post-metadata">

**Author:** ![MNiehaus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mniehaus/32/11436_2.png) [@MNiehaus](https://discourse.nodered.org/u/MNiehaus)\
**Post date:** [29 August 2019 16:39 UTC](https://discourse.nodered.org/t/help-writing-my-first-function/14918/3 "2019-08-29T16:39:12Z")

</div>

How would I set the switch node up to do what I need for it to do?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [29 August 2019 16:44 UTC](https://discourse.nodered.org/t/help-writing-my-first-function/14918/4 "2019-08-29T16:44:05Z")

</div>

drop in you flow, double click it and look at its options

---

<div class="post-metadata">

**Author:** ![MNiehaus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mniehaus/32/11436_2.png) [@MNiehaus](https://discourse.nodered.org/u/MNiehaus)\
**Post date:** [29 August 2019 16:47 UTC](https://discourse.nodered.org/t/help-writing-my-first-function/14918/5 "2019-08-29T16:47:42Z")

</div>

I got it! So now I have the switch between rpi gpio node and email node. I have the switch rule set to only send an email when the the value is == to 0. The email that was sent has pi/37 in the subject line and 0 in the body. How do i change the subject and body?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [29 August 2019 16:50 UTC](https://discourse.nodered.org/t/help-writing-my-first-function/14918/6 "2019-08-29T16:50:21Z")

</div>

maybe use a `change` node...😁  
look at the options on the email node to see what msg properties you can send into it.

---

<div class="post-metadata">

**Author:** ![MNiehaus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mniehaus/32/11436_2.png) [@MNiehaus](https://discourse.nodered.org/u/MNiehaus)\
**Post date:** [29 August 2019 17:03 UTC](https://discourse.nodered.org/t/help-writing-my-first-function/14918/7 "2019-08-29T17:03:16Z")

</div>

That worked! msg.payload for the body and msg.topic for the subject line. I really appreciate you guys and your help!

Matt
