I try to create a rule that goes to next scene each time the button is pressed. But do not understand what is wrong. The fisrt rule Light_Scene_Bathroom works fine its going up and down. But the rule “Scene_Badkamer” is not working it does nothing.
Items configuration
//Scene
Number Light_Scene_Bathkamer//voor de woonkamer Scene
Rules code related to the issue
rule "Badkamer kleur +1"
when
Item GF_Bathroom_Schakelaar_BovenL received update ON
then
Light_Scene_Bathkamer.sendCommand((Light_Scene_Bathkamer.state as Number) + 1)
end
rule "Badkamer kleur -1"
when
Item GF_Bathroom_Schakelaar_BovenL received update OFF
then
Light_Scene_Bathkamer.sendCommand((Light_Scene_Bathkamer.state as Number) - 1)
end
rule "Scene_Badkamer"
when
Item Light_Scene_Bathkamer received command
then
switch rreceivedCommand{
case 0:{
GF_Bathroom_Light_spiegelled_Dimmer.sendCommand(0)
}
case 1:{
GF_Bathroom_Light_spiegelled_Dimmer.sendCommand(10)
}
case 2:{
GF_Bathroom_Light_spiegelled_Dimmer.sendCommand(50)
}
}
end
that’s stupid i use VSCode … I looked at the log did not see anything … Sorry stuput. How can i make the rule that if Light_Scene_Bathroom goes higher than 2 it goes back to 0
Edit
Was easier than I thought. Is this is a good way?
rule "Badkamer kleur +1"
when
Item GF_Bathroom_Schakelaar_BovenL received update
then
if (GF_Bathroom_Schakelaar_BovenL.state == ON && Light_Scene_Bathkamer.state == 3) {
Light_Scene_Bathkamer.sendCommand(0)
}
if (GF_Bathroom_Schakelaar_BovenL.state == ON && Light_Scene_Bathkamer.state < 3) {
Light_Scene_Bathkamer.sendCommand((Light_Scene_Bathkamer.state as Number) + 1)
}
if (GF_Bathroom_Schakelaar_BovenL.state == OFF && Light_Scene_Bathkamer.state == 0) {
Light_Scene_Bathkamer.sendCommand(3)
}
if (GF_Bathroom_Schakelaar_BovenL.state == OFF && Light_Scene_Bathkamer.state > 0) {
Light_Scene_Bathkamer.sendCommand((Light_Scene_Bathkamer.state as Number) - 1)
}
end
If it works it’s probably a good way. There are some ways to simplify.
rule "Badkamer kleur +1"
when
Item GF_Bathroom_Schakelaar_BovenL received update
then
val direction = if(GF_Bathroom_Schakelaar_BovenL.state == ON) 1 else -1 // if ON increase, if OFF decrease
// % is the mod operator, returns the remainder after dividing
val next = (Light_Scene_Bathkamer.state + direction) % 3
Light_Scene_Bathkamer.sendCommand(next)
end