Announcement

Collapse
No announcement yet.

Help with open/closed statuses and speak results only if open

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

    Help with open/closed statuses and speak results only if open

    I would like to be able to query if my windows (or doors) are open or closed and if they are open I would like to know which one(s) are open. I plan on using this as a speaking event during my nightly shut down.



    Is this something simple i am missing or is this something in the scripting world?

    #2
    Originally posted by keithj69 View Post
    I would like to be able to query if my windows (or doors) are open or closed and if they are open I would like to know which one(s) are open. I plan on using this as a speaking event during my nightly shut down.



    Is this something simple i am missing or is this something in the scripting world?



    that wouldn't be too hard. just create an event for each window like..


    if widow is open
    and if night shut down is on (so this is the only time it runs)

    then speak...window open


    then run the events from within your "night shut down" event, and select only run if event conditions are true.


    so you would have and event like..


    if night shut down is on
    then run event 1 - only if conditions are true

    then run event 2 - only if conditions are true
    then run event 3 - only if conditions are true

    Comment


      #3
      Originally posted by keithj69 View Post
      I would like to be able to query if my windows (or doors) are open or closed and if they are open I would like to know which one(s) are open. I plan on using this as a speaking event during my nightly shut down.



      Is this something simple i am missing or is this something in the scripting world?
      I don't know if you are willing to use a simple script, but a script is the easiest way to populate a device with an array of all of the doors or windows are open. I use a script that Wayne (waynehead99) built and modified it for my use. I use several virtual devices and multiple subroutines in this script to update different groups. In this simplified script I have pared the script down to all windows and all doors. There is a virtual device for each. Lines in a script that begin with a single quote are only comments, they have nothing to do with the function of the script.



      When the script runs, it goes through one of two fixed arrays of reference numbers for the doors or windows I wish to check. It will populate each virtual device with the names of each window or door that is open. As you can see above, the front door is open and all windows are closed. This is a simplified version of the script:

      Code:
      'these are the virtual devices to be updated by the script
      '5281	Windows
      '8829   Doors
      
      'Use the reference ID of the door or window sensor devices in the arrays below
      
      dim array_windows() as string = {"4557", "4548", "4550", "4543", "4556", "4549", "4564", "4553", "4555", "4554", "4551", "4545", "4544","4559", "4560", "4561", "4562", "4563"}
      
      dim array_doors() as string = {"4565", "4542", "4558", "4566", "4532", "4531", "4552", "4523", "4522", "4528", "4527"}
      
      dim windows_count as integer = 0
      dim window_name as string = ""
      dim wstr as string = ""
      
      dim doors_count as integer = 0
      dim door_name as String = ""
      dim dstr as string = ""
      
      Dim dv as Object
      
      'Using 2 subs, one for doors and the other for windows
      
      'WINDOWS
      sub windows(ByVal Parms as Object)
      Try
      windows_count = 0
      window_name = ""
      wstr = ""
      for each devw as string in array_windows
              'hs.writelog("Array", "Window " & window_name & " | Value " & hs.DeviceValue(devw))
      	if hs.DeviceValue(devw) = 1 then
                      windows_count = windows_count + 1
      		dv = hs.GetDeviceByRef(devw)
      		window_name =  dv.Name(hs)
             		wstr = wstr & window_name & ",<br>"
      	hs.writelog("DoorWindow", window_name & " Open")
      	'hs.writelog("DoorWindow", array_windows)
              end if
      next
      	If windows_count > 0 then 
      		hs.SetDeviceValueByRef(5281,100,true)
      		hs.SetDeviceString(5281, wstr,true)
      	Else
      		hs.SetDeviceValueByRef(5281,0,true)
      		hs.SetDeviceString(5281, "All Windows Closed",true)
      	End If
      	
      	hs.writelog("DoorWindow", "Window Count: " & windows_count)
      
      Catch ex As Exception
      hs.WriteLog ("DoorWindow", "Error: " & ex.Message)
      End Try
      
      End Sub
      
      'DOORS
      sub doors(ByVal Parms as Object)
      Try
      doors_count = 0
      door_name = ""
      dstr = ""
      for each devd as string in array_doors
              'hs.writelog("Array", "Door " & door_name & " | Value " & hs.DeviceValue(devd))
      	if hs.DeviceValue(devd) = 1 then
      		dv = hs.GetDeviceByRef(devd)
      		door_name =  dv.Name(hs)
      		doors_count = doors_count + 1
      		dstr = dstr & door_name & ",<br>"
      	hs.writelog("DoorWindow", door_name & " Open")
              end if
      next
      	If doors_count > 0 then 
      		hs.SetDeviceValueByRef(8829,100,true)
      		hs.SetDeviceString(8829, dstr,true)
      	Else
      		hs.SetDeviceValueByRef(8829,0,true)
      		hs.SetDeviceString(8829, "All Doors Closed",true)
      	End If
      
      	hs.writelog("DoorWindow", "Door Count: " & doors_count)
      
      Catch ex As Exception
      hs.WriteLog ("DoorWindow", "Error: " & ex.Message)
      End Try
      
      End Sub
      I think the script is commented well enough.

      Just create your virtual devices for storing windows and doors. Then use the Reference ID of the virtual devices in the script. Build your arrays using the Reference IDs of the doors and windows you want to check. The script will set the virtual device to Off (0) when all devices are closed and at On (100) if any device is open. The actual text is written to the string for each device. You can then use the device in a TTS announcement, email or other method of communicating.

      When we go to bed our "House to Sleep" events will run the script.

      Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	50.0 KB
ID:	1197334

      Click image for larger version

Name:	Capture2.PNG
Views:	1
Size:	31.8 KB
ID:	1197336

      If any doors or windows are open it will speak the string values of either or both devices to remind us that a door or window is open. I use a script to initiate my TTS since we use all Sonos devices for announcements. The script allows me to set the levels, voice and rooms where the announcement is made.

      Click image for larger version

Name:	Capture3.PNG
Views:	1
Size:	50.0 KB
ID:	1197332

      The script is run any time a door or window is opened with these events. They are triggered by Easy Trigger group triggers. We can optionally have the system announce when any door or window is opened.

      Click image for larger version

Name:	Capture4.PNG
Views:	1
Size:	55.4 KB
ID:	1197335

      I also run the script to check doors and windows on a schedule to make sure it is absolutely current.

      I also have broken the virtual devices into subgroups of doors and windows, so that I can separate the house from two outbuildings and a back porch.

      Click image for larger version

Name:	Capture5.PNG
Views:	1
Size:	43.8 KB
ID:	1197337

      Hopefully this makes sense. If not, ask away
      Last edited by randy; July 2, 2018, 05:47 PM.
      HS4 Pro, 4.2.19.0 Windows 10 pro, Supermicro LP Xeon

      Comment


        #4
        Thank you both. I will try both solutions. Learning as I go and I appreciate the help.

        Comment


          #5
          Randy, thanks for sharing the script and events. Works perfect.

          Comment


            #6
            I created an easy trigger group with my doors in it. I edited the script with the ref id's. I created the door/window, check doors and check windows events. When I open a door, the icon on the door virtual device changes but the wording does not change. i get the following in the logs



            Jul-05 5:10:04 PM EasyTrigger ERROR SetDeviceValue: Cannot find control value 0 for device 547
            Jul-05 5:10:04 PM EasyTrigger ERROR SetDeviceValue: Cannot find control value 0 for device 250
            Jul-05 5:10:04 PM EasyTrigger ERROR SetDeviceValue: Cannot find control value 0 for device 223
            Jul-05 5:10:04 PM EasyTrigger ERROR SetDeviceValue: Cannot find control value 0 for device 253
            Jul-05 5:10:04 PM EasyTrigger ERROR SetDeviceValue: Cannot find control value 0 for device 245
            Jul-05 5:10:04 PM EasyTrigger ERROR SetDeviceValue: Cannot find control value 0 for device 259
            Jul-05 5:10:04 PM EasyTrigger ERROR SetDeviceValue: Cannot find control value 0 for device 269

            I have no idea on this one. Any thoughts?

            Comment


              #7
              Originally posted by keithj69 View Post
              I created an easy trigger group with my doors in it. I edited the script with the ref id's. I created the door/window, check doors and check windows events. When I open a door, the icon on the door virtual device changes but the wording does not change. i get the following in the logs



              Jul-05 5:10:04 PM EasyTrigger ERROR SetDeviceValue: Cannot find control value 0 for device 547
              Jul-05 5:10:04 PM EasyTrigger ERROR SetDeviceValue: Cannot find control value 0 for device 250
              Jul-05 5:10:04 PM EasyTrigger ERROR SetDeviceValue: Cannot find control value 0 for device 223
              Jul-05 5:10:04 PM EasyTrigger ERROR SetDeviceValue: Cannot find control value 0 for device 253
              Jul-05 5:10:04 PM EasyTrigger ERROR SetDeviceValue: Cannot find control value 0 for device 245
              Jul-05 5:10:04 PM EasyTrigger ERROR SetDeviceValue: Cannot find control value 0 for device 259
              Jul-05 5:10:04 PM EasyTrigger ERROR SetDeviceValue: Cannot find control value 0 for device 269

              I have no idea on this one. Any thoughts?
              I don't know. It is an Easy Trigger error where it seems to be trying to control a device that has no control values. It almost looks like an Easy Trigger action to set a group of devices. I'm thinking you are trying to set the values of your door/window sensor group, which are not controllable by an event. Can you post a screenshot of the event that is causing the errors? The event should be logged just before these errors.
              HS4 Pro, 4.2.19.0 Windows 10 pro, Supermicro LP Xeon

              Comment


                #8
                Click image for larger version

Name:	Screenshot 2018-07-05 at 7.21.22 PM.jpg
Views:	1
Size:	44.2 KB
ID:	1197382

                Click image for larger version

Name:	Screenshot 2018-07-05 at 7.20.53 PM.jpg
Views:	1
Size:	58.9 KB
ID:	1197383

                Comment


                  #9
                  Do I need to change anything on the status graphics status-control option? They are set as status, should they be set to both or control?

                  Comment


                    #10
                    Originally posted by keithj69 View Post
                    I set the status control to both on the virtual device and I am not getting the errors anymore. Only thing is the status never changes from "All Doors Closed".
                    Then I guess the errors were reference IDs of your virtual devices. They do not need to have standard Off and On controls. The script writes to the string of the virtual devices as well as setting the value. Could you post your script? That will probably prompt some more questions.

                    When I get to a computer, I will post the status graphics tab from one.
                    HS4 Pro, 4.2.19.0 Windows 10 pro, Supermicro LP Xeon

                    Comment


                      #11
                      Originally posted by keithj69 View Post
                      I created an easy trigger group with my doors in it. I edited the script with the ref id's. I created the door/window, check doors and check windows events. When I open a door, the icon on the door virtual device changes but the wording does not change. i get the following in the logs



                      Jul-05 5:10:04 PM EasyTrigger ERROR SetDeviceValue: Cannot find control value 0 for device 547
                      Jul-05 5:10:04 PM EasyTrigger ERROR SetDeviceValue: Cannot find control value 0 for device 250
                      Jul-05 5:10:04 PM EasyTrigger ERROR SetDeviceValue: Cannot find control value 0 for device 223
                      Jul-05 5:10:04 PM EasyTrigger ERROR SetDeviceValue: Cannot find control value 0 for device 253
                      Jul-05 5:10:04 PM EasyTrigger ERROR SetDeviceValue: Cannot find control value 0 for device 245
                      Jul-05 5:10:04 PM EasyTrigger ERROR SetDeviceValue: Cannot find control value 0 for device 259
                      Jul-05 5:10:04 PM EasyTrigger ERROR SetDeviceValue: Cannot find control value 0 for device 269

                      I have no idea on this one. Any thoughts?
                      What are each of the devices referenced in the errors?
                      HS4 Pro, 4.2.19.0 Windows 10 pro, Supermicro LP Xeon

                      Comment


                        #12
                        Originally posted by rprade View Post
                        Then I guess the errors were reference IDs of your virtual devices. They do not need to have standard Off and On controls. The script writes to the string of the virtual devices. Could you post your script? That will probably prompt some more questions.
                        I lied the errors are still happening. It happens when I open the door.

                        Code:
                        'these are the virtual devices to be updated by the script
                        '1542	Windows
                        '1530   Doors
                        
                        'Use the reference ID of the door or window sensor devices in the arrays below
                        
                        dim array_windows() as string = {"1537", "1534"}
                        
                        dim array_doors() as string = {"269", "259", "245", "253", "223", "250", "547"}
                        
                        dim windows_count as integer = 0
                        dim window_name as string = ""
                        dim wstr as string = ""
                        
                        dim doors_count as integer = 0
                        dim door_name as String = ""
                        dim dstr as string = ""
                        
                        Dim dv as Object
                        
                        'Using 2 subs, one for doors and the other for windows
                        
                        'WINDOWS
                        sub windows(ByVal Parms as Object)
                        Try
                        windows_count = 0
                        window_name = ""
                        wstr = ""
                        for each devw as string in array_windows
                                'hs.writelog("Array", "Window " & window_name & " | Value " & hs.DeviceValue(devw))
                        	if hs.DeviceValue(devw) = 1 then
                                        windows_count = windows_count + 1
                        		dv = hs.GetDeviceByRef(devw)
                        		window_name =  dv.Name(hs)
                               		wstr = wstr & window_name & ",<br>"
                        	hs.writelog("DoorWindow", window_name & " Open")
                        	'hs.writelog("DoorWindow", array_windows)
                                end if
                        next
                        	If windows_count > 0 then 
                        		hs.SetDeviceValueByRef(1542,100,true)
                        		hs.SetDeviceString(1542, wstr,true)
                        	Else
                        		hs.SetDeviceValueByRef(1542,0,true)
                        		hs.SetDeviceString(1542, "All Windows Closed",true)
                        	End If
                        	
                        	hs.writelog("DoorWindow", "Window Count: " & windows_count)
                        
                        Catch ex As Exception
                        hs.WriteLog ("DoorWindow", "Error: " & ex.Message)
                        End Try
                        
                        End Sub
                        
                        'DOORS
                        sub doors(ByVal Parms as Object)
                        Try
                        doors_count = 0
                        door_name = ""
                        dstr = ""
                        for each devd as string in array_doors
                                'hs.writelog("Array", "Door " & door_name & " | Value " & hs.DeviceValue(devd))
                        	if hs.DeviceValue(devd) = 1 then
                        		dv = hs.GetDeviceByRef(devd)
                        		door_name =  dv.Name(hs)
                        		doors_count = doors_count + 1
                        		dstr = dstr & door_name & ",<br>"
                        	hs.writelog("DoorWindow", door_name & " Open")
                                end if
                        next
                        	If doors_count > 0 then 
                        		hs.SetDeviceValueByRef(1530,100,true)
                        		hs.SetDeviceString(1530, dstr,true)
                        	Else
                        		hs.SetDeviceValueByRef(1530,0,true)
                        		hs.SetDeviceString(1530, "All Doors Closed",true)
                        	End If
                        
                        	hs.writelog("DoorWindow", "Door Count: " & doors_count)
                        
                        Catch ex As Exception
                        hs.WriteLog ("DoorWindow", "Error: " & ex.Message)
                        End Try
                        
                        End Sub

                        Comment


                          #13
                          The devices in reference are the open/close sensors on the door.

                          Comment


                            #14
                            Originally posted by keithj69 View Post
                            The devices in reference are the open/close sensors on the door.
                            Then I really have no idea why you were getting the errors. None of your posted events could cause them.

                            In any event... Set your virtual devices like this

                            Click image for larger version

Name:	Capture.jpg
Views:	1
Size:	72.6 KB
ID:	1197384

                            Click image for larger version

Name:	Capture1.PNG
Views:	1
Size:	72.7 KB
ID:	1197385

                            They are status only devices, the script controls them. Note the values of 0 for closed and 100 for open, the standard Off and On values for a virtual device.

                            Also check your door and window sensors for their open and closed values. They must use 0 and 1 for closed and open. If they use 0 and 100, the script will need to be modified.

                            EDIT:

                            When the virtual device is set, the value for Open will be 100 and the string should contain the open doors or windows.

                            Click image for larger version

Name:	Capture2.PNG
Views:	1
Size:	60.5 KB
ID:	1197386
                            HS4 Pro, 4.2.19.0 Windows 10 pro, Supermicro LP Xeon

                            Comment


                              #15
                              Originally posted by rprade View Post
                              They are status only devices, the script controls them. Note the values of 0 for closed and 100 for open, the standard Off and On values for a virtual device.

                              Also check your door and window sensors for their open and closed values. They must use 0 and 1 for closed and open. If they use 0 and 100, the script will need to be modified.
                              Adjustments made as the door sensors were 255 for open and the windows were 100. Thank you. Working great now. Thank you for the help.

                              Comment

                              Working...
                              X