• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

why do On Payload and Off Payload change values in node-red edit switch node

Q&A Forum › Category: ESP8266 › why do On Payload and Off Payload change values in node-red edit switch node
0 Vote Up Vote Down
merkelck asked 6 years ago

What is causing the On/Off payload values to switch from the entered values in Node-Red “Edit switch node”? I have noted the warnings in the course material and I have had some luck getting them to work but not always. I have entered the digits “1” and “0” as numbers and strings but they always change back to “true” and “false” . This appears contrary to course instructions but I can’t make it work reliably enough.

Question Tags: node-red edit switch node
14 Answers
0 Vote Up Vote Down
Rui Santos Staff answered 6 years ago

Hello, can you add to those fields the words “on” and “off”. Then, in the code if/else statements, can you change it also to “on” and “off”? Instead of “1” and “0”…
If you need further help let me know. Thanks for your patience. Regards,
Rui

0 Vote Up Vote Down
merkelck answered 6 years ago

I thought of that later but have not had a chance to try it. But I will today and let you know what happens. It always seems to want to change it to “true” or “false” no matter if I select number or string.
I will keep you posted.

0 Vote Up Vote Down
Rui Santos Staff answered 6 years ago

Ok! Keep me updated, if the error persists I’ll have to double-check and update the course. Regards,
Rui

0 Vote Up Vote Down
merkelck answered 6 years ago

Rui,
I tried as previously discussed. The code is here. This allowed the use of either “1” or “true”, “0” or “false”. However, I still found some irregularity here as sometimes the inputs would change after clicking “DONE” . For the most part, input error would be caught and reported after selecting “DEPLOY” . The flow error would be reported. This is getting pretty picky but frustrating for someone new to this stuff. (me)
Thanks for your help,  I still need to learn how to copy code from the IDE to insert into this forum..
______________________
if(topic==”home/office/esp1/gpio2″){
Serial.print(“Changing GPIO 2 to “);
if(messageTemp == “true”);
else if(messageTemp == “1”){
digitalWrite(ledGPIO2, HIGH);
Serial.print(“On”);
}
else if(messageTemp == “false”);
else if(messageTemp == “0”)
{
digitalWrite(ledGPIO2, LOW);
Serial.print(“Off”);
}
}

0 Vote Up Vote Down
Rui Santos Staff answered 6 years ago

Yes, I totally understand and I’ll update the course with that change in 1 or 2 weeks.

If you enter in the Node-RED fields the words “on” and “off“. Then, your code should look like this:

if(topic=="home/office/esp1/gpio2"){
  Serial.print("Changing GPIO 2 to ");
  if(messageTemp == "on"){
    digitalWrite(ledGPIO2, HIGH);
    Serial.print("On");
  }
  else if(messageTemp == "off"){
    digitalWrite(ledGPIO2, LOW);
    Serial.print("Off");
  }
}

Does that work for you? Thanks!

0 Vote Up Vote Down
merkelck answered 6 years ago

Yes, that worked fine.
 

0 Vote Up Vote Down
Rui Santos Staff answered 6 years ago

I’m glad it worked! Regards,
Rui

0 Vote Up Vote Down
merkelck answered 6 years ago

Rui,
This issue has reared it’s ugly head again. I have been working through the course again and ran into this issue. The last time I was able to add and if/else statement that would allow the choice of two variables (true or 1) (false or 0). However, it appears that the “mqtt_esp8266” example has been changed and I am not sure how this code can be changed to accept either value. Here is the current version:
// Switch on the LED if an 1 was received as first character
if ((char)payload[0] == ‘1’) {
digitalWrite(BUILTIN_LED, LOW); // Turn the LED on (Note that LOW is the voltage level
// but actually the LED is on; this is because
// it is active low on the ESP-01)
} else {
digitalWrite(BUILTIN_LED, HIGH); // Turn the LED off by making the voltage HIGH
}
can you point me to some info that will allow me to tackle this?
Thanks

0 Vote Up Vote Down
merkelck answered 6 years ago

Rui,
I was able to get passed this issue even though I do not understand it fully. I do understand my error in making the entries in the payload of the switch node. I had to make sure the 1/0 was being entered as a number and not a string. So for now I am moving on to accomplish my goal with the “simple” push button remote for my sonoff devices.

0 Vote Up Vote Down
Rui Santos Staff answered 6 years ago

I’m glad you were able to find a work around! Sorry about the trouble during this process.

0 Vote Up Vote Down
Robert Johns answered 4 years ago

Having same problem as the members above.

In the pdf file Rui mentions:

“Important:sometimes the switch nodekeeps the default values trueand falseafter you press Done. If your project isn’t working, double-check thatyour On Payloadand your Off Payloadfields are set to1and 0, respectively”

Is there a fix for this or a really good trick??. It’s really frustrating, tried like 10 times and it kept going back to true & false! Don’t know what I did but then it finally stayed.  Argghh!!!

The original posted asked this 2 years ago. Still no fix????

0 Vote Up Vote Down
Rui Santos Staff answered 4 years ago

Hello Robert.

I’m sorry to hear that! I honestly thought this issued was fixed by now, I didn’t realize there was people still having this error on Node-RED. Can you change the text on Node-RED nodes of the payload to the text “on” and “off”, instead of “1” and “0”.

Then, in the void callback() function change messageTemp comparisons to “on” and “off”:

if(messageTemp == "on"){

And off:

else if(messageTemp == "off"){

Thanks for your patience!

0 Vote Up Vote Down
Robert Johns answered 4 years ago

Thank you Rui. I just tried that and it works! Now I can go to the next module…
P.S. having a blast with this course! Best $25 I ever spent. 🙂

0 Vote Up Vote Down
Christopher Hughes answered 3 years ago

Most have tried this 100 times over several days.  Finally got it to change from True and False to 1 and 0 by first changing to on and off, then deploying it with the error, then going back to edit the node to 1 and 0, redeploy and it stayed 1 and 0.  No idea how or why but it works.

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.