How to perform basic maths operations on a NumberItem

I think I am getting something really basic wrong in my rules syntax, but am struggling to find anything in the documentation or forums that are helping me. Please can you shed some light for me?

I have a numberItem called Days_away which is represented in the sitemap with a setpoint. I want to use it to tell the system, when I am away, how many days I will be away for.

The idea is that every day at midnight the Days_away value will be decreased by 1, so on the day I am due to return, the whole house will go back to its lived-in state.

In the rules I have:

var Number New_date = 0
rule "Update days_away at midnight"
when
Item Test_switch changed /* for testing this switch is in place of a cron /
then
if ( Days_away.state > 0 ) {
New_date = Days_away.state-1 /
This is the line that seems to be wrong */
postUpdate(Days_away, New_date)
}
end

But this returns an error in the debug window:

Error during the execution of rule ‘Use the test switch changing in place of a cron’: The name ’ - ’ cannot be resolved to an item or type.

Please can you help me work out what I am doing wrong?

Thanks,

Philip

First, does Days_away have a value or is it undefined? Try logging its state in the rule so you can see. One thing I just learned on another thread is that when an Item that is represented by a setpoint on the Web UI is undefined, the setpoint will not give the Number a value. So you may want to add the following line to the top of your rule:

if(Days_away.state instanceof UnDefType) {
    Days_away.postUpdate(0)
} else if (Days_away.state > 0) {
...

Secondly, assuming it does have a value I think what you have should work but perhaps we need to help it along by telling the rules engine that Days_away is a NumberItem.

New_date = (Days_away.state as DecimalType) - 1

Finally, try using Days_away.postUpdate(New_date) as the postUpdate and sendCommand methods on the Item are smarter about handling different data types than the action methods.