How to increment a counter

General HouseBot discussion. Any issues that don't fit into any of the other topics belong here.
Post Reply
HeinrichH
Member
Posts: 21
Joined: Mon Jan 12, 2009 4:40 am

How to increment a counter

Post 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?
ScottBot
Site Admin
Posts: 2790
Joined: Thu Feb 13, 2003 6:46 pm
Location: Georgia (USA)
Contact:

Re: How to increment a counter

Post 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)
Scott
HeinrichH
Member
Posts: 21
Joined: Mon Jan 12, 2009 4:40 am

Re: How to increment a counter

Post 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?
HeinrichH
Member
Posts: 21
Joined: Mon Jan 12, 2009 4:40 am

Re: How to increment a counter

Post 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.
Attachments
It's working with 2 varibles
It's working with 2 varibles
Counter task.jpg (18.85 KiB) Viewed 2892 times
raptor_demon
Senior Member
Posts: 141
Joined: Tue Jul 07, 2009 12:55 pm
Location: NC

Re: How to increment a counter

Post 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
ScottBot
Site Admin
Posts: 2790
Joined: Thu Feb 13, 2003 6:46 pm
Location: Georgia (USA)
Contact:

Re: How to increment a counter

Post 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.
Scott
Post Reply