Hardware: Running in a LXC Container on a Dell R510 Server
OS: Debian 9 (Stretch)
Java Runtime Environment: openjdk 1.8.0_181
openHAB version: OpenHAB2 2.3.0-1
Issue of the topic:
I have some rules setup to interface with my Radio Thermostat CT50. Right now both the “Set Fan” buttons work. However, they throw an error in the openhab.log.
ERROR
2018-11-18 20:36:05.303 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Set Fan': An error occurred during the script execution: Couldn't invoke 'assignValueTo' for feature JvmVoid: (eProxyURI: ct50dn.rules#|::0.2.3.2.0.1::0::/1)
RULE
rule "Set Fan"
when
Item HVAC_CT50Dn_FanMode received command
then
logInfo("HVAC", "HVAC_CT50Dn_FanMode received: " + receivedCommand)
output = sendHttpPostRequest("http://172.27.4.2/tstat/fmode", "application/json", '{"fmode":' + receivedCommand + '}')
logInfo("HVAC", "HVAC Command sent - output: " + output)
end
There are a number of implicit variables that are made available in a Rule based on how the Rule was triggered. Most of them are documented here. The missing one is now which gives you a DateTime object for right now that you can manipulate (e.g. schedule a Timer for five seconds from now using now.plusSeconds(5).
Now to address your expectation, there are few reasons why it doesn’t work like that.
As Dim posted, the Rule gets triggered on a command BEFORE the Item actually changes state. So, depending on timing, HVAC_CT50_Dn_FanMode.state may still be at the old state inside the Rule for a few dozen milliseconds.
What happens if the Rule can be triggered by a whole bunch of Items receiving a command? How do you know that the receivedCommand is? It would be pretty ugly to have to iterate over all of the Items and call receivedCommand on each one until you find one that has that set. And then what if another Item received a command in the mean time while you were searching? Then you won’t know which one was the command that actually triggered the Rule.
So OH provides this and a set of other similar implicit variables to the Rule when it executes.