I am trying to make dynamic sitemap and have the following configuration:
.items file
String OPPO105 "OPPO 105D" {channel="globalcache:gc100_12:000C1EC016A4:sl-m2#c1"}
Number OPPOSwitchVisability
.rules file:
rule "OPPO Power Visibility"
when
Item OPPO105 received command
then
var OPPOSwitchVisability = 1
println("Point 0 reached, visability state is: " + OPPOSwitchVisability)
println("Point 1 reached")
if(receivedCommand == "OPPO_DICSCR_POWER_ON") {
println("Point 2 reached")
OPPOSwitchVisability = 0
println("Point 3 reached, visability state is: " + OPPOSwitchVisability)
}
println("Point 4 reached, visability state is: " + OPPOSwitchVisability)
end
I have a single switch with “ON” label at the sitemap initiation.
When I push the switch button I expect to have “ON” button to be hidden and “OFF” button shown. But actually nothing happens. The rule works without errors. Below are the records from the Console as a result of println() command in .rules file:
openhab> Point 0 reached, visability state is: 1
Point 1 reached
Point 2 reached
Point 3 reached, visability state is: 0
Point 4 reached, visability state is: 0
I can not understand why it does not work since variable “OPPOSwitchVisability” get the value of “0”, that shall trigger “OFF” switch button to be shown and “ON” button to be hidden, but I do not see it.
Would much appreciate for your guidance and help how to fix this problem and comments where I made a mistake. Thank you in advance.
You have OPPOSwitchVisability declared as Item AND as a variable in your rule. The variable is known to rule only and is lost when the rule is finished, the sitemap however does know the Item, but that one doesn’t change.
I don’t understand what you are trying to do with the mapping, I would do it like this on the sitemap:
Thank you for your help, I reached the desirable result through process of trial and error.
To my mind, the key mistake in my code was that as you mentioned
What I wanted is:
at the initiation I have button “ON” visible
When I click the “ON” button it disappears and the button “OFF” become visible
After I click “OFF” button it disappears and “ON” button become visible again
on and on
Would much appreciate if you can give me a clue why the following code works for the case described above:
rule "OPPO Power Visibility"
when
Item OPPO105 received command
then
if(receivedCommand == "OPPO_DICSCR_POWER_ON") {
OPPOSwitchVisability.postUpdate(0)
}
else {
if(receivedCommand == "OPPO_DICSCR_POWER_OFF"){
OPPOSwitchVisability.postUpdate(1)
}
}
end
and this code does not work:
rule "OPPO Power Visibility"
when
Item OPPO105 received command
then
if(receivedCommand == "OPPO_DICSCR_POWER_ON") {
OPPOSwitchVisability = 0
}
else {
if(receivedCommand == "OPPO_DICSCR_POWER_OFF"){
OPPOSwitchVisability = 1
}
}
end
postUpdate( ) works for item state and equality sign for variables?