Avoid two consecutive item state changes or executions of rules

This is a typical debounce behavior. When the state changes you want to ignore all subsequent state changes for a given amount of time. Correct?

If so you don’t need to implement this yourself. Install the Debounce rule template from Settings → Automation → Rule Templates, and instantiate and configure a rule based on the template.

The template requires a debounce Group that all your “raw” Items belong to. Each raw Item has a proxy Item. Each raw Item also has metadata that points to the proxy Item and defines the behavior of the debounce (e.g. how long, whether to only debounce certain states, debounce changes and updates, etc.).

The rule template will only update the proxy Item for state updates or changes that occur the configured amount of time after the last update or change.

Everything else in OH uses the proxy Item.

It’s a complicated problem and it can be tough to get right so why code it if you don’t have to?

If you do want to code it yourself, you can at least look at how I did it for inspiration. Note that a little more than half of the code is error checking to generate meaningful error messages. Don’t be intimidated by it’s length.