Announcement

Collapse
No announcement yet.

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

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

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

    Cheers
    Al

    Leave a comment:


  • mikee123
    replied
    That did it. Brilliant. Thanks !

    Leave a comment:


  • sparkman
    replied
    You can use the Replace function to replace "Watts" with "".

    Code:
    energy_name = devt.Replace("Watts","")
    See https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx for details.

    Leave a comment:


  • mikee123
    replied
    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

    Leave a comment:


  • mikee123
    replied
    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:

    Code:
    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 
     Try
    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
    next
        
          hs.SetDeviceString(612, energystr,true)
        
     Catch ex As Exception
    hs.WriteLog ("Array", "Error: " & ex.Message)
    End Try
    End Sub
    Attached Files

    Leave a comment:


  • sparkman
    replied
    You are on the right track, but have the syntax wrong:

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

    Code:
    consumption = hs.devicevalueEx(1) + hs.devicevalueEx(2) + ...

    Leave a comment:


  • mikee123
    started a topic How do I add up various Watt values and display them ?

    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) + ...
Working...
X