I was wondering if there was an easy way to count the total number of devices that are on using a virtual device. For example, have a virtual device that counts the total number of devices that are on from a group of devices. I looked at the counter option in HS but it does not look like it would work. I'm just looking to have a virtual device show the total number of lights on at any given time.
Announcement
Collapse
No announcement yet.
Counting Multiple Device Value Statuses
Collapse
X
-
You could certainly use a counter. Create an event that adds 1 to the counter any time any of your devices are turned on and another that subtracts 1 any time one of them is turned off. Then use a simple script to update your virtual device every time the counter changes. I can't help you with the script specifically but I can show you a script that I use to update a virtual device with the value of a counter if you'd like.Originally posted by rpradeThere is no rhyme or reason to the anarchy a defective Z-Wave device can cause
-
Originally posted by S-F View PostYou could certainly use a counter. Create an event that adds 1 to the counter any time any of your devices are turned on and another that subtracts 1 any time one of them is turned off. Then use a simple script to update your virtual device every time the counter changes. I can't help you with the script specifically but I can show you a script that I use to update a virtual device with the value of a counter if you'd like.
Comment
-
Originally posted by bmora View PostSure that be great! Maybe if I see the script it may make sense...Originally posted by rpradeThere is no rhyme or reason to the anarchy a defective Z-Wave device can cause
Comment
-
I am not sure a counter would work out in the long run. I can see it getting out of sync with the real world device status's and when it does the only way to clean it up is to poll all the devices and get their current status. This is something I need to do as well but I simply haven't had the time to work on it yet. I suspect it will require a script to enumerate the devices in HS and get the status of the ones I care about. I don't think the script will be too difficult to write I just have higher priorities at the moment . I am surprised someone hasn't already done this and shared the script as it seems like a common task many people would need at one point or another. In any case this will probably get you started.
http://homeseer.com/support/homeseer...enumerator.htm
Comment
-
This would run through a list of specified device references and count the number that had their CAPI labels as 'On', 'on', 'ON' etc. You would fill the top line with as many device references as you wanted and where the writelog entry is then you could set another devices value from this line.
Code:Dim DeviceList() As Integer = {197, 101, 87} Dim CurrentStatus As CAPIStatus Dim NumberOfOnDevices As Integer = 0 Sub Main(Parm As Object) For Each DevRef As Integer In DeviceList CurrentStatus = hs.CAPIGetStatus(DevRef) If CurrentStatus.Status.ToLower = "on" Then NumberOfOnDevices += 1 Next hs.writelog("OnCount", "I Count " & NumberOfOnDevices & " devices as having the CAPI status of 'On'") End Sub
Comment
-
Originally posted by mrhappy View PostThis would run through a list of specified device references and count the number that had their CAPI labels as 'On', 'on', 'ON' etc. You would fill the top line with as many device references as you wanted and where the writelog entry is then you could set another devices value from this line.
Code:Dim DeviceList() As Integer = {197, 101, 87} Dim CurrentStatus As CAPIStatus Dim NumberOfOnDevices As Integer = 0 Sub Main(Parm As Object) For Each DevRef As Integer In DeviceList CurrentStatus = hs.CAPIGetStatus(DevRef) If CurrentStatus.Status.ToLower = "on" Then NumberOfOnDevices += 1 Next hs.writelog("OnCount", "I Count " & NumberOfOnDevices & " devices as having the CAPI status of 'On'") End Sub
I just gave this a try and it seems to work with one exception. If you run it again, it's incrementing the count from the last number, rather from zero.
e.g. I have 10 devices defined in the list and 3 are On. I run it the first time and it gives me a log print of 3 devices On. I run it a second time (with same devices set to On) and it prints 6 devices are On etc etc.
I also modified this line:
If CurrentStatus.Status.ToLower = "on" Then NumberOfOnDevices += 1
to be:
If CurrentStatus.Status.ToLower <> "off" Then NumberOfOnDevices += 1
which then works for dimming devices.
Any idea on the incrementing?
Cheers
Jamescheeryfool
Comment
-
Originally posted by cheeryfool View PostAdam
I just gave this a try and it seems to work with one exception. If you run it again, it's incrementing the count from the last number, rather from zero.
e.g. I have 10 devices defined in the list and 3 are On. I run it the first time and it gives me a log print of 3 devices On. I run it a second time (with same devices set to On) and it prints 6 devices are On etc etc.
I also modified this line:
If CurrentStatus.Status.ToLower = "on" Then NumberOfOnDevices += 1
to be:
If CurrentStatus.Status.ToLower <> "off" Then NumberOfOnDevices += 1
which then works for dimming devices.
Any idea on the incrementing?
Cheers
James
NumberOfOnDevices = 0
to just below the hs.writelog entry and that should reset the counter for the next run of the script...yes you can do that for everything else than off which is akin to the event action of not equal to xxxx status.
Comment
-
Originally posted by mrhappy View PostDidn't expect that for an error, thought that the script died when it finished, guess not. You should be able to add
NumberOfOnDevices = 0
to just below the hs.writelog entry and that should reset the counter for the next run of the script...yes you can do that for everything else than off which is akin to the event action of not equal to xxxx status.
Thankscheeryfool
Comment
-
Guest
Originally posted by cheeryfool View PostAdam
I just gave this a try and it seems to work with one exception. If you run it again, it's incrementing the count from the last number, rather from zero.
e.g. I have 10 devices defined in the list and 3 are On. I run it the first time and it gives me a log print of 3 devices On. I run it a second time (with same devices set to On) and it prints 6 devices are On etc etc.
I am running into this same issue when trying to do something similar (checking for open windows). Every time I run the script, NumberOfOnDevices keeps increasing in the log.
Can anyone explain how this variable seems to be persistent? All references to the variables should be destroyed when the script is finished but that does not seem to be the case. Even if they stayed around I would think a new run of the script would clear them out.
Here is the script:
Code:Dim DeviceList() As Integer = {167, 168, 169, 170, 171, 172} Dim CurrentStatus As CAPIStatus Dim NumberOfOnDevices As Integer = 0 Sub Main(Parm As Object) For Each DevRef As Integer In DeviceList CurrentStatus = hs.CAPIGetStatus(DevRef) If CurrentStatus.Status.ToLower = "violated" Then NumberOfOnDevices += 1 Next hs.writelog("OnCount", "I Count " & NumberOfOnDevices & " as open") End Sub
Jun-28 11:27:04 AM Event Running script and waiting: /usr/local/HomeSeer/scripts/CountWindowOpen.vb
Jun-28 11:27:04 AM Event Event Trigger "WHF Check for Open Windows"
Jun-28 11:27:04 AM Event Event WHF Check for Open Windows triggered by the event page 'Run' button.
Jun-28 11:23:53 AM OnCount I Count 20 as open
Jun-28 11:23:53 AM Event Running script and waiting: /usr/local/HomeSeer/scripts/CountWindowOpen.vb
Jun-28 11:23:53 AM Event Event Trigger "WHF Check for Open Windows"
Jun-28 11:23:53 AM Event Event WHF Check for Open Windows triggered by the event page 'Run' button.
Jun-28 11:22:07 AM OnCount I Count 16 as open
Jun-28 11:22:07 AM Event Running script and waiting: /usr/local/HomeSeer/scripts/CountWindowOpen.vb
Jun-28 11:22:07 AM Event Event Trigger "WHF Check for Open Windows"
Jun-28 11:22:07 AM Event Event WHF Check for Open Windows triggered by the event page 'Run' button.
Jun-28 11:21:34 AM OnCount I Count 12 as open
Jun-28 11:21:34 AM Event Running script and waiting: /usr/local/HomeSeer/scripts/CountWindowOpen.vb
Jun-28 11:21:34 AM Event Event Trigger "WHF Check for Open Windows"
Jun-28 11:21:34 AM Event Event WHF Check for Open Windows triggered by the event page 'Run' button.
Jun-28 11:21:13 AM OnCount I Count 8 as open
Jun-28 11:21:13 AM Event Running script and waiting: /usr/local/HomeSeer/scripts/CountWindowOpen.vb
Jun-28 11:21:13 AM Event Event Trigger "WHF Check for Open Windows"
Jun-28 11:21:13 AM Event Event WHF Check for Open Windows triggered by the event page 'Run' button.
Jun-28 11:20:58 AM OnCount I Count 4 as open
Thanks,
Howie
Comment
Comment