Light control on switch - generate loop

Raspberry Pi 4 4gb
openhabian 1.7
openhab 3.4.4

Hi to everyone,

I’ve written a rules with blockly to control my 2x lamps (upstairs and corridor) with 3x QuadWallmote from Aeotec.
The rule goes for some times… and from 2 days it enter in an infinite loop that full all the CPU.
Result I must reboot the system…

Here the code:

if (itemRegistry.getItem('Node_011_WallMote_Quad_PT_Salotto_Scene_Number').getState() == '1.0' && itemRegistry.getItem('ZWaveNode003FGS224FibaroDoubleSmartModule_Switch1').getState() == 'OFF') {
  events.sendCommand('ZWaveNode003FGS224FibaroDoubleSmartModule_Switch1', 'ON');
} else if (itemRegistry.getItem('Node_011_WallMote_Quad_PT_Salotto_Scene_Number').getState() == '1.0' && itemRegistry.getItem('ZWaveNode003FGS224FibaroDoubleSmartModule_Switch1').getState() == 'ON') {
  events.sendCommand('ZWaveNode003FGS224FibaroDoubleSmartModule_Switch1', 'OFF');
}
if (itemRegistry.getItem('Node_011_WallMote_Quad_PT_Salotto_Scene_Number').getState() == '2.0' && itemRegistry.getItem('ZWaveNode009FGS224FibaroDoubleSmartModule_Switch1').getState() == 'OFF') {
  events.sendCommand('ZWaveNode009FGS224FibaroDoubleSmartModule_Switch1', 'ON');
} else if (itemRegistry.getItem('Node_011_WallMote_Quad_PT_Salotto_Scene_Number').getState() == '2.0' && itemRegistry.getItem('ZWaveNode009FGS224FibaroDoubleSmartModule_Switch1').getState() == 'ON') {
  events.sendCommand('ZWaveNode009FGS224FibaroDoubleSmartModule_Switch1', 'OFF');
}
if (itemRegistry.getItem('ZWave_Node_012_WallMote_Quad_PT_Entrata_Scene_Number').getState() == '1.0' && itemRegistry.getItem('ZWaveNode003FGS224FibaroDoubleSmartModule_Switch1').getState() == 'OFF') {
  events.sendCommand('ZWaveNode003FGS224FibaroDoubleSmartModule_Switch1', 'ON');
} else if (itemRegistry.getItem('ZWave_Node_012_WallMote_Quad_PT_Entrata_Scene_Number').getState() == '1.0' && itemRegistry.getItem('ZWaveNode003FGS224FibaroDoubleSmartModule_Switch1').getState() == 'ON') {
  events.sendCommand('ZWaveNode003FGS224FibaroDoubleSmartModule_Switch1', 'OFF');
}
if (itemRegistry.getItem('ZWave_Node_012_WallMote_Quad_PT_Entrata_Scene_Number').getState() == '2.0' && itemRegistry.getItem('ZWaveNode009FGS224FibaroDoubleSmartModule_Switch1').getState() == 'OFF') {
  events.sendCommand('ZWaveNode009FGS224FibaroDoubleSmartModule_Switch1', 'ON');
} else if (itemRegistry.getItem('ZWave_Node_012_WallMote_Quad_PT_Entrata_Scene_Number').getState() == '2.0' && itemRegistry.getItem('ZWaveNode009FGS224FibaroDoubleSmartModule_Switch1').getState() == 'ON') {
  events.sendCommand('ZWaveNode009FGS224FibaroDoubleSmartModule_Switch1', 'OFF');
}
if (itemRegistry.getItem('ZWave_Node_013_WallMote_Quad_1P_Corridoio_Scene_Number').getState() == '1.0' && itemRegistry.getItem('ZWaveNode003FGS224FibaroDoubleSmartModule_Switch1').getState() == 'OFF') {
  events.sendCommand('ZWaveNode003FGS224FibaroDoubleSmartModule_Switch1', 'ON');
} else if (itemRegistry.getItem('ZWave_Node_013_WallMote_Quad_1P_Corridoio_Scene_Number').getState() == '1.0' && itemRegistry.getItem('ZWaveNode003FGS224FibaroDoubleSmartModule_Switch1').getState() == 'ON') {
  events.sendCommand('ZWaveNode003FGS224FibaroDoubleSmartModule_Switch1', 'OFF');
}
// Quando il tasto N13 viene premuto, verifica lo
// stato dello switch al 1P e commuta di conseguenza
if (itemRegistry.getItem('ZWave_Node_013_WallMote_Quad_1P_Corridoio_Scene_Number').getState() == '2.0' && itemRegistry.getItem('ZWaveNode009FGS224FibaroDoubleSmartModule_Switch1').getState() == 'OFF') {
  events.sendCommand('ZWaveNode009FGS224FibaroDoubleSmartModule_Switch1', 'ON');
} else if (itemRegistry.getItem('ZWave_Node_013_WallMote_Quad_1P_Corridoio_Scene_Number').getState() == '2.0' && itemRegistry.getItem('ZWaveNode009FGS224FibaroDoubleSmartModule_Switch1').getState() == 'ON') {
  events.sendCommand('ZWaveNode009FGS224FibaroDoubleSmartModule_Switch1', 'OFF');
}
events.sendCommand('Node_011_WallMote_Quad_PT_Salotto_Scene_Number', '6.0');
events.sendCommand('ZWave_Node_012_WallMote_Quad_PT_Entrata_Scene_Number', '6.0');
events.sendCommand('ZWave_Node_013_WallMote_Quad_1P_Corridoio_Scene_Number', '6.0');

the blockly rules “simply” check if the light is “on” or “off” and check the scene (number from 1.0 to 4.0) from the Wallmotes.
After that if is On then off, and if is Off then On.

that for 2x Switch and 3x Wallmotes.

After All, I change the Scene number to 6.0 to not have problems in another Run of the rule.

But, because there always a “but”… this is the result from the front tail:

2023-11-14 20:53:15.844 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item ‘Node_011_WallMote_Quad_PT_Salotto_Scene_Number’ predicted to become 6.0
2023-11-14 20:53:15.849 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘ZWave_Node_012_WallMote_Quad_PT_Entrata_Scene_Number’ received command 6.0
2023-11-14 20:53:15.851 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘ZWave_Node_013_WallMote_Quad_1P_Corridoio_Scene_Number’ received command 6.0
2023-11-14 20:53:15.852 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item ‘ZWave_Node_012_WallMote_Quad_PT_Entrata_Scene_Number’ predicted to become 6.0
2023-11-14 20:53:15.857 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘Node_011_WallMote_Quad_PT_Salotto_Scene_Number’ received command 6.0
2023-11-14 20:53:15.858 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item ‘ZWave_Node_013_WallMote_Quad_1P_Corridoio_Scene_Number’ predicted to become 6.0
2023-11-14 20:53:15.862 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘ZWave_Node_012_WallMote_Quad_PT_Entrata_Scene_Number’ received command 6.0
2023-11-14 20:53:15.864 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘ZWave_Node_013_WallMote_Quad_1P_Corridoio_Scene_Number’ received command 6.0
2023-11-14 20:53:15.866 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘Node_011_WallMote_Quad_PT_Salotto_Scene_Number’ received command 6.0
2023-11-14 20:53:15.869 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘ZWave_Node_012_WallMote_Quad_PT_Entrata_Scene_Number’ received command 6.0
2023-11-14 20:53:15.871 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘ZWave_Node_013_WallMote_Quad_1P_Corridoio_Scene_Number’ received command 6.0
2023-11-14 20:53:15.872 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘Node_011_WallMote_Quad_PT_Salotto_Scene_Number’ received command 6.0
2023-11-14 20:53:15.878 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘ZWave_Node_012_WallMote_Quad_PT_Entrata_Scene_Number’ received command 6.0
2023-11-14 20:53:15.880 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘ZWave_Node_013_WallMote_Quad_1P_Corridoio_Scene_Number’ received command 6.0
2023-11-14 20:53:15.880 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item ‘Node_011_WallMote_Quad_PT_Salotto_Scene_Number’ predicted to become 6.0
2023-11-14 20:53:15.883 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘Node_011_WallMote_Quad_PT_Salotto_Scene_Number’ received command 6.0
2023-11-14 20:53:15.885 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘ZWave_Node_012_WallMote_Quad_PT_Entrata_Scene_Number’ received command 6.0
2023-11-14 20:53:15.886 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘ZWave_Node_013_WallMote_Quad_1P_Corridoio_Scene_Number’ received command 6.0
2023-11-14 20:53:15.886 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item ‘ZWave_Node_012_WallMote_Quad_PT_Entrata_Scene_Number’ predicted to become 6.0
2023-11-14 20:53:15.888 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item ‘ZWave_Node_013_WallMote_Quad_1P_Corridoio_Scene_Number’ predicted to become 6.0

Some One as an Explanation?

thank you a lot.
bye
Xander

This is the cause of the issue. When you send the command to your scene items, it results in an update to those items which triggers the rule again, which sends the command again, which results in an update, which triggers the rule again…

There are a couple of easy ways to resolve this. 1) This is an excellent candidate for the rule conditions. You do not want the blockly script to run unless the new state of the item that has changed is not 6.0. This is what conditions do. They allow you to check something and if that check is false, the rule actions never even get run. 2) You could do this in the rule as well. You can always check before you run any of the other code in the rule that your updated value is not 6.0 and then run the other parts of the rule.

The last way to fix this is a little more complicated and one that we can’t help with without seeing more information: you say the wallmote has to be 6.0 to not interfere with another rule. Well, that seems a little strange. You could try to refactor that other rule so that you don’t have this collision, then you don’t have to worry about resetting the wallmote values to 6.0 when you are done with this rule at all.

1 Like

Thank you @JustinG.

this was the problem.
I will re-write the rule just for have a clean setup, but my loop was really the update of the scene…
after the entry of the condition i’ve cheked and the loop is gone.
Good work!