Announcement

Collapse
No announcement yet.

Trying to create event which tells me which window is open

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

  • Trying to create event which tells me which window is open

    I have an event which triggers when any window is open and it starts to rain. It triggers a TTS that a window is open and it has started to rain. I now want to expand this so the event will tell me which window(s) is open. I think I have seen something like this on the forum a few months ago but didnt bookmark it and now cannot find it any more.

  • #2
    I use a script to write my window status to a virtual device to display which window (or door into another virtual device) is opened. I guess that could be the basis for what I want to develop

    Code:
    'Define Windows/Doors Array
    
    dim array_windows() as string = {"Bedroom Right Window","Bedroom Left Window","Cloakroom window","Study Window","Gym Window","EnSuite Window"}
    dim array_doors() as string = {"Garage Door","Porch Door","Garage Inside Door","Kitchen Back Door","Patio Door","Bedroom Door"}
    dim windows_count as integer = 0
    dim doors_count as integer = 0
    dim door_name as String = ""
    dim dstr as string = ""
    dim window_name as string = ""
    dim wstr as string = ""
    
    sub windows(ByVal Parms as Object)
    Try
    windows_count = 0
    window_name = ""
    wstr = ""
     for each devw as string in array_windows
        if hs.DeviceValueByName(devw) = 255 or hs.DeviceValueByName(devw) = 100 then
            windows_count = windows_count + 1
            window_name = devw
            wstr = wstr & window_name & " Opened" & "<br>"
        Else If hs.DeviceValueByName(devw) = 0 then 'No windows open
        end if
    next
        If windows_count > 0 then 
            hs.SetDeviceValueByRef(439,100,true)
            hs.SetDeviceString(439, wstr,true)
        Else
            hs.SetDeviceValueByRef(439,0,true)
            hs.SetDeviceString(439, "All Windows Closed",true)
        End If
    
        hs.writelog("Array", "Window Count: " & windows_count)
     Catch ex As Exception
    hs.WriteLog ("Array", "Error: " & ex.Message)
    End Try
    End Sub
    
    sub doors(ByVal Parms as Object)
    Try
    doors_count = 0
    door_name = ""
    dstr = ""
    for each devd as string in array_doors
        if hs.DeviceValueByName(devd) = 255 or hs.DeviceValueByName(devd) = 100 or hs.DeviceValueByName(devd) = 22 then
            doors_count = doors_count + 1
            door_name = devd
            dstr = dstr & door_name & " Opened" & "<br>"
        Else If hs.DeviceValueByName(devd) = 0 then 'No doors open
        end if
    next
        If doors_count > 0 then 
            hs.SetDeviceValueByRef(438,100,true) 'was 170
            hs.SetDeviceString(438, dstr,true) 'was 170
        Else
            hs.SetDeviceValueByRef(438,0,true)
            hs.SetDeviceString(438, "All Doors Closed",true)
        End If
    Catch ex As Exception
    hs.WriteLog ("Array", "Error: " & ex.Message)
    End Try
      hs.writelog("Script","multistatustest")
    End Sub

    Comment


    • #3
      I'm sure something like this would work:

      Code:
          Sub Main(ByVal Parms As Object)
              Dim array_windows() As String = {"Bedroom Right Window", "Bedroom Left Window", "Cloakroom window", "Study Window", "Gym Window", "EnSuite Window"}
              For Each devw As String In array_windows
                  If hs.DeviceValueByName(devw) = 100 Or hs.DeviceValueByName(devw) = 255 Then hs.speak(devw & " is open")
              Next
          End Sub
      Jon

      Comment


      • #4
        Theoretically it probably would. But I want to route it to one of my tablets via tasker TTS. Ill have a look on the tasker part of the forum, and see if there is a script command, I think I vaguely remember there is a way. Before your response I started thinking of maybe adding it all up in a string variable, but that would need to be available outside of the script. I could then use tasker tts - variable to speak it. I think I would need to create a golbal variable, i think they are available outside of the script. I was probably overthinking this.
        So I think I'll try your approach first, if needed with the tasker speak command in the script

        Comment


        • #5
          Originally posted by mikee123 View Post
          I have an event which triggers when any window is open and it starts to rain. It triggers a TTS that a window is open and it has started to rain. I now want to expand this so the event will tell me which window(s) is open. I think I have seen something like this on the forum a few months ago but didnt bookmark it and now cannot find it any more.
          Hi Mike how do you accomplish this with a script? I would like to do something similar with my doors and if the doors are locked ect.

          Comment


          • #6
            Are you trying to display the status in a virtual device or what are you trying to do ? The script from post #2 is what I use top display the door and window status in 2 virtual devices

            This is the event which triggers when it rains and a window is open

            Attached Files

            Comment

            Working...
            X