Page 1 of 1

How to increment a counter

Posted: Mon Feb 23, 2009 6:12 am
by HeinrichH
I want to keep track of the state changes of some devices. I created a "null device" with a property "general count" and I wat that this property is incremeted by 1 when the monitored device changes the state, therefore I'm trying to created a task to change the property of general count by +1 but it does not work. I've tried several expressions as +=1, =+1 and so on.
What do I have to do to increment the counter property?

Re: How to increment a counter

Posted: Mon Feb 23, 2009 8:58 am
by ScottBot
That's a good question. I can be done from a script, and easily from a SWRemote with the +=1 notation, but directly from a Task is not as easy. I suppose it's just a huge oversight, but you can't just use +=1.

To do it from a Task, you will need to use Property Value substitution and an extra Property, since you can't assign a property to itself in any way using PV substitution. So the logic would go something like:
  • Change TempNumericProperty (new Property that you must add) to PropertyYouWantToInc (this is done with PV substitution)
  • Change PropertyYouWantToInc to TempNumericProperty+1 (again, done with PV substitution)

Re: How to increment a counter

Posted: Mon Feb 23, 2009 9:50 am
by HeinrichH
Thanks for the answer, I am going to try this but in my opinion a counter device is a must for a automation program because you want to keep track of devices.
I am switching a couple of air dryers on and of based on the humidity and the temperature off the rooms and I want to see how many times the are switched on and off in a month or so.

Maybe a counter device as a new device in HouseBot?

Re: How to increment a counter

Posted: Mon Feb 23, 2009 10:38 am
by HeinrichH
With PV substitutions it works, see attached screenshot.
Every time the state is changing to off the switch counter property is incrementing by 1.

Re: How to increment a counter

Posted: Wed Feb 17, 2010 1:51 pm
by raptor_demon
Hi Scott,

Is there any plan to add this into the task so we don't have to create extra variables each time?

Thanks

Raptor

Re: How to increment a counter

Posted: Sun Feb 21, 2010 12:54 pm
by ScottBot
Not currently. However, if it is important to you and you think others would value the feature, please add it to the feature request list.