I’ve got rule which executes python script to get data from solar inverter. It was working fine in OH3.0 but it doesn’t work anymore since upgrading to latest stable version OH3.1.0.
rule “solar inverter”
when
Time cron “0 0/5 * 1/1 * ? *”
then
if(solarman.state == ON) {
var String invdata = executeCommandLine(Duration.ofSeconds(10),"/usr/bin/python", “/var/lib/openhab/INVT-inverter/getPVData.py”)
invtstring.postUpdate(invdata)
val data1 = invtstring.state.toString.split("\n").get(0)
invttot.postUpdate(data1) //worked with OH 3.0
val data2 = invtstring.state.toString.split("\n").get(1)
invtday.postUpdate(data2)
val data3 = invtstring.state.toString.split("\n").get(2)
invtcurrent.postUpdate(data3)
logInfo(“results”, data1)
}
end
Below are errors from openhab log
2021-12-08 7:19:31.689 [WARN ] [b.core.model.script.actions.BusEvent] - Cannot convert ‘12471.4’ to a state type which item ‘invttot’ accepts: [DecimalType, QuantityType, UnDefType].
2021-12-08 7:19:31.692 [WARN ] [b.core.model.script.actions.BusEvent] - Cannot convert ‘12.66’ to a state type which item ‘invtday’ accepts: [DecimalType, QuantityType, UnDefType].
2021-12-08 7:19:31.694 [WARN ] [b.core.model.script.actions.BusEvent] - Cannot convert ‘3170’ to a state type which item ‘invtcurrent’ accepts: [DecimalType, QuantityType, UnDefType].
2021-12-08 7:19:31.695 [INFO ] [rg.openhab.core.model.script.results] - 12471.4
Items config
String invtstring
Number invttot “inverter total [%.1f]”
Number invtday “inverter daily [%.1f]”
Number invtcurrent “inverter current power [%.1f]”
It seems that the python script executes ok but there is an issue with updating number items? Any idea how to resolve it?
Interesting that you were able to switch the font to courier. But as you can see that’s not really helpful as all the white space is lost. When posting code and logs and the like please use code fences.
```
code goes here
```
You can also use the icons at the top of the post entry form.
thanks, I changed rule as per your advice but I receive same warning as before
rule "solar inverter"
when
Time cron "0 0/5 * 1/1 * ? *"
then
if(solarman.state == ON) {
var String invdata = executeCommandLine(Duration.ofSeconds(10),"/usr/bin/python", "/var/lib/openhab/INVT-inverter/getPVData.py")
invtstring.postUpdate(invdata)
val data1 = invtstring.state.toString.split("\n").get(0)
postUpdate(invttot, data1)
val data2 = invtstring.state.toString.split("\n").get(1)
// invtday.postUpdate(data2)
val data3 = invtstring.state.toString.split("\n").get(2)
// invtcurrent.postUpdate(data3)
// logInfo("results", data1)
}
end
2021-12-09 6:58:00.644 [WARN ] [b.core.model.script.actions.BusEvent] - Cannot convert '12494.7
' to a state type which item 'invttot' accepts: [DecimalType, QuantityType, UnDefType].
Only thing I can think of, you’ve got some invisible control characters in your strings.
Try postUpdate("invttot", "3.142")
to prove stuff works.
Try logInfo("test", "Chars " + data1.length)
for character count.