No announcement yet.

How do I add up various Watt values and display them ?

  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I add up various Watt values and display them ?

    I have about 20 devices with child devices displaying Watts. I would like to add all of them up and display them in a virtual device, so I can see the overall Watt consumption of all my devices.

    At a later stage I want to create a multi display device (I have a few already) which only shows devices which consume more than 0 Watts, and then also the overall consumption. I have an idea of how to do the multi device display, the problem is how to get the value of each device.

    Can I get that by using hsgetdevicevaluebyref ? Then have a line
    consumption = hsgetdevicevaluebyref(1) + hsgetdevicevaluebyref(2) + ...

  • #2
    You are on the right track, but have the syntax wrong:

    consumption = hsgetdevicevaluebyref(1) + hsgetdevicevaluebyref(2) + ...
    Should be

    consumption = hs.devicevalueEx(1) + hs.devicevalueEx(2) + ...
    HS 1976 Devices 1156 Events
    Z-Wave 123 Nodes on one Z-Net


    • #3
      nearly there

      I am trying to do it all now. I have all devices which have more than 0 Watts consumption displayed. How do I now display consumption in watts as a last line ? Not sure if its calculated correctly in my script attempt either...
      Then is there a way to suppress the first 'Watts' in the name, so instead of

      Watts GreenIQ 7 watts

      it should display

      GreenIQ 7 watts

      This is my script attempt:

      dim array_energy() as string = {"Watts Blue lights right","Watts Blue lights left","Watts Satellite","Watts GreenIQ","Watts Sauna TV","Watts Projector","Watts Brick Lights","Watts Uplighters","Watts Water feature pump","Watts Water feature lights","Watts Artcoustic","Watts TV Sim","Watts tablet charger lounge","Watts tablet charger kitchen","Watts TAG","Watts Chromecast","Watts TV","Watts GC100","Watts iPod","Watts SKY"}
      dim watts as decimal = 0
      dim consumption as decimal = 0
      dim energy_name as string = ""
      dim energystr as string = ""
      sub Main(ByVal Parms as Object)
       'Option Strict Off 
      energy_name = ""
      energystr = ""
       for each devt as string in array_energy 
                         watts = hs.DeviceValueByNameEx(devt)
               If watts > 0 
                         energy_name = devt
                        energystr = energystr & energy_name & " <span style='color:blue'>" & watts & "</span>" & "<br>"
                        consumption = consumption + watts
               End If
            hs.SetDeviceString(612, energystr,true)
       Catch ex As Exception
      hs.WriteLog ("Array", "Error: " & ex.Message)
      End Try
      End Sub
      Attached Files


      • #4
        just one more thing

        Got the total consumption working I think

        I added

        energystr = energystr & "Total Consumtion " & " <span style='color:blue'>" & consumption & "</span>" & " Watts<br>"

        after the 'next'

        seems to work.

        Now, all whats left to do get rid of the 'Watts' in the device name, but I do not want to change the device name which would be the easy option, so I have to somehow 'subtract' the string 'Watts' from the device name
        Attached Files


        • #5
          You can use the Replace function to replace "Watts" with "".

          energy_name = devt.Replace("Watts","")
          See for details.
          HS 1976 Devices 1156 Events
          Z-Wave 123 Nodes on one Z-Net


          • #6
            That did it. Brilliant. Thanks !


            • #7
              Originally posted by mikee123 View Post
              That did it. Brilliant. Thanks !
              You're welcome.

              HS 1976 Devices 1156 Events
              Z-Wave 123 Nodes on one Z-Net