I have an arduino sending MQTT messages to OpenHAB. A rule responds to messages by doing things like “turn the light up” or “turn the volume down” etc.
The rule stores the current light level into a variable, increments the variable, then sends the command.
However when I remove persistence data (e.g. upgrade OH) the rule doesn’t trigger at all, no error shown on console. I can get the rule to trigger again by removing line 5 of the below:
rule "ArduinoBedroomVector"
when
Item Bedroomvector received update
then
var Number lightcircuit1level = BedroomLights.members.get(0).state as DecimalType
case "light_1_up" : {
lightcircuit1level = lightcircuit1level + 3
if(lightcircuit1level>100) lightcircuit1level = 100
Light_LG_Bedroom_Ceiling.sendCommand(lightcircuit1level); // send command to light
}
end
Of course, this stops the rule working, and it gives an error, but at least I know it triggers.
In order to make the rule work, and allow my light switches to control the light again, I have to go through all lights in the sitemap and “touch” the settings to give them a value, presumably this creates the persistence data.
Can anyone tell me why? And how best to resolve this? I don’t want to set all light levels at startup every time.
I have the workaround, but it happens quite often when I set up new items and change them etc.