Help Writing My First Function

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.

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

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

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

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?

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

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


1 Like