Announcement

Collapse
No announcement yet.

Script to eval multiple devices and set virtual device value

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

    Script to eval multiple devices and set virtual device value

    Hello all,

    I'm trying to create a virtual device that holds the on/off state based on if *any* of the predefined lights are on or off.

    For example, I will have a virtual device called: vUPSTAIRS_LIGHTS with simple on/off value.

    IF any of the lights upstairs are turned on, then this virtual device value will change to ON.
    IF all of the lights upstairs are off, then this virtual device value will change to OFF.

    I have managed to get an event working with lots of OR IF/AND IF statements, but thought this could best be managed long-term (as device ID's are added/removed) via a script.

    Can someone give me an idea of how to accomplish this via scripting? I can figure out the vb logic, but I'm most confused by the actual trigger that executes the script.

    thank you,

    Marco

    #2
    The issue is that you will probably just end up with an event to run the script that has triggers about as complex as the one you already have. There are ways to avoid it (by having a callback whenever a device changes) but in reality I think that's overkill for this situation - that's best if you want to know in HS about changes to numerous devices that may be all over HS.

    The only way I could see it would be that you could get away with one event instead of two, you could have one event that triggered the script if *any* of the specified devices changed their value. Then in the script do the figuring out but I'm not sure that's really going to give you any value above doing it with two events.

    Comment


      #3
      I've an event running, which contains all the lights with OR statements. The action is a script, that update the devicestring of the virtual device. The script will run a html code, and on every line it will print which light is ON. When a light is OFF it will not be printed/visible.

      I've the same running for all door and window sensors, so I can easily see what door is OPEN, without checking all individual sensors.
      Attached Files

      Comment


        #4
        I made this script , https://www.domoticaforum.eu/viewtopic.php?f=47&t=11325


        Verzonden vanaf mijn iPhone met Tapatalk
        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


          #5
          Originally posted by Rutger View Post
          I've an event running, which contains all the lights with OR statements. The action is a script, that update the devicestring of the virtual device. The script will run a html code, and on every line it will print which light is ON. When a light is OFF it will not be printed/visible.

          I've the same running for all door and window sensors, so I can easily see what door is OPEN, without checking all individual sensors.
          Rutger,

          sounds pretty cool. Would you mind sharing that script?

          Comment


            #6
            Originally posted by Malosa View Post
            I made this script , https://www.domoticaforum.eu/viewtopic.php?f=47&t=11325


            Verzonden vanaf mijn iPhone met Tapatalk
            Malosa,

            I just looked at your advanced script. Pretty nice work. I think this may be an overkill for what I'm doing, and frankly, may be easier to just work with events. However, I'm thinking of other ways to utilize your script. It's got my brain working...

            Comment


              #7
              This script is fool proof and easy to use the manual is included. Just give iT a try


              Verzonden vanaf mijn iPhone met Tapatalk
              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