I made a device group where I added all my devices that uses power (child named Power or Watts). I would like a virtual device to show the total current power usage. Is this possible and how?
Announcement
Collapse
No announcement yet.
Show the total value of devices in a group to a VD
Collapse
X
-
Originally posted by lasseruud View PostI made a device group where I added all my devices that uses power (child named Power or Watts). I would like a virtual device to show the total current power usage. Is this possible and how?
Sent from my SM-G950U using Tapatalk
-
Yes, it requires some very simple scripting (cut and paste level stuff). I’ll explain with reference to figures from my system, shown below.
First create a counter from the [Tools] -> [Global Variables, Timers and Counters] menu. Let's call it "Total_Watts". In my figures, below, this is device Reference # 551.
I then have several energy readings I want to add together and store in the counter. These energy meters are devices #s 16, 20, 25, 29, 34, 38
In the Events tab, I created a new event which triggers every 15 seconds, when it triggers it runs an “immediate” script. In the script box, I have pasted a “hs.setDevicevaluebyref” script which sets the value of the device 551, the counter, by adding together the values of the 6 energy meters.
You just need to edit this to insert your counter reference #s in place of 551, and to add together your energy meters. You could set the triggers to trigger whenever the energy meters change, but I found that can cause too many events to trigger and found, instead, that a steady 15 second triggering rate worked well for me. The Script you need is along the following lines:
&hs.setdevicevaluebyref( 551, hs.devicevalueex(16) + hs.devicevalueex(20) + hs.devicevalueex(25) + hs.devicevalueex(29) + hs.devicevalueex(34) + hs.devicevalueex(38), True)
Last edited by jvm; November 16, 2018, 08:06 PM.
- Likes 1
Comment
-
You should be able to use Easy Trigger “Set Device to an Expression” using replacement variables. See this post
EDIT: It does work, but the virtual device must be controllable (cannot be Status only). I used a text box for control, but updated the device with the sum of 4 different energy devices via the Easy Trigger Action
Last edited by randy; November 16, 2018, 09:59 PM.HS4 Pro, 4.2.18.3 Windows 10 pro, Supermicro LP Xeon
Comment
-
jvm - your script works like a charm! To make it easier when I add devices, I want to use EasyTriggers Device Group to determine which devices is included. I've added all power devices in a device group and want to use this group to sum all values. I think it's what has done, but I can't figure out what you did. Could you provide a screenshot of your event, please?
Comment
-
lasseruud - I don't think you can use Easy Trigger Device Groups to determine which devices to add together. The Group mechanism doesn't give you a way to access / read the individual devices in the group (though, if you use the group as a trigger, Easy Trigger does allow you to read certain environmental variables that identify which of the devices in the group triggered).
Also, I did notice something odd which I hadn't noticed before.
When you set up the Counter, it creates a corresponding virtual device which you use to store the totaled Watts. I noticed that as you total the watts and store it in the virtual device the Counter does not change. You can even delete the Counter and the virtual device remains and still functions. So, you don't actually need the counter - it is just a convenient way to create the virtual device. A lesson from this is not to use the "Counter" variable directly in any other function as it doesn't actually hold the sum - that's held in the virtual device. To me, this seems like a bug in HomeSeer as I would have expected the Counter and its virtual device to remain in sync.
Comment
-
I'll see if I can help. I created a virtual device with a range of values from 0-10000 with 2 decimal place resolution. I made the range status and control and set a range graphic to match my other devices. As I mentioned above the Easy Trigger "Set Device to Expression will not set a vevice value if the device is status only.
There are 17 wattage measurement devices in my server closet that I wanted to sum, plus the new virtual device
Then I used a simple addition expression to total the 17 devices. You cannot use an Easy Trigger group to sum values, so each replacement variable must be entered. The string is thisCode:$$DVR:4889:+$$DVR:4887:+$$DVR:4885:+$$DVR:4882:+$$DVR:4879:+$$DVR:4876:+$$DVR:5068:+$$DVR:5066:+$$DVR:5064:+$$DVR:5061:+$$DVR:5058:+$$DVR:5044:+$$DVR:176:+$$DVR:172:+$$DVR:169:+$$DVR:165:+$$DVR:162
There is a bug in how HS handles such a long string when collapsed, which I will let Spud and Rich know about, but the Event functions well.
The immediate script that jvm posted is just as easy and would allow you to set the device as status only.
HS4 Pro, 4.2.18.3 Windows 10 pro, Supermicro LP Xeon
- Likes 1
Comment
-
Here is the same result using an immediate script. I was able to make the device status only.
Code:&hs.setdevicevaluebyref( 391, hs.devicevalueex(4889) + hs.devicevalueex(4887) + hs.devicevalueex(4885) + hs.devicevalueex(4882) + hs.devicevalueex(4879) + hs.devicevalueex(4876) + hs.devicevalueex(5068) + hs.devicevalueex(5066) + hs.devicevalueex(5064) + hs.devicevalueex(5061) + hs.devicevalueex(5058) + hs.devicevalueex(5044) + hs.devicevalueex(176) + hs.devicevalueex(172) + hs.devicevalueex(169) + hs.devicevalueex(165) + hs.devicevalueex(162) , True)
HS4 Pro, 4.2.18.3 Windows 10 pro, Supermicro LP Xeon
- Likes 1
Comment
-
I will see if I can put in a fix. The problem is that there are no spaces in your string so the html does not wrap. I should be able to force a wrap with some CSS.
An easy fix on your end is to add some spaces. I suspect the EasyTrigger plugin is not going to mind if you put a space in front of the "+". Then is will wrap ok.
You can force the same issue if you create a simple speak action then enter text without spaces, you see the same problem.
Originally posted by rprade View PostI'll see if I can help. I created a virtual device with a range of values from 0-10000 with 2 decimal place resolution. I made the range status and control and set a range graphic to match my other devices. As I mentioned above the Easy Trigger "Set Device to Expression will not set a vevice value if the device is status only.
There are 17 wattage measurement devices in my server closet that I wanted to sum, plus the new virtual device
Then I used a simple addition expression to total the 17 devices. You cannot use an Easy Trigger group to sum values, so each replacement variable must be entered. The string is thisCode:$$DVR:4889:+$$DVR:4887:+$$DVR:4885:+$$DVR:4882:+$$DVR:4879:+$$DVR:4876:+$$DVR:5068:+$$DVR:5066:+$$DVR:5064:+$$DVR:5061:+$$DVR:5058:+$$DVR:5044:+$$DVR:176:+$$DVR:172:+$$DVR:169:+$$DVR:165:+$$DVR:162
There is a bug in how HS handles such a long string when collapsed, which I will let Spud and Rich know about, but the Event functions well.
The immediate script that jvm posted is just as easy and would allow you to set the device as status only.
Comment
-
Originally posted by rjh View PostI will see if I can put in a fix. The problem is that there are no spaces in your string so the html does not wrap. I should be able to force a wrap with some CSS.
An easy fix on your end is to add some spaces. I suspect the EasyTrigger plugin is not going to mind if you put a space in front of the "+". Then is will wrap ok.
You can force the same issue if you create a simple speak action then enter text without spaces, you see the same problem.
HS4 Pro, 4.2.18.3 Windows 10 pro, Supermicro LP Xeon
Comment
-
Originally posted by devanbI am trying to use Easy trigger to add two values generated by reference pointers. I am getting the error:
I am not sure how to configure my virtual device to allow it's value to be changed by Easy Trigger.Apr-30 21:30:24 EasyTrigger ERROR SetDeviceValue: Cannot find control value 2081.03 for device 195
Thanks,
Devan
HS4 Pro, 4.2.18.3 Windows 10 pro, Supermicro LP Xeon
Comment
-
Originally posted by rprade View PostOnly the most recent Easy Trigger beta will allow you to set values on devices without controls. What version are you running?
I have it working now setting the Text Box in the Control column.
Is there a way to run an expression within a change device string command?
I'd like the total watts to be listed under status.
Currently with my above expression, it reports "948 + 1401" instead of the actual value of 2349.
Comment
Comment