Announcement

Collapse
No announcement yet.

Display Array Results in Device String

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

    #16
    I have made a start. First stumbling block, getting the setpoint value by device name. hs.DeviceValue(Name) ?

    This is what I've come up with:

    Code:
    'Define TRV Array
    '440 Array Virtual Switch
    '224 Heating Temp Control
    '227 Main Heating Setpoint
    '294 Guest Bed TRV
    '288 Study TRV
    '282 Lounge TRV
    '276 Kitchen TRV
    
    dim array_trvs() as string = {"Heating Temp Control","Main Heating Setpoint","Guest Bed TRV","Study TRV","Lounge TRV","Kitchen TRV"}
    
    dim trvsetpoint as integer = 0
    dim trvs_name as string = ""
    dim trvstr as string = ""
     
    Try
    trvs_name = ""
    trvstr = ""
     
    sub Main(ByVal Parms as Object)
    for each devw as string in array_trvs
                trvs_name = devw
               trvsetpoint = hs.DeviceValue(Name)
            trvstr = trvstr & trvs_name & " Setpoint" & trvsetpoint & "<br>"
        
    next
        
          hs.SetDeviceString(440, trvstr,true)
        
        hs.writelog("Array", "Window Count: " & windows_count)
     Catch ex As Exception
    hs.WriteLog ("Array", "Error: " & ex.Message)
    End Try
    End Sub

    Comment


      #17
      It should be HS.devicevaluebyname(devw)

      Comment


        #18
        I have had a few errors in the log, I have found and corrected them, so no errors any more when I run it. But I am not getting any values in my device or any text

        just seen this in the log:

        Array Error: Overload resolution failed because no accessible 'devicevaluebyname' accepts this number of arguments.

        Code:
        '227 Main Heating Setpoint
        '294 Guest Bed TRV
        '288 Study TRV
        '282 Lounge TRV
        '276 Kitchen TRV
         dim array_trvs() as string = {"Heating Temp Control","Main Heating Setpoint","Guest Bed TRV","Study TRV","Lounge TRV","Kitchen TRV"}
         dim trvsetpoint as integer = 0
        dim trvs_name as string = ""
        dim trvstr as string = ""
         
        sub Main(ByVal Parms as Object)
         Try
        trvs_name = ""
        trvstr = ""
         
         for each devw as string in array_trvs
                    trvs_name = devw
                   trvsetpoint = hs.devicevaluebyname
                trvstr = trvstr & trvs_name & " Setpoint" & trvsetpoint & "<br>"
            
        next
            
              hs.SetDeviceString(440, trvstr,true)
            
            'hs.writelog("Array", "Window Count: " & windows_count)
         Catch ex As Exception
        hs.WriteLog ("Array", "Error: " & ex.Message)
        End Try
        End Sub

        Comment


          #19
          found it !

          had to change trvsetpoint = hs.devicevaluebyname to trvsetpoint = hs.devicevaluebyname(devw)

          now its all working !

          Comment


            #20
            I have started the next project where I want to display temperatures. It works, but as I have set

            dim temperature as integer = 0

            it is only showing the integer of the temperature, while I would like to display 25.1, so 1 digit
            how do I have to define 'temperature' ?
            Also I have my array say for example

            Temp Kitchen 24 degrees

            I would like it to display

            Temp Kitchen 24.1 C

            That's the ultimate goal... I was reading about RangeStatusSuffix and RangeStatusPrefix and I think I need to use them
            But don't really understand the manual there
            Last edited by mikee123; July 29, 2016, 10:19 AM.

            Comment


              #21
              Change:
              dim temperature as integer = 0

              To:

              dim temperature as decimal = 0

              That will give you the decimal, then create another variable (something like dim temp_readout as string)

              temp_readout = temperature & " C"

              I think that should give you what you want.

              Comment


                #22

                Comment


                  #23
                  Double didnt work, nor did decimal. I can see in my RFXcom temperature devices that there is 1 digit after so 24.1 for example. So it is there...
                  Just in the array so far its not displaying.

                  Comment


                    #24
                    hs.devicevaluebyname is Integer based. You have to use hs.devicevaluebynameEx which uses Double Integer.

                    Also ensure you keep:

                    Dim temperature as decimal = 0
                    Jon

                    Comment


                      #25
                      Originally posted by jon00 View Post
                      hs.devicevaluebyname is Integer based. You have to use hs.devicevaluebynameEx which uses Double Integer.

                      Also ensure you keep:

                      Dim temperature as decimal = 0
                      That did it. Fantastic.

                      Comment


                        #26
                        I have a script to display all my temperature sensors in an array and that works fine. But one of my sensor devices displays 'Communication Failure'. In the array it is displaying the last temperature, but I would rather have it display 'CF' so that I can see that there is a problem

                        This is my attempt but it came up with this error in the log:

                        Aug-02 19:17:16 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\multitemp2.vb: End of statement expected.
                        Aug-02 19:17:16 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\multitemp2.vb: 'Communication' is not declared. It may be inaccessible due to its protection level.
                        Aug-02 19:17:16 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\multitemp2.vb: Namespace or type specified in the Imports 'System.Core' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.

                        Code:
                        dim array_temps() as string = {"Temp Outside","Temp Weather Station","Temp Master Bedroom","Temp Kitchen","Hall Temperature","Temp Utility Room","Temp Study","Temp Garage"}
                        
                        dim temperature as decimal = 0
                        dim temp_name as string = ""
                        dim tempstr as string = ""
                         
                        sub Main(ByVal Parms as Object)
                        
                        Try
                        temp_name = ""
                        tempstr = ""
                         
                        
                        for each devt as string in array_temps
                                    temp_name = devt
                                   temperature = hs.DeviceValueByNameEx(devt)
                        
                                If temperature = "Communication Failure"
                                tempstr = tempstr & temp_name & " " & " CF" & "<br>"
                                Else
                                tempstr = tempstr & temp_name & " " & temperature & " °C" & "<br>"
                            
                        next
                            
                              hs.SetDeviceString(441, tempstr,true)
                            
                         Catch ex As Exception
                        hs.WriteLog ("Array", "Error: " & ex.Message)
                        End Try
                        End Sub

                        Comment


                          #27
                          Just add the following after the line: temperature = hs.DeviceValueByNameEx(devt)

                          PHP Code:
                          temperature temperature.replace("Communication Failure","CF"

                          Edit. I see you updated your post.....

                          The error in your script if you want to use your code is this line:

                          If temperature = "Communication Failure"

                          It should read:

                          If temperature = "Communication Failure" then

                          And you missed an 'End if'

                          i.e.

                          PHP Code:
                                 If temperature "Communication Failure" then
                                     tempstr 
                          tempstr temp_name " " " CF" "<br>"
                                 
                          Else
                                     
                          tempstr tempstr temp_name " " temperature " °C" "<br>"
                                 
                          End if 
                          Jon

                          Comment


                            #28
                            I added the 'then', that got rid of the error but its not displaying CF even though I have a Communication Failure. Pretty sure I know why, but dont know how to catch it. There is a value in the variable, the communication failure is in device string
                            Attached Files

                            Comment


                              #29
                              Got it. Changed it to:

                              Code:
                              If hs.DeviceStringByNameEx(devt) = "Communication Failure" then
                                      tempstr = tempstr & temp_name & " " & " CF" & "<br>"
                                      Else
                                      tempstr = tempstr & temp_name & " " & temperature & " °C" & "<br>"
                                      End If
                              That seems to work. I must have learnt something...

                              Now I would like the 'CF' to be red... possible ?

                              Comment


                                #30
                                PHP Code:
                                tempstr tempstr temp_name " " " <span style='color:red'>CF</span>" "<br>" 
                                Jon

                                Comment

                                Working...
                                X