Announcement

Collapse
No announcement yet.

Averaging Temperature Devices

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Averaging Temperature Devices

    How do you average temperature devices? This require a plugin? I have Jon00's Database Graphing PI, but i'm not sure it does averaging that I can use in an event.

    #2
    Can be done easily in script. Plugin is not needed. You will create a third device which will be your average of the others. You will setup an event trigger for when the device value of any of the devices you are averaging changes. The action will be to run what can be a one line script so placed directly in the event action.

    &hs.SetDeviceValueByRef(123) = (hs.DeviceValue(456)+hs.DeviceValue(789))/2

    Where 123, 456, and 789 are the Device References of the three devices involved.

    Comment


      #3
      I think I have the script set up, but I'm not sure how to set up the virtual device to accept the data.

      Comment


        #4

        Comment


          #5

          Comment


            #6
            Bump..

            Comment


              #7
              Maybe i've done something wrong with the code. I have 3 devices to average, so I added the 4th device. Here's what I have:

              Code:
              &hs.SetDeviceValueByRef(1141) = (hs.DeviceValue(1016)+hs.DeviceValue(1037)+hs.DeviceValue(1096)))/3

              Comment


                #8
                Note from the example code, hs.SetDeviceValueByRef has this form:
                HS.SetDeviceValueByRef(Average, AverageTemp, True)

                Why not use the same structure as in the example, and modify this line?
                Dim AverageTemp = (BloomSkyTemp + CarParkTemp + GardenTemp + ShedTemp) / 4
                Mike____________________________________________________________ __________________
                HS3 Pro Edition 3.0.0.548, NUC i3

                HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

                Comment


                  #9
                  I'm trying to use the code supplied by Michael McSharry. It is one line. Are you saying it was one line out of a larger piece of code? lol that would figure as I'm code illiterate.

                  Comment


                    #10
                    Originally posted by tome10 View Post
                    I'm trying to use the code supplied by Michael McSharry. It is one line. Are you saying it was one line out of a larger piece of code? lol that would figure as I'm code illiterate.



                    looks like the 123 is the virtual device and 456 and 789 are the temp devices



                    &hs.SetDeviceValueByRef(123) = (hs.DeviceValue(456)+hs.DeviceValue(789))/2

                    Comment


                      #11
                      looks like the 123 is the virtual device and 456 and 789 are the temp devices
                      I agree, and that is the way I have it set up. I've never done this before, I don't know how the Virtual Device needs set up. I currently have on/off buttons, and it reads 100 for on, and 0 for off. So I think I need to create a device with just a textbox.

                      Comment


                        #12
                        Originally posted by tome10 View Post
                        I agree, and that is the way I have it set up. I've never done this before, I don't know how the Virtual Device needs set up. I currently have on/off buttons, and it reads 100 for on, and 0 for off. So I think I need to create a device with just a textbox.



                        all you need to do is get the reference number for the virtual device set it in the script where the 123 is. maybe set the range of value in the virtual device to cover the range of temps. the script will set the value of the virtual device. are you getting an error in the log for the script?

                        Comment


                          #13
                          Uncle Michael was correct about the format of the SetDeviceValue

                          &hs.SetDeviceValueByRef(1141,(hs.DeviceValue(1016)+hs.Device Value(1037)+hs.DeviceValue(1096))/3,true)

                          1141 is your new virtual device that was setup using DeviceManagent page of HS3. 1016, 1037 and 1096 are the three temperature devices. You will then use 1141 for charting or whatever you want to do with average temperature.

                          Comment


                            #14
                            Here's my take on scripting average temperatures and a couple of screenshots showing the virtual device config that receives the calculated average.

                            Only the SourceDevices array and AvgTempDevice values should need changing for it to work on any HS3 system.

                            Code:
                            Sub Main(Optional ByVal Parms As String = "")
                                Dim SourceDevices() As Integer = {4789, 5098, 5760, 8290, 872}
                                Dim AvgTempDevice As Integer = 1058
                            
                                Dim AvgTemp As Double = 0
                                Dim DeviceCount As Integer = 0
                            
                                For Each dvRef As Integer In SourceDevices
                                    If hs.DeviceExistsRef(dvRef) Then
                                        AvgTemp += (hs.DeviceValueEx(dvRef))
                                        DeviceCount += 1
                                    Else
                                        hs.WriteLog("AvgTempScript", "Error! Source device Ref:" & dvRef & " doesn't exist in HS.")
                                    End If
                                Next
                            
                                If DeviceCount > 0 Then
                                    AvgTemp = AvgTemp / DeviceCount
                                    If hs.DeviceExistsRef(AvgTempDevice) Then
                                        hs.SetDeviceValueByRef(AvgTempDevice, AvgTemp, True)
                                    Else
                                        hs.WriteLog("AvgTempScript", "Error! Target device Ref:" & AvgTempDevice & " doesn't exist in HS.")
                                    End If
                                Else
                                    hs.WriteLog("AvgTempScript", "Error! No devices to average.")
                                End If
                            
                            End Sub
                            Attached Files

                            Comment


                              #15
                              Though not the OP, thanks a million, Sooty... this worked great, with one very minor issue....


                              I don't seem to have the icon that you used. Should I?
                              HomeSeer Version: HS4 Pro Edition 4.2.19.0 (Windows - Running as a Service)
                              Home Assistant 2024.3
                              Operating System: Microsoft Windows 11 Pro - Desktop
                              Z-Wave Devices via two Z-Net G3s
                              Zigbee Devices via RaspBee on RPi 3b+
                              WiFi Devices via Internal Router.

                              Enabled Plug-Ins
                              AK GoogleCalendar 4.0.4.16,AK HomeAssistant 4.0.1.23,AK SmartDevice 4.0.5.1,AK Weather 4.0.5.181,AmbientWeather 3.0.1.9,Big6 3.44.0.0,BLBackup 2.0.64.0,BLGData 3.0.55.0,BLLock 3.0.39.0,BLUPS 2.0.26.0,Device History 4.5.1.1,EasyTrigger 3.0.0.76,Harmony Hub 4.0.14.0,HSBuddy 4.51.303.0,JowiHue 4.1.4.0,LG ThinQ 4.0.26.0,ONVIF Events 1.0.0.5,SDJ-Health 3.1.1.9,TPLinkSmartHome4 2022.12.30.0,UltraCID3 3.0.6681.34300,Z-Wave 4.1.3.0

                              Comment

                              Working...
                              X