Dashboard Form -> python3-function node

Hi, I created a Dashboard (form node) with 2 elements , and I want to transfer the variables to a python3 function node.

Please can you adivse how to do this?

Many Thanks

Kind Regards

Marc

What have you tried ? The form will send an object on msg.payload. And the function will accept that, so you may be able to wire them together.

Hi dceejay,

I tried a few things to get the msg.payload in the function

This is the flow, please can you have a look at it:
In the form node, there is on element (on) and I want this value as a variable in the python3 function node.

I appreciate your help.
many Thanks

Marc

[{"id":"a5407a88.e48968","type":"ui_form","z":"cabd8eb4.cde01","name":"Formular","label":"","group":"985af1f8.09381","order":2,"width":"6","height":"6","options":[{"label":"Relais ein [Sek.]","value":"on","type":"number","required":true}],"formValue":{"on":""},"payload":"","submit":"Start","cancel":"Reset","topic":"","x":451,"y":246,"wires":[["ea5d198.c8f5de8"]]},{"id":"985af1f8.09381","type":"ui_group","z":"","name":"Default","tab":"67887c30.b9d3e4","disp":true,"width":"6"},{"id":"67887c30.b9d3e4","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]

Unfortunately your flow isn't currently importable.Please read the following post How to share code or flow json and then edit the above message.

Also tell us what you mean by 'python3 function node`. Is this one of the contrib nodes? If you mean node-red-contrib-python3-function then note that this appears to be unsupported and has issues against it that have not been addressed.
Alternatives are either use an exec node to call a python program or to use javascript in a function node.

Hi, That is just a form that sends a payload like {"on":5} in the payload like you wanted so, what did you do next ? This may help extracting data - https://nodered.org/docs/user-guide/messages

Hi, I shared a screenshot from the two nodes, unfortunately the function node was not exported from node red in my prevois post.

I have a raspi with a led.
I want to select a value via a form node and bring this value to the phyton3-function node.

I hope my explanation is understandable.
Thanks for helping.

Kind Regards

Marc

Before you go any further as @Colin mentioned the node you want to use doesn't appear to be supported by the author anymore.

Take a look at https://github.com/dejanrizvan/node-red-contrib-python3-function/issues

Turning a GPIO value on and off is fairly easy to do in Node-RED, there's no need to use a contrib-node to do what you appear to be trying to do

Hi ukmoose,

thanks for the answer, I know thats it's easy to turning a gpio value on in node red. I decided to do it with a python script, because I want to add more code which is easier for me to do in python.
But the first step is to bring this value to the function node.

Maybe you can give me a hint what is wrong with the python code?

It's sad to hear that the node doesn't appear to be supported. if the code looks correct and there is bug in the function I have to try another way.

You could always use something like Transcrypt to turn your Python into JavaScript :wink:

More seriously, if the contributed node is no longer supported, you could include a reference to Python Shell in settings.js and then grab it from the global variables in your function nodes. This has much better process interaction between Node and Python.

Why not try using Node-Red for the additional code? This would give you a great opportunity to learn more about NR.is this additional code not

I think I'm close to get this running. How can I get the 4 objects from msg.payload (on, endstate, repeat, off) into separate variables?

Thank you

Have you read about msgs https://nodered.org/docs/user-guide/messages

yes, but this is all javascript code, and not python code or?

Sorry I thought you were using the function node.

  1. you haven't provided the full name of the node you are using
  2. you haven't provided the flow in a form that is importable.

Why mess around writing your python code in those nodes? I assume the nodes have several other limitations like no support for threads, I skipped using python nodes long time ago, I have all my python code separated in scripts outside of NR and communicate NR <----> Python scripts using MQTT, Much better and can give you much better control

I guess there are some situations that much easier to handle by Python than JS, especially those about data processing.

It depends what you wanna do, there are advantages & disadvantages

Unless you are looking at specialist analytical processing that I don't believe that to be true. It is more about what people are familiar with.