Announcement

Collapse
No announcement yet.

vDevice state based on states from multiple devices - easier way?

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

    #16
    Originally posted by Ltek View Post
    I recommend using the script. It works well AND FAR more efficient, flexible and faster to create/change when adding devices, functionality, etc.
    I've figured out that HS3's event engine is fine for basic things but tedious and inefficient for most things.
    While I agree with you on a script being more efficient for something like this, I'm nonetheless reminded of the book by Richard Carlson, "Don't Sweat the Small Stuff... and It's All Small Stuff." I find the a great deal of what I want HS to do is very easily done without scripts. (I'd say about 75% of the tasks in my HS installation are accomplished with script-less events.)
    Mike____________________________________________________________ __________________
    HS3 Pro Edition 3.0.0.548, NUC i3

    HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

    Comment


      #17
      Originally posted by Monk View Post
      SO - my value for
      hs.DeviceValueByName(devw)
      must be something other than 100 or 255.
      It runs and changes my virtual device to off because the Motions_count always states 0 in the log regardless of the state of the motion sensor device being off or on.

      OK - I see I'm missing something - in testing I was manually triggering the event.
      This might be to advanced for me
      devw is set to a string from the
      dim array_motion() as string = {"Hall Motion Sensor","Front door motion sensor","Garage Motion Sensor"}

      in the command
      for each devw as string in array_motion

      so the first time it runs devw = Hall Motion Sensor which then gets the status of the Hall Motion Sensor, next loop Hall Motion Sensor and so on. So if you have more motion sensors or add mor at a later stage you just add them to the array

      and Hall Motion Sensor,Front door motion sensor,Garage Motion Sensor are just the names of my motion sensor devices. Its not the root deice, see below





      Hope that makes sense
      Attached Files

      Comment


        #18
        Originally posted by mikee123 View Post
        devw is set to a string from the
        dim array_motion() as string = {"Hall Motion Sensor","Front door motion sensor","Garage Motion Sensor"}

        in the command
        for each devw as string in array_motion

        so the first time it runs devw = Hall Motion Sensor which then gets the status of the Hall Motion Sensor, next loop Hall Motion Sensor and so on. So if you have more motion sensors or add mor at a later stage you just add them to the array

        and Hall Motion Sensor,Front door motion sensor,Garage Motion Sensor are just the names of my motion sensor devices. Its not the root deice, see below





        Hope that makes sense
        yes it makes sense. but my usage always returns "0".
        The motion sensors I monitor do not have a value of 100. Like a virtual device or other device might have to indicate they are on.

        so within here:

        for each devw as string in array_motion
        if hs.DeviceValueByName(devw) = 255 or hs.DeviceValueByName(devw) = 100 then
        motions_count = motions_count + 1
        motion_name = devw
        wstr = wstr & motion_name & " <span style='color:red'>MOTION</span>" & "<br>"
        Else If hs.DeviceValueByName(devw) = 0 then
        end if

        When it gets to:

        motions_count = motions_count + 1
        mine never increments.

        here is what I have for my motion devices

        dim array_motion() as string = {"Motion 2 BSMT","Motion 3 BSMT","Motion Stairs"}

        So here are what my device info looks like and I think the "advanced tab" where it shows "supports status" might be the answer why - ?

        Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	10.4 KB
ID:	1191060


        Click image for larger version

Name:	Capture2.PNG
Views:	1
Size:	13.5 KB
ID:	1191061


        Thanks so much for your time!

        Comment


          #19
          This is the 3rd tab:

          Click image for larger version

Name:	Capture3.PNG
Views:	1
Size:	25.3 KB
ID:	1191062

          Comment


            #20
            Originally posted by Uncle Michael View Post
            While I agree with you on a script being more efficient for something like this, I'm nonetheless reminded of the book by Richard Carlson, "Don't Sweat the Small Stuff... and It's All Small Stuff." I find the a great deal of what I want HS to do is very easily done without scripts. (I'd say about 75% of the tasks in my HS installation are accomplished with script-less events.)
            +1

            https://en.wikipedia.org/wiki/Systemantics

            Comment


              #21
              Its a good way for me to learn things.

              And also sometimes fun -

              https://en.wikipedia.org/wiki/Rube_Goldberg_machine

              Comment


                #22
                Originally posted by Monk View Post
                Its a good way for me to learn things. And also sometimes fun
                +1

                Sometimes the trip is more important than the destination. Or, as Tom Brokaw observed, "What we learn is more important that what we set out to do."
                Mike____________________________________________________________ __________________
                HS3 Pro Edition 3.0.0.548, NUC i3

                HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

                Comment


                  #23
                  If violated is motion in your case, you would have to change 100 or 255 to 3. If all your motion sensors show violated, and on the status page that is represented by 3, then you are there. I was going to suggest to look in the status page of the device what value you have for motion. Then just replace 100 or 255 by that number.
                  If it was for example trouble or violated, change 100 or 255 to 2 or 3

                  Comment


                    #24
                    Thanks for the reply. I had tried that with no luck. Maybe it has todo with the plugin I'm using.

                    Comment


                      #25
                      Greetings!
                      Giving this another try - problem that I didn't have before is the HS warning when I run it:

                      VB.Net script exception(0), re-starting: Object reference not set to an instance of an object.

                      Here is what I run:
                      Code:
                      dim array_motion() as string = {"Hall Motion Sensor","Front door motion sensor","Garage Motion Sensor"}
                      dim motions_count as integer = 0
                      dim motion_name as string = ""
                      dim wstr as string = ""
                      
                      sub motion(ByVal Parms as Object)
                      Try
                      motions_count = 0
                      motion_name = ""
                      wstr = ""
                       for each devw as string in array_motion
                          if hs.DeviceValueByName(devw) = 255 or hs.DeviceValueByName(devw) = 100 then
                              motions_count = motions_count + 1
                              motion_name = devw
                              wstr = wstr & motion_name & " <span style='color:red'>MOTION</span>" & "<br>"
                          Else If hs.DeviceValueByName(devw) = 0 then 
                          end if
                      next
                          If motions_count > 0 then 
                              hs.SetDeviceValueByRef(2136,100,true)
                              hs.SetDeviceString(2136, wstr,true)
                          Else
                              hs.SetDeviceValueByRef(2136,0,true)
                              hs.SetDeviceString(2136, "No Motion",true)
                          End If
                      
                          hs.writelog("Array", "Motion Sensor Count: " & motions_count)
                       Catch ex As Exception
                      hs.WriteLog ("Array", "Error: " & ex.Message)
                      End Try
                      End Sub
                      Not a programmer - can't seem to find the cause of the warning - am I missing something?

                      Comment


                        #26
                        So - it was suggested that I should call the sub "motion" when running the script..
                        Click image for larger version

Name:	Capture.PNG
Views:	33
Size:	27.2 KB
ID:	1279604

                        Which I tried - and obtained the same result.- the error in the log.
                        Jan-27 6:51:59 AM Warning VB.Net script exception(0), re-starting: Object reference not set to an instance of an object.
                        Any suggestions welcome!

                        Comment


                          #27
                          Someone else has now told me that this runs as expected - yet I have tried this on two separate systems thus far and get the same error. I really don't get it.

                          Comment


                            #28
                            My Tags plugin has triggers for all devices in a state, some devices (eg 6 of 10), no more than (no more than 4?out of 20) and none triggers.

                            Comment


                              #29
                              @monk
                              I built a script for this a year ago. Have you seen it? Search for Composite Device Status, in script library.

                              It's super easy to use and pretty flexible. You don't need to call out every device, it uses devices naming (rooms, name, etc) structure and exclusions (optional)

                              Simular to Tags plugin - which is more extensive. but my script is free so if you don't need more, it should save you time and money


                              Comment


                                #30
                                Thanks all. Especially those who saw the error of my ways!

                                Note to self -
                                There are two things I did not realize which kept me from success here.

                                1 - I was not calling the function "motion" from the event I was using to run the script. I had entered in in the "Parameters" section - NOT the "Sub or Function" section where it should have been. This allowed the script to run, but brought me back to my original problem.
                                2 - Originally I was not getting any data from the devices. This was because I was using only the device name. DeviceValueByName requires the location be provided as well.

                                So - when I added the "Location" to the device name all was good

                                Comment

                                Working...
                                X