regissg
(Régis Saint Girons)
May 23, 2019, 12:59pm
1
I need to increase my device item “Volume” by a specific amount and I was trying to do that directly in the sendCommand:
Volume.sendCommand(Volume.state+5)
But this give me an error "Unknown variable or command ‘+’ "
The workaround is to use a variable
var Number Vol = Volume.state
Vol = Vol + 5
Volume.sendCommand(Vol)
I was wondering if there is a way to have an expression as the sendCommand argument and if yes what will be the proper syntax for my specific problem?
5iver
(Scott Rushworth)
May 23, 2019, 1:05pm
2
Volume.sendCommand(Volume.state as Number + 5)
rossko57
(Rossko57)
May 23, 2019, 1:06pm
3
The rules engines seems to work out what operators are “allowed” from the type of object it is handling, in this case item.state
Note that in your working example, the state is cast to a Number object.
This should do the trick -
Volume.sendCommand( (Volume.state as Number) + 5)
regissg
(Régis Saint Girons)
May 23, 2019, 1:11pm
4
It does work. Thanks to both of you.
Any recommendation where I could find the documentation to address such basic syntax question?
rossko57
(Rossko57)
May 23, 2019, 1:37pm
5
The most useful resource is searching this forum for examples. As well as problem+solution posts like this one, where even the struggles inbetween can be educational, there are useful guides like
Attention: This article is now also available on the openHAB 2 documentation page. If you want to add improvements or additions, please do so there.
http://docs.openhab.org/configuration/rules-dsl.html#conversions
Interacting with Items in rules
A frequent operation in rules is to calculate other values from Item states or compare Item states against other values or perform other operations that are either responses to changes in item states or intended to change the item state. For a complete…
regissg
(Régis Saint Girons)
May 24, 2019, 9:22am
6
Forum is great and I found the xtend documentation that helps as well https://www.eclipse.org/xtend/documentation/203_xtend_expressions.html