Announcement

Collapse
No announcement yet.

devicelastchange question in a script

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

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

    Leave a comment:


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

    Leave a comment:


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

    Leave a comment:


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

    Leave a comment:


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

    Leave a comment:


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

    Leave a comment:


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

    Leave a comment:


  • jon00
    replied
    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.

    Leave a comment:


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

    Leave a comment:


  • Malosa
    replied
    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.

    Leave a comment:


  • jon00
    replied
    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.

    Leave a comment:


  • Malosa
    replied
    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.

    Leave a comment:


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

    Leave a comment:


  • Malosa
    started a topic devicelastchange question in a script

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