Pass input parameters to a script using pythonshell node

Hi all, I hope I can find some help regarding the following:

I'm using pythonshell node to execute a script for statistical prediction, using input parameters obtained from a weather station via MQTT (sun altitude and azimuth, direct and diffuse solar radiation).

My question: how to make the shell scrypt node to read input values from the server? Note: the script is not mine, so I'd prefer not to modify it, is it possible some way around?

Since the aim is predicting using the input data, I've tried to use the second approach in the link below, (passing the data as an argument), however I haven't found the way of doing it (I'm honestly new in Node-red and python).

I've been experimenting, trying to output the parameters from the server @10sec to a txt file and then feed the python-shell-node (copied image of that part of the flow), but I just cannot find the way of doing this very simple example below:

> import sys
> print 'Hello ' + sys.argv[1]

I copy below part of the script that I believe, needs to be solved with the nodes:

class Emodel:
    def __init__(
        self
    ):
	
	    self.model_pred = lgbm.Booster(model_file = config.MODEL_PRED)

   def return_predictions(
        self,
        altitude=None,
        ibn=None,
        idh=None,
        azimuth=None,
    ):
         #set vector values
        X[:,0] = altitude
        X[:,1] = ibn
        X[:,2] = idh
        X[:,3] = azimuth_sin
        X[:,4] = azimuth_cos


        pred = self.model_pred.predict(X)
 
        return pred

The output from debug1 is the list of parameters:

azimuth : msg.payload : Object
object
azimuth: 335.99097754452083
Idh: 71
altitude: 0
Ibn: 234
fully_open: 0
blind_angle: 10

Clearly I'm missing one important step, hope someone can give me a hint, thank you!

Miin

Does the python script work directly on the commandline ? If yes, maybe it is easier to execute it using an exec node.

Hi, thank you for your reply, I' tried with the exec node and that brought some other issues, I've tried using pythonshell and sys.argv[1] to pass the arguments, but found some other problems that I'm addressing in a new post.
Pass input parameters to a phytonshell node using sys.argv: IndexError: list index out of range
Thank you so much for your help.

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