Announcement

Collapse
No announcement yet.

X-10 device firing a script that controls the same device - is there a better way?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    X-10 device firing a script that controls the same device - is there a better way?

    In the following, V1 is a virtual device, A6 is a Switchlinc V2 (controlling deck lights) being tracked by the virtual device, and B2 is another X-10 switch controlling landscape lights.

    the first tap turns A6 ON,
    the second turns B1 ON and A6 OFF,
    the third turns A6 ON, leaving B1 ON,
    the fourth turn both OFF, and so on.

    The effect is:

    tap 1 = deck lights ON, tap 2 = landscape lights ON, Deck lights OFF, tap 3 = both ON, tap 4 = Both OFF

    Thanks to Gogs for his help in learning how scripting works, and the basic logic for this approach


    Am I asking for trouble using A6 to trigger a script that changes the state of A6?

    Is there a better way to accomplish the same end?

    Lastly, should I tick the "Wait for the script to finish" box? There seems to be a delay that I can't account for. . .








    Sub main()
    dim x
    x=hs.DeviceValue ("v1")
    if x=0 then
    hs.execX10 "A6","ON"
    hs.SetDeviceValue "v1",1
    exit sub
    end if
    if x=1 then
    hs.ExecX10 "A6","OFF"
    hs.execX10 "B2","ON"
    hs.SetDeviceValue "v1",2
    exit sub
    end if
    if x=2 then
    hs.ExecX10 "A6","ON"
    hs.SetDeviceValue "v1",3
    exit sub
    end if
    if x=3 then
    hs.ExecX10 "A6","OFF"
    hs.ExecX10 "B2","OFF"
    hs.SetDeviceValue "v1",0
    exit sub
    end if
    end sub




    The next script is associated with A6 OFF, which turns OFF A6 and B2, and resets v1's value to 0:







    Sub main()


    dim x
    x=hs.DeviceValue ("v1")


    hs.SetDeviceValue "v1",0


    hs.ExecX10 "A6","OFF"
    hs.execX10 "B2","OFF"
    end sub






    #2
    If the trigger for your second script occurs when A6 goes OFF then there is no need to set if OFF again. There are situations that you need to be careful and the behavior you will experience will vary between versions of HS and the point at which these self-changing situations present themselves. It is best to avoid potential troublesome areas, but if you want to do something like this then just try on a test case and see what behavior is exhibited.

    Each ExecX10 for X10 devices will take a minimum of 1 second to execute. In situaitons where you just want to change status without actually sending something through the IO interface then use hs.SetDeviceStatus rather than hs.ExecX10. There is usually no need to wait for the command to actually be completed before ending the script. It is queued to be sent and you can leave the script immediately.

    What I do not understand in your logic is the A6 OFF event itself. It will trigger on your second step and fourth step in your sequence since both of these are turning A6 OFF.

    Comment


      #3

      What I do not understand in your logic is the A6 OFF event itself. It will trigger on your second step and fourth step in your sequence since both of these are turning A6 OFF.
      I was trying to wife proof it. The idea is that if the top of the paddle (A6 ON) is tapped more than 4 times, it resets the counter, and if the bottom of the paddle is tapped once (A6 OFF), it also resets the counter.

      I think I see your point though. Tapping the bottom of the paddle is physically turning A6 OFF, so there's no need to have hs.ExecX10 "A6","OFF" in that particular script.

      I suppose the best idea would be to replace the switchlinc with a keypadlinc and be done with it. . .

      Comment


        #4
        Thanks for the acknowledgement.

        As for the sake of creating a virtual device and what little time and space it takes to reference it, I personally would not use the same house and unit code.

        As Michael states in theory there is no need to duplicate this state, in practise i have found that HS does not always do thing in the order you would expect, so when trying to do this kind of thing have always used a virtual device that has no other purpose in life than stating what state the other device is in, if that makes any sense.

        There is a pay off in this. As you progress you can have other scripts whatever checking on what state that Virtual is in, can be a lot more reliable than checking on a Active Device state, there again could miss a last second change, also useful if you are using multiple conditions such as is it after midnight, do I want the lights to go out because I am still up etc.

        Ah the joys of Home Automation on this scale.

        There is no definitive answer to your question, but if you wish to play safe until you get a good grasp of whats going on, use Virtual to keep note of the state of devices for the purpose you are using them.
        sigpic
        A founder member of "The HA Pioneer Group" otherwise known as the "Old farts club!"

        Comment

        Working...
        X