Announcement

Collapse
No announcement yet.

devicelastchange question in a script

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

    devicelastchange question in a script

    //ELAPSED TIME

    im building a very huge script and i need this option for my voice system if its possible..


    i have an script that gets the status of all my pir sensors .
    but i want that it get the last change also , and that it speaks the last change ...

    i already have it speaking the last change but it speaks wrong , it says 19 july 19:12:12 it says 19 days and 12 hours and 12 minutes...

    i want that it speaks like if the last change is 10 july 14:40:32 and the time is now 14:50:32 he must speak 10 minutes and 32 seconds ago.


    regards
    Last edited by Malosa; July 29, 2016, 09:36 AM. Reason: FOrget something in the title
    Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
    Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




    HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

    #2
    Something to get you going:

    PHP Code:
    Sub Main(ByVal Parm As Object)

        
    Dim TN As Date DateTime.Now
        Dim LC 
    As Date hs.devicelastchange("devicename")
        
    Dim TS As Timespan TN.Subtract(LC)
        
    Dim H As Integer TS.TotalHours
        Dim M 
    As Integer TS.Minutes
        Dim S 
    As Integer TS.Seconds

        
    If 0 Then
            hs
    .speak(" hours " " minutes and " " seconds ago")
        Else
            If 
    0 Then
                hs
    .speak(" minutes and " " seconds ago")
            Else
                
    hs.speak(" seconds ago")
            
    End If
        
    End If

    End Sub 
    Jon

    Comment


      #3
      many many great thanks again JON!

      it works perfect , how can i add multiple device?
      what do i need to add to it , or do i need to change the code



      //edit , i found it out , i put after everything a 1 and so on.



      Originally posted by jon00 View Post
      Something to get you going:

      PHP Code:
      Sub Main(ByVal Parm As Object)

          
      Dim TN As Date DateTime.Now
          Dim LC 
      As Date hs.devicelastchange("devicename")
          
      Dim TS As Timespan TN.Subtract(LC)
          
      Dim H As Integer TS.TotalHours
          Dim M 
      As Integer TS.Minutes
          Dim S 
      As Integer TS.Seconds

          
      If 0 Then
              hs
      .speak(" hours " " minutes and " " seconds ago")
          Else
              If 
      0 Then
                  hs
      .speak(" minutes and " " seconds ago")
              Else
                  
      hs.speak(" seconds ago")
              
      End If
          
      End If

      End Sub 
      Last edited by Malosa; July 29, 2016, 11:46 AM.
      Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
      Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




      HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

      Comment


        #4
        You may be better leaving it as a subroutine and then calling it for each device name.

        Here is an example:

        PHP Code:
        Sub Main(ByVal Parm As Object)

            
        Dim MyDeviceNames As Array = {"devicename1""devicename2""devicename3"}
            For 
        Each DN As String In MyDeviceNames
                Announce
        (DN)
            
        Next

        End Sub


        Sub Announce
        (ByVal DeviceName As String)

            
        Dim TN As Date DateTime.Now
            Dim LC 
        As Date hs.devicelastchange(DeviceName)
            
        Dim TS As Timespan TN.Subtract(LC)
            
        Dim H As Integer TS.TotalHours
            Dim M 
        As Integer TS.Minutes
            Dim S 
        As Integer TS.Seconds

            
        If 0 Then
                hs
        .speak(" hours " " minutes and " " seconds ago")
            Else
                If 
        0 Then
                    hs
        .speak(" minutes and " " seconds ago")
                Else
                    
        hs.speak(" seconds ago")
                
        End If
            
        End If

        End Sub 
        Last edited by jon00; July 29, 2016, 06:05 PM.
        Jon

        Comment


          #5
          thanks

          i got it

          many thanks !!!!


          Originally posted by jon00 View Post
          You may be better leaving it as a subroutine and then calling it for each device name.

          Here is an example:

          PHP Code:
          Sub Main(ByVal Parm As Object)

              
          Dim MyDeviceNames As Array = {"devicename1""devicename2""devicename3"}
              For 
          Each DN As String In MyDeviceNames
                  Announce
          (DN)
              
          Next

          End Sub


          Sub Announce
          (ByVal DeviceName As String)

              
          Dim TN As Date DateTime.Now
              Dim LC 
          As Date hs.devicelastchangeref(DeviceName)
              
          Dim TS As Timespan TN.Subtract(LC)
              
          Dim H As Integer TS.TotalHours
              Dim M 
          As Integer TS.Minutes
              Dim S 
          As Integer TS.Seconds

              
          If 0 Then
                  hs
          .speak(" hours " " minutes and " " seconds ago")
              Else
                  If 
          0 Then
                      hs
          .speak(" minutes and " " seconds ago")
                  Else
                      
          hs.speak(" seconds ago")
                  
          End If
              
          End If

          End Sub 
          Last edited by Malosa; July 29, 2016, 12:26 PM.
          Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
          Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




          HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

          Comment


            #6
            jon

            how can i let it read the name instead of the reference? because i never remember the correct numbers, name is easy
            like PIR1,PIR2,PIR3
            Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
            Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




            HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

            Comment


              #7
              I'm not quite sure I understand. I assume you have modified the code to announce the device name?

              I did change the hs.devicelastchangeref to hs.devicelastchange in my example.
              Jon

              Comment


                #8
                hi jon ,

                like now i need to put the device ref in it , but if i change the code it still don't want to get my device name like (pir livingroom)i still need to put 2001 in there..

                i have it with the other scripts also


                regards
                Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
                Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




                HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

                Comment


                  #9
                  You can get the name, Location etc from the ref.

                  Here is an example:

                  PHP Code:
                      Sub Main(ByVal Parm As Object)

                          
                  Dim dv As Scheduler.Classes.DeviceClass Nothing
                          Dim dvRef 
                  As Integer 1234
                          Dim Location 
                  As String ""
                          
                  Dim Location2 As String ""
                          
                  Dim Name As String ""
                          
                  dv hs.GetDeviceByRef(dvRef)
                          
                  Location dv.Location(hs)
                          
                  Location2 dv.Location2(hs)
                          
                  Name dv.Name(hs)
                          
                  hs.writelog("Loc"Location)
                          
                  hs.writelog("Loc2"Location2)
                          
                  hs.Writelog("Name"Name)

                      
                  End Sub 
                  Jon

                  Comment


                    #10
                    hi jon,

                    that example you give me works ,

                    i merged multiple scripts from the forum and edited some lines

                    but what did i do wrong here ,

                    i know this topic is getting different now but thats my last question

                    here i only can use the device ref but i want to use the names so later homeseer can speak the name of the pir instead of the ugly code , so normal it needs to work but i cant get it to work..

                    it counts the pir's that are online and disabled.. and also it says the status.
                    but when i want to add hs.speak (pir_name & " standby") nothing comes out only standby/




                    i know it looks like a mess but i need to clean it up later ,



                    Code:
                    dim array_pir() as string = {"2704","2698","2517"}
                    dim pirdisabled_count as integer = 0
                    dim pirenabled_count as integer = 0
                    dim pir_name as string = ""
                    dim pstr as string = ""
                     
                    sub pir(ByVal Parms as Object)
                    Try
                    pirdisabled_count = 0
                    pirenabled_count = 0
                    pir_name = ""
                    pstr = ""
                     for each devp as string in array_pir
                        Select Case hs.DeviceValue(devp)
                          Case 0
                           pirenabled_count = pirenabled_count + 1
                    	   hs.speak (pir_name & "  standby")
                         Case 1
                           hs.speak ("person detected in the **")
                         Case 11
                           pirdisabled_count = pirdisabled_count + 1
                         Case 15
                           hs.speak ("P I R in the ** is Enabled")
                         Case Else 'Optional
                            hs.speak ("P I R in the garden has an error please check the battery")
                       End Select
                    next
                        If pirdisabled_count > 0 then 
                         hs.speak("found some")   
                            
                        Else
                            
                            hs.speak("no count")
                        End If
                        
                        hs.speak (pirdisabled_count, true, "$SONOS$TTS")
                        hs.writelog("Array", "enabled pir's: " & pirenabled_count)
                    	hs.writelog("Array", "disabled pir's: " & pirdisabled_count)
                     Catch ex As Exception
                    hs.WriteLog ("Array", "Error: " & ex.Message)
                    End Try
                    End Sub

                    output

                    Code:
                    Jul-31 15:36:35	 	Array	disabled pir's: 2
                    Jul-31 15:36:35	 	Array	enabled pir's: 1
                    Jul-31 15:36:35	 	TTS	Speak ($SONOS$TTS):2
                    Jul-31 15:36:35	 	TTS	Speak ():found some
                    Jul-31 15:36:35	 	TTS	Speak ():standby

                    this is my final question , im building and learning so its my first complex script for all my pir's
                    Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
                    Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




                    HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

                    Comment


                      #11
                      Does this work?:

                      PHP Code:
                          Dim array_pir() As String = {"2704""2698""2517"}
                          
                      Dim pirdisabled_count As Integer 0
                          Dim pirenabled_count 
                      As Integer 0
                          Dim pir_name 
                      As String ""
                          
                      Dim pstr As String ""
                          
                      Dim dv As Scheduler.Classes.DeviceClass Nothing

                          Sub pir
                      (ByVal Parms As Object)
                              Try
                                  
                      pirdisabled_count 0
                                  pirenabled_count 
                      0
                                  pir_name 
                      ""
                                  
                      pstr ""
                                  
                      For Each devp As String In array_pir
                                      Select 
                      Case hs.DeviceValue(devp)
                                          Case 
                      0
                                              dv 
                      hs.GetDeviceByRef(devp)
                                              
                      pir_name dv.Name(hs)
                                              
                      pirenabled_count pirenabled_count 1
                                              hs
                      .speak(pir_name "  standby")
                                          Case 
                      1
                                              hs
                      .speak("person detected in the **")
                                          Case 
                      11
                                              pirdisabled_count 
                      pirdisabled_count 1
                                          
                      Case 15
                                              hs
                      .speak("P I R in the ** is Enabled")
                                          Case Else 
                      'Optional
                                              hs.speak("P I R in the garden has an error please check the battery")
                                      End Select
                                  Next
                                  If pirdisabled_count > 0 Then
                                      hs.speak("found some")

                                  Else

                                      hs.speak("no count")
                                  End If

                                  hs.speak(pirdisabled_count, True, "$SONOS$TTS")
                                  hs.writelog("Array", "enabled pir'
                      s" & pirenabled_count)
                                  hs.writelog("
                      Array", "disabled pir's: " & pirdisabled_count)
                              Catch ex As Exception
                                  hs.WriteLog("Array", "Error: " & ex.Message)
                              End Try
                          End Sub 
                      Jon

                      Comment


                        #12
                        hi jon

                        many thanks for your time , it works !!

                        so i only have to copy these 2 lines in each case and it works

                        dv = hs.GetDeviceByRef(devp)
                        pir_name = dv.Name(hs)

                        regards and many thanks!!!



                        Originally posted by jon00 View Post
                        Does this work?:

                        PHP Code:
                            Dim array_pir() As String = {"2704""2698""2517"}
                            
                        Dim pirdisabled_count As Integer 0
                            Dim pirenabled_count 
                        As Integer 0
                            Dim pir_name 
                        As String ""
                            
                        Dim pstr As String ""
                            
                        Dim dv As Scheduler.Classes.DeviceClass Nothing

                            Sub pir
                        (ByVal Parms As Object)
                                Try
                                    
                        pirdisabled_count 0
                                    pirenabled_count 
                        0
                                    pir_name 
                        ""
                                    
                        pstr ""
                                    
                        For Each devp As String In array_pir
                                        Select 
                        Case hs.DeviceValue(devp)
                                            Case 
                        0
                                                dv 
                        hs.GetDeviceByRef(devp)
                                                
                        pir_name dv.Name(hs)
                                                
                        pirenabled_count pirenabled_count 1
                                                hs
                        .speak(pir_name "  standby")
                                            Case 
                        1
                                                hs
                        .speak("person detected in the **")
                                            Case 
                        11
                                                pirdisabled_count 
                        pirdisabled_count 1
                                            
                        Case 15
                                                hs
                        .speak("P I R in the ** is Enabled")
                                            Case Else 
                        'Optional
                                                hs.speak("P I R in the garden has an error please check the battery")
                                        End Select
                                    Next
                                    If pirdisabled_count > 0 Then
                                        hs.speak("found some")

                                    Else

                                        hs.speak("no count")
                                    End If

                                    hs.speak(pirdisabled_count, True, "$SONOS$TTS")
                                    hs.writelog("Array", "enabled pir'
                        s" & pirenabled_count)
                                    hs.writelog("
                        Array", "disabled pir's: " & pirdisabled_count)
                                Catch ex As Exception
                                    hs.WriteLog("Array", "Error: " & ex.Message)
                                End Try
                            End Sub 
                        Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
                        Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




                        HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

                        Comment


                          #13
                          You only need to enter it once if you put it outside the case statements i.e.:

                          PHP Code:
                              Sub pir(ByVal Parms As Object)
                                  Try
                                      
                          pirdisabled_count 0
                                      pirenabled_count 
                          0
                                      pir_name 
                          ""
                                      
                          pstr ""
                                      
                          For Each devp As String In array_pir
                                          dv 
                          hs.GetDeviceByRef(devp)
                                          
                          pir_name dv.Name(hs)
                                          
                          Select Case hs.DeviceValue(devp)
                                              Case 
                          0
                                                  pirenabled_count 
                          pirenabled_count 1
                                                  hs
                          .speak(pir_name "  standby")
                                              Case 
                          1
                                                  hs
                          .speak("person detected in the **")
                                              Case 
                          11
                                                  pirdisabled_count 
                          pirdisabled_count 1
                                              
                          Case 15
                                                  hs
                          .speak("P I R in the ** is Enabled")
                                              Case Else 
                          'Optional
                                                  hs.speak("P I R in the garden has an error please check the battery")
                                          End Select
                                      Next
                                      If pirdisabled_count > 0 Then
                                          hs.speak("found some")

                                      Else

                                          hs.speak("no count")
                                      End If

                                      hs.speak(pirdisabled_count, True, "$SONOS$TTS")
                                      hs.writelog("Array", "enabled pir'
                          s" & pirenabled_count)
                                      hs.writelog("
                          Array", "disabled pir's: " & pirdisabled_count)
                                  Catch ex As Exception
                                      hs.WriteLog("Array", "Error: " & ex.Message)
                                  End Try
                              End Sub 
                          Jon

                          Comment


                            #14
                            thanks again ,
                            you right , im understanding now how everything works with array's and the rest.
                            you spare me a lot of time !


                            Originally posted by jon00 View Post
                            You only need to enter it once if you put it outside the case statements i.e.:

                            PHP Code:
                                Sub pir(ByVal Parms As Object)
                                    Try
                                        
                            pirdisabled_count 0
                                        pirenabled_count 
                            0
                                        pir_name 
                            ""
                                        
                            pstr ""
                                        
                            For Each devp As String In array_pir
                                            dv 
                            hs.GetDeviceByRef(devp)
                                            
                            pir_name dv.Name(hs)
                                            
                            Select Case hs.DeviceValue(devp)
                                                Case 
                            0
                                                    pirenabled_count 
                            pirenabled_count 1
                                                    hs
                            .speak(pir_name "  standby")
                                                Case 
                            1
                                                    hs
                            .speak("person detected in the **")
                                                Case 
                            11
                                                    pirdisabled_count 
                            pirdisabled_count 1
                                                
                            Case 15
                                                    hs
                            .speak("P I R in the ** is Enabled")
                                                Case Else 
                            'Optional
                                                    hs.speak("P I R in the garden has an error please check the battery")
                                            End Select
                                        Next
                                        If pirdisabled_count > 0 Then
                                            hs.speak("found some")

                                        Else

                                            hs.speak("no count")
                                        End If

                                        hs.speak(pirdisabled_count, True, "$SONOS$TTS")
                                        hs.writelog("Array", "enabled pir'
                            s" & pirenabled_count)
                                        hs.writelog("
                            Array", "disabled pir's: " & pirdisabled_count)
                                    Catch ex As Exception
                                        hs.WriteLog("Array", "Error: " & ex.Message)
                                    End Try
                                End Sub 
                            Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
                            Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




                            HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

                            Comment

                            Working...
                            X