Subtract from counter

Hi All,

I’ve taken the below snippet found from the rules example on

// increase the counter at midnight
rule "Increase counter"
	Time cron "0 0 0 * * ?"
	counter = counter + 1

What I’d like to do is the opposite and actually subtract one from the counter instead so that it can be used as a “days until” counter.

Can anyone help?


Umm, counter = counter - 1 isn’t working?

1 Like

Hmm that’s really weird, I had tried that several times and couldn’t get a success with it so I assumed there was an error with the syntax…

I’ve tried it once again before responding and it has worked?! :laughing:

Whilst you are here, would you know how to reset the counter once it has reached 0?

I would think something along the lines of if (counter == 0) { do whatever you want …?