Don't execute rule if previous value was NULL

If have a simple rule which sends a mail if an item is changed

rule "Check item"
when
    Item Item_tobe_Checked changed
then
    val mailActions = getActions("mail","mail:smtp:general")
    mailActions.sendMail("xxx@test.com", "item changed", "item changed: " + Item_tobe_Checked.state.toString )
end

But when I eg restart openHAB the item restores it’s value:

Item_tobe_Checked changed from NULL to previous text

How can I change the when part to make the rule not to trigger when changing from NULL ?

You can’t.

But you can add an if() to your rule and see what the previousState implicit variable contains.

1 Like

Thx, I was also thinking of this approach, but I hoped there was another solution. With simple switch items I use ‘changed from on to off’ or ‘changed from off to on’