Announcement

Collapse
No announcement yet.

Creating a string with values of an array and also checking another array

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

  • Creating a string with values of an array and also checking another array

    I have a virtual device which displays the values (setpoints) of my TRV's (see below). I am using a script to retrieve the setpoints, then writes it to a variable which is then written to the virtual device. The TRV has 2 modes, which are independent of the setpoints. That mode can be Heat or OFF. Only in the case that the TRV is Off, I want to display that TRV as OFF, not displaying the TRV setpoint .
    So in teh pic below, lets say the Kitchen TRV mode was off. The display then should be:

    Nest Setpoint 20 C
    Guest Bed TRV Setpoint 18 C
    Study TRV Setpoint 20 C
    Lounge TRV Setpoint 24.C
    Kitchen TRV Setpoint OFF
    Gym TRV Setpoint 17 C


    This is my current script:

    Code:
    dim array_trvs() as string = {"Nest","Guest Bed TRV","Study TRV","Lounge TRV","Kitchen TRV","Gym TRV"}
    
    dim trvsetpoint as string
    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.DeviceValueByNameEx(devw)
    
              If trvsetpoint >20
              trvstr = trvstr & trvs_name & " Setpoint " & " <span style='color:red'>" & trvsetpoint & " °C" & "</span>" & "<br>"
              Else
              trvstr = trvstr & trvs_name & " Setpoint " & " <span style='color:blue'>" & trvsetpoint & " °C" & "</span>" & "<br>"
    
              End If
    
    
    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
    .
    Attached Files

  • #2
    I have found a solution. But there is probably an easier way. I created conditions for each TRV separately rather than going through an array. Long winded and not pretty. But it works

    Code:
    sub Main(ByVal Parms as Object)
    
    dim trvsetpoint as string
    dim trvs_name as string = ""
    dim trvmode as string = ""
    dim trvstr as string = ""
    
    
              trvsetpoint = hs.DeviceValueByNameEx("Nest")
    
              If trvsetpoint >20
              trvstr = trvstr & "Nest" & " Setpoint " & " <span style='color:red'>" & trvsetpoint & " °C" & "</span>" & "<br>"
              Else
              trvstr = trvstr & "Nest" & " Setpoint " & " <span style='color:blue'>" & trvsetpoint & " °C" & "</span>" & "<br>"
    
              End If
    
    
    
              trvsetpoint = hs.DeviceValueByName("Guest Bed TRV")
              trvmode = hs.DeviceValueByName("Guest Bed TRV mode")
    
              If trvmode = 1
    
              If trvsetpoint >20
              trvstr = trvstr & "Guest Bed TRV" & " Setpoint " & " <span style='color:red'>" & trvsetpoint & " °C" & "</span>" & "<br>"
              Else
              trvstr = trvstr & "Guest Bed TRV" & " Setpoint " & " <span style='color:blue'>" & trvsetpoint & " °C" & "</span>" & "<br>"
              End If
    
              Else
    
              trvstr = trvstr & "Guest Bed TRV" & " Setpoint " & " <span style='color:red'>" & "OFF" & "</span>" & "<br>"
    
    
              End If
    
    
    
              trvsetpoint = hs.DeviceValueByName("Study TRV")
              trvmode = hs.DeviceValueByName("Study TRV mode")
    
              If trvmode = 1
    
              If trvsetpoint >20
              trvstr = trvstr & "Study TRV" & " Setpoint " & " <span style='color:red'>" & trvsetpoint & " °C" & "</span>" & "<br>"
              Else
              trvstr = trvstr & "Study TRV" & " Setpoint " & " <span style='color:blue'>" & trvsetpoint & " °C" & "</span>" & "<br>"
              End If
    
              Else
    
              trvstr = trvstr & "Study TRV" & " Setpoint " & " <span style='color:red'>" & "OFF" & "</span>" & "<br>"
    
    
              End If
    
    
              trvsetpoint = hs.DeviceValueByName("Lounge TRV")
              trvmode = hs.DeviceValueByName("Lounge TRV mode")
    
              If trvmode = 1
    
              If trvsetpoint >20
              trvstr = trvstr & "Lounge TRV" & " Setpoint " & " <span style='color:red'>" & trvsetpoint & " °C" & "</span>" & "<br>"
              Else
              trvstr = trvstr & "Lounge TRV" & " Setpoint " & " <span style='color:blue'>" & trvsetpoint & " °C" & "</span>" & "<br>"
              End If
    
              Else
    
              trvstr = trvstr & "Lounge TRV" & " Setpoint " & " <span style='color:red'>" & "OFF" & "</span>" & "<br>"
    
    
              End If
    
    
              trvsetpoint = hs.DeviceValueByName("Kitchen TRV")
              trvmode = hs.DeviceValueByName("Kitchen TRV mode")
    
              If trvmode = 1
              If trvsetpoint >20
              trvstr = trvstr & "Kitchen TRV" & " Setpoint " & " <span style='color:red'>" & trvsetpoint & " °C" & "</span>" & "<br>"
              Else
              trvstr = trvstr & "Kitchen TRV" & " Setpoint " & " <span style='color:blue'>" & trvsetpoint & " °C" & "</span>" & "<br>"
              End If
    
              Else
    
              trvstr = trvstr & "Kitchen TRV" & " Setpoint " & " <span style='color:red'>" & "OFF" & "</span>" & "<br>"
    
    
              End If
    
    
    
              trvsetpoint = hs.DeviceValueByName("Gym TRV")
              trvmode = hs.DeviceValueByName("Gym TRV mode")
    
              If trvmode = 1
    
               If trvsetpoint >20
               trvstr = trvstr & "Gym TRV" & " Setpoint " & " <span style='color:red'>" & trvsetpoint & " °C" & "</span>" & "<br>"
                Else
               trvstr = trvstr & "Gym TRV" & " Setpoint " & " <span style='color:blue'>" & trvsetpoint & " °C" & "</span>" & "<br>" 
    
               End If
    
               Else
    
              trvstr = trvstr & "Gym TRV" & " Setpoint " & " <span style='color:red'>" & "OFF" & "</span>" & "<br>"
    
    
    
              End If
    
          hs.SetDeviceString(440, trvstr,true)
    
    
    
    
    End Sub

    Comment

    Working...
    X