Keep 'when Item received update' rules from running during RestoreOnStartup

Actually, the last sendCommand should not send NULL.
Instead one should use “” (emtpy string) or 0 or some other value depending on the item type.
NULL should be only on system startup :smile:

Not necessarily. For example, I use the expire binding to set Items back to NULL when the sensor has not reported in a long time. This tells me that the sensor is not functional and therefore whatever it is sensing is in an unknown state and I write my rules accordingly.

You are right one would not want to sendCommand NULL but it is perfectly reasonable to postUpdate(NULL) or let Expire do it for you.

I also implemented the “previousState != NULL” trick to prevent rules from triggering with RestoreOnStartup but the use of the implicit variable previousState is generating an error:

Rule 'Scene CMD_mCR_command': An error occurred during the script execution: index=0, size=0

Below is the rule:

rule "Scene CMD_mCR_command"
    Item CMD_mCR_command received update 15 //triple-click
    if(previousState != NULL){

When replacing by CMD_mCR_command.previousState().state it works but this is not what I need.
Any idea?

previousState only exists when a Rule is triggered by a changed trigger.

There is no way I know of to determine if an Item’s previous state was NULL with any other Rule trigger.

Thank you! I should read the doc with more concentration :roll_eyes:

I applied a workaround with a global boolean variable that is set to true when the rule is first triggered at startup (due to RestoreOnStartup behavior).

var my_item_initialized = new Boolean(false)

rule "Rule that must not be triggered during RestoreOnStartup"
	Item MyItem_WithRestoreOnStartup received update
		//code that must be executed only after RestoreOnStartup is completed
		my_item_initialized = true