Following your advice I have simplified the rule for testing purposes as follows:
rule "Wind direction & speed" //combine wind speed & wind direction into one item
when
Member of gWind changed
then
var wdir = gWind.members.findFirst[ t | t.name == ("OWM_"+ triggeringItem.name.split("_").get(1) + "_WindDirection") ]
var wspeed = gWind.members.findFirst[ t | t.name == ("OWM_"+ triggeringItem.name.split("_").get(1) + "_WindSpeed") ]
logInfo("TEST", wdir.name.toString + " " + wdir.state.toString)
logInfo("TEST", wspeed.name.toString + " " + wspeed.state.toString)
val test = gOWM.members.findFirst[ t | t.name == ("OWM_"+ triggeringItem.name.split("_").get(1) + "_WindSpeedDirection") ]
logInfo("TEST", test.name.toString + " " + test.state.toString)
// gOWM.members.findFirst[ t | t.name == ("OWM_"+ triggeringItem.name.split("_").get(1) + "_WindSpeedDirection") ].postUpdate((wspeed.state.toString) + " [" + transform("SCALE", "wind.scale", (wdir.state as QuantityType<Number>).doubleValue.toString) +"]")
// gOWM.members.findFirst[ t | t.name == ("OWM_"+ triggeringItem.name.split("_").get(1) + "_WindSpeedDirection") ].postUpdate((wspeed.state.toString.split(".").get(0)) + "km/h [" + transform("SCALE", "wind.scale", (wdir.state as QuantityType<Number>).doubleValue.toString) +"]")
end
gWind
includes OWM_XX_WindSpeed
and OWM_XX_WindDirection
items which can trigger the rule. My assumption is that if both XX items have changed the rule shall be triggered twice providing value for wdir, wspeed, test
for each trigerringItem.
I think that null
error is caused by val test
(searching for item in gOWM group which is bigger). Sometimes OWM_XX_WindSpeedDirection is found/reported only one time despite that both items OWM_XX_WindSpeed and OWM_XX_WindDirection have changed.
For instance (based on logs attached below): OWM_24_WindDirection and OWM_24_WindSpeed Items changed I can see two lines with OWM_24_WindSpeedDirection 10.296 km/h [N] .
However for OWM_48_WindSpeed and OWM_48_WindDirection items changed there is only one line with OWM_48_WindSpeedDirection 12.204 km/h [ESE], then null
error reported.
2020-08-13 09:37:46.742 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_00_WindDirection 250.0 °
2020-08-13 09:37:46.757 [vent.ItemStateChangedEvent] - OWM_00_WindSpeed changed from 3.6 km/h to 7.56 km/h
2020-08-13 09:37:46.765 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_00_WindSpeed 7.56 km/h
2020-08-13 09:37:46.838 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_00_WindDirection 250.0 °
2020-08-13 09:37:46.857 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_00_WindSpeed 7.56 km/h
2020-08-13 09:37:46.890 [vent.ItemStateChangedEvent] - OWM_00_WindDirection changed from 0.0 ° to 250.0 °
2020-08-13 09:37:46.963 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_06_WindDirection 294.0 °
2020-08-13 09:37:46.990 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_06_WindSpeed 2.628 km/h
2020-08-13 09:37:46.997 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Wind direction & speed': null
2020-08-13 09:37:47.110 [vent.ItemStateChangedEvent] - OWM_06_WindSpeed changed from 4.968 km/h to 2.628 km/h
2020-08-13 09:37:47.112 [vent.ItemStateChangedEvent] - OWM_06_WindDirection changed from 284.0 ° to 294.0 °
2020-08-13 09:37:47.120 [vent.ItemStateChangedEvent] - OWM_12_Temperature changed from 22.66 °C to 22.97 °C
2020-08-13 09:37:47.122 [vent.ItemStateChangedEvent] - OWM_12_WindSpeed changed from 11.268 km/h to 11.196 km/h
2020-08-13 09:37:47.129 [vent.ItemStateChangedEvent] - OWM_12_WindDirection changed from 50.0 ° to 53.0 °
2020-08-13 09:37:47.174 [vent.ItemStateChangedEvent] - OWM_24_WindSpeed changed from 8.208 km/h to 9.324 km/h
2020-08-13 09:37:47.177 [vent.ItemStateChangedEvent] - OWM_24_WindDirection changed from 130.0 ° to 122.0 °
2020-08-13 09:37:47.190 [vent.ItemStateChangedEvent] - OWM_48_WindSpeed changed from 12.996 km/h to 11.952 km/h
2020-08-13 09:37:47.193 [vent.ItemStateChangedEvent] - OWM_48_WindDirection changed from 103.0 ° to 122.0 °
2020-08-13 09:37:47.313 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_00_WindSpeedDirection 5.4 km/h [NNW]
2020-08-13 09:37:47.325 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_06_WindDirection 294.0 °
2020-08-13 09:37:47.334 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_06_WindSpeed 2.628 km/h
2020-08-13 09:37:47.489 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_12_WindDirection 53.0 °
2020-08-13 09:37:47.497 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_12_WindSpeed 11.196 km/h
2020-08-13 09:37:47.525 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_06_WindSpeedDirection 9.288 km/h [ESE]
2020-08-13 09:37:47.668 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_06_WindSpeedDirection 9.288 km/h [ESE]
2020-08-13 09:37:47.708 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_12_WindDirection 53.0 °
2020-08-13 09:37:47.714 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_12_WindSpeed 11.196 km/h
2020-08-13 09:37:47.739 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_24_WindDirection 122.0 °
2020-08-13 09:37:47.750 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_24_WindSpeed 9.324 km/h
2020-08-13 09:37:47.850 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Wind direction & speed': null
2020-08-13 09:37:47.890 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_24_WindDirection 122.0 °
2020-08-13 09:37:47.898 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_24_WindSpeed 9.324 km/h
2020-08-13 09:37:48.136 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_12_WindSpeedDirection 4.248 km/h [ESE]
2020-08-13 09:37:48.259 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_24_WindSpeedDirection 10.296 km/h [N]
2020-08-13 09:37:48.268 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_48_WindDirection 122.0 °
2020-08-13 09:37:48.273 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_48_WindSpeed 11.952 km/h
2020-08-13 09:37:48.326 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_24_WindSpeedDirection 10.296 km/h [N]
2020-08-13 09:37:48.361 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_48_WindDirection 122.0 °
2020-08-13 09:37:48.366 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_48_WindSpeed 11.952 km/h
2020-08-13 09:37:48.376 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Wind direction & speed': null
2020-08-13 09:37:48.540 [INFO ] [.eclipse.smarthome.model.script.TEST] - OWM_48_WindSpeedDirection 12.204 km/h [ESE]
So based on the logs there are no second lines for: OWM_00_WindSpeedDirection, OWM_12_WindSpeedDirection and OWM_48_WindSpeedDirection and there 3 null
errors
Seems the null
error is not a specific item related. All items are defined in the same way and the error is random. I mean in the attached log there is one line only with OWM_00_WindSpeedDirection (the second line I assume is the error), but in the other logs (another time) OWM_00_WindSpeedDirection has two lines.
Seems like an instance of rule tries to find an item (in a bigger group) and the same time another instance of this rule tries to find the same item and there is some sort a conflict in accessing/find and assign the same item?