All rules executed at startup (service openhab restart)

Hi everybody,

I have a question regarding the behavior of the rules at startup.
When I restart openhab (sudo service openhab restart) all the rules are executed while booting up.
This is very funny since all of the lights go totally crazy.

I have only 2 rules that should be executed at “System started”

rule "Reset permissions at startup"
System started
executeCommandLine(“chmod 777 /etc/openhab/configurations/scripts/*”)
logInfo(“Network”, “Resetting permissions on script:\n”)

rule "Update max and min temperatures"
Item Weather_Temperature changed or
Time cron “0 0/5 0 * * ?” or
System started
postUpdate(Weather_Temp_Max, Weather_Temperature.maximumSince(now.withTimeAtStartOfDay).state)
postUpdate(Weather_Temp_Min, Weather_Temperature.minimumSince(now.withTimeAtStartOfDay).state)
logInfo(“Weather”, “Temperature evolved of " + Weather_Temperature.deltaSince(now.minusMinutes(2)) + " degrees.”)

The rest of them should only be executed at other triggers.

rule "Fenster geschlossen"
Item winsens_sleep_Open_Closed received update 0
logInfo(“Fensterbewegung”, “Das Schlafzimmerfenster wurde geschlossen”)
sendCommand(winsens_sleep_timer, OFF)

Any suggestions?


I would change to

Item fenster.state changed from OPEN to CLOSED

i guess your rules get triggered at the startup because your item states get restored from persistence and therefor there is an update in your item

Thanks for the hint. I removed “restoreonstartup” for * Items in the rrd4j and will try again.

(Unfortunately it is a binary window sensor so I can only check for 1 and 0)

No that’s not the right solution in my eyes, you want to restore the last state. You should work on your triggers for the rules:

Example: You restart and your item state is undefined. Now your sensor sends an update lets say every 6 hours and updates the item to CLOSED.

So your rule triggers although the windows was physically closed before

This isn’t a good fix. This is like having a hurt toe so you cut off your foot. Sure you solved the hurt toe but now you have other problems. The correct solution, as @Mpower has said, is to correct your rule triggers.

If it is binary you should use either a Contact Item whose states are OPEN and CLOSED or a Switch whose states are ON and OFF. Do not use a Number Item to store boolean values and do not use the numerical equivalents to OPEN/CLOSED/ON/OFF in your rules, particularly in your rule triggers. Your code will be easier to read, less prone to error and easier for us on the forum to help you with if you follow these conventions.

The main point that @Mpower is trying to get across is that you want your rules to trigger only when winsens_sleep_Open_Closed actually changes, not every time it receives an update indicates that the state of the Item has changed.

This made me laugh a lot !
Thanks for the advice. I got your point. I will rework the rules and the triggers.