Announcement

Collapse
No announcement yet.

How do I grab the time stamp of a device into a variable ?

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

    How do I grab the time stamp of a device into a variable ?

    I need to get the time stamp of a device into a variable to display in a virtual device. I only need the time, not the date. (24h format). Basically I want to display the last time a device has changed.

    The device is the device below, and I just need the 13:22:35

    Attached Files

    #2
    I have got the timestamp, but that returns the date as well as the time,

    Dim dteLast As Date = hs.DeviceLastChangeRef(2138)

    Comment


      #3
      Try this:

      Dim dteLast As String = hs.DeviceLastChangeRef(1699).ToLongTimeString
      Jon

      Comment


        #4
        Great, that worked !

        Comment


          #5
          What would I need to do to get rid of the seconds ? I do not need to show the seconds, the hour and minutes would be sufficient. Also something else I never managed in other scripts too. I would like 2 spaces between the C and the timestamp. In my script, this is the line I use to create the variable to write to the virtual device

          Code:
          If trvsetpoint >19.5
                    trvstr = trvstr & "Nest" & " Setpoint " & " <span style='color:red'>" & trvsetpoint & " °C " & "</span>"
                    Else
                    trvstr = trvstr & "Nest" & " Setpoint " & " <span style='color:blue'>" & trvsetpoint & " °C " & "</span>"
          
                    End If
          
                    If trvmode = 1
                    trvstr = trvstr &  " <span style='color:red'>" & "  Heat" & "</span>" & "<br>"
                    End If
          
                     trvstr = trvstr & "  " & dteLast & "<br>"
          but if I replace " " with " ", that still only creates 1 space. Also tried " " & " ", still just 1 space. I have the same problem when trying to format strings for emails, I never manage to get more than 1 space between

          Attached Files

          Comment


            #6
            You can use:

            hs.DeviceLastChangeRef(1699).ToShortTimeString

            or if you want to format it explicitly:

            hs.DeviceLastChangeRef(1699).ToString("HH:mm")
            Jon

            Comment


              #7
              Dim dteLast As Date = hs.DeviceLastChangeRef(2138).ToString("HH:mm")

              does not work, I have these errors in the log:

              Mar-19 12:08:45 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\multi trv temp display new.vb: Value of type 'Char' cannot be converted to 'Date'.
              Mar-19 12:08:45 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\multi trv temp display new.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.
              Mar-19 12:08:42 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\multi trv temp display new.vb: Value of type 'Char' cannot be converted to 'Date'.
              Mar-19 12:08:42 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\multi trv temp display new.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.


              Dim dteLast As Date = hs.DeviceLastChangeRef(2138).ToShortTimeString

              this does not show any errors, but the time is still shown with seconds

              Comment


                #8
                You should be using:

                Dim dteLast As String =
                Jon

                Comment


                  #9
                  Yes that was it. Any idea of how to get 2 spaces between the C and the time ? Just cannot work out how to, but it must be possible ? Unless I add a " . " but thats not really what I want

                  Comment


                    #10
                    Originally posted by mikee123 View Post
                    Yes that was it. Any idea of how to get 2 spaces between the C and the time ? Just cannot work out how to, but it must be possible ? Unless I add a " . " but thats not really what I want
                    Try using &nbsp;&nbsp; instead of the two spaces. The problem is that html is formatting it for you. This should explain to it that you do want the extra spaces.

                    Comment


                      #11
                      I tried
                      trvstr = trvstr & nbsp & nbsp & dteLast & "<br>"
                      as well as
                      rvstr = trvstr &nbsp; &nbsp; & dteLast & "<br>"

                      but its giving me an error

                      Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\multi trv temp display new.vb: 'nbsp' is not declared. It may be inaccessible due to its protection level.

                      Comment


                        #12
                        I think that is what you meant. Looks as if it works now

                        trvstr = trvstr & "&nbsp;&nbsp;" & dteLast & "<br>"

                        Comment


                          #13
                          Put &nbsp; inside of quotes, like you do with the "<br>".

                          rvstr = trvstr & "&nbsp;&nbsp;" & dteLast & "<br>"

                          Comment


                            #14
                            Originally posted by mikee123 View Post
                            I think that is what you meant. Looks as if it works now

                            trvstr = trvstr & "&nbsp;&nbsp;" & dteLast & "<br>"
                            Yes, sorry that wasn't clear.

                            Comment

                            Working...
                            X