Call a python script from rule with additional parameter

I need to set battery current on a battery solar inverter with different charging current setpoint values.
items

Switch IBAT             "I BAT" <battery> (Studer) {autoupdate="false"}
Number IBAT_SW          "I BAT SW [%.0f A]" <batterylevel> (Studer)

influx presistence memorize current setpoint value

IBAT_SW : strategy = everyChange, everyUpdate

sitemaps

Switch item=IBAT label="I BAT SET" mappings=[ON="SET"] visibility=[IBAT==OFF]
Setpoint item=IBAT_SW minValue=2.0 maxValue=50.0 step=1.0

rules

rule "IBAT set"
    when
        Item IBAT received command ON
    then
        executeCommandLine("python@@/etc/openhab2/scripts/ibatset.py")
end

This executes python script once switch IBAT has been pressed, but without transfer of setpoint value to the batset.py script.

How can be transfered also script parameter value together with script calling ?
Solution with lot of scripts with different SW values is posssible, but terrible.
Thanks.

Is possible to transfer parameter to python as item.value or state ?

executeCommandLine("python@@/etc/openhab2/scripts/ibatset.py IBAT_SW.value")
or
executeCommandLine("python@@/etc/openhab2/scripts/ibatset.py IBAT_SW.state")

Is this a way ?

pip install python-openhab

parse item from
http://localhost:8080/rest/items

Is possible to transfer parameter to python as item.value or state ?

executeCommandLine("python /etc/openhab2/scripts/ibatset.py " + IBAT_SW.state)
1 Like

Thanks, can i print item IBAT_SW in python script as

#!/usr/bin/python
f = open("/etc/openhab2/scripts/demofile.txt", "a")
f.write(IBAT_SW.state)
or 
f.write(IBAT_SW.value)

can i print item IBAT_SW in python script as

No, they need to be handled as command line parameters in python side. See more details from Python - Command-Line Arguments

Thanks, all OK