Announcement

Collapse
No announcement yet.

Looking for Advice for a workaround due to lack of an ELSE clause in events

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

  • Looking for Advice for a workaround due to lack of an ELSE clause in events

    I have both a projector & motorized screen and an LCD TV in my living room. I choose one or the other in my HSTouch application which sets a virtual device representing the choice. I then send a "turn on" command. This should activate the appropriate display device (as well as other things). For the projector/screen the projector should turn on (via IR command) and the screen should be lowered (via relay). In pseudo-code I would expect to write something like:

    Code:
    if ActiveDisplay == Projector then
        Turn on projector
        Lower screen
    Else
        Turn on TV
    EndIf
    Since there is no else clause available in events, I resorted to writing a script as follows:

    Code:
    Sub Main(parm as object)
        Dim activeDisplay
        activeDisplay = hs.DeviceValueByName("Display Active")
        'hs.WriteLog("msg", activeDisplay)
    
        If activeDisplay = 0 Then
            hs.WriteLog("msg", "ActivateDisplay: Projector")
            ' Lower screen
            hs.SetDeviceValueByName("Theater System Projector Screen", 100)
    
            ' Turn on projector
            hs.SetDeviceValueByName("Theater System Projector", 100)
    
        Else
            ' Turn on TV
            hs.WriteLog("msg", "ActivateDisplay: LCD")
            hs.SetDeviceValueByName("Theater System LCD TV", 100)
    
        End If
    End Sub
    This script is run from the following event:

    Click image for larger version

Name:	Capture3.PNG
Views:	29
Size:	336.4 KB
ID:	1292893

    "Theater System Projector Screen" and "Theater System Projector" are both virtual devices. There are events tied to changes in these devices to send the appropriate IR or relay commands. Devices and events are shown below.

    Another thought I had to do this without a script is to create two events - one for projector/screen and one for TV - and condition the events on the current value of the 'Display Active' virtual device. Then in my top level event I would call both of these events, only one of these would run depending on the value of the 'Display Active' device. Which of these approaches (if either) would be preferred? Is there anther approach that I am missing?

    Click image for larger version

Name:	Capture.PNG
Views:	38
Size:	45.5 KB
ID:	1292890

    Showing just the events for the projector and screen...

    Click image for larger version

Name:	Capture1.PNG
Views:	22
Size:	152.8 KB
ID:	1292891

    Click image for larger version

Name:	Capture2.PNG
Views:	22
Size:	395.8 KB
ID:	1292892

    I send the IR commands multiple times because something in the IR chain is flaky and it takes multiple tries to get the projector to turn on and off reliably. I will eventually switch to using RS-232 to control the projector, but that is a project for another day.

  • #2
    I find it useful to think of an event in terms of its actions, not it's trigger.
    To implement the scheme, you need three events. The first event has two actions to run each of the other events if their conditions are satisfied.

    Event 1:
    If this Event is manually triggered
    Then If the event conditions are true Run Event 2
    Then If the event conditions are true Run Event 3

    Event 2:
    If this Event is manually triggered
    And If [active display = projector]
    Then Turn on projector
    Then Lower Screen

    Event 3
    If this Event is manually triggered
    And If [active display <> projector]
    Then Turn on TV
    Mike____________________________________________________________ __________________
    HS3 Pro Edition 3.0.0.548

    HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF, Rain8Net+ | RFXCOM | QSE100D | Vantage Pro | Green-Eye | X10: XTB-232, -IIR | Edgeport/8 | Way2Call | Ecobee3

    Comment


    • #3
      That was the alternate, non-script way I was thinking of. Decided to try it. Works. And solves another problem I had run into.

      Comment

      Working...
      X