Announcement

Collapse
No announcement yet.

if statement in scripting

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

    if statement in scripting

    Hi All,

    Hoping someone might be able to let me know what i am doing wrong in the below. I have a TV which i control exclusively through a tablet / PC controller. When the device is turned ON, it changes the Virtual Device (Power On) to ON (T7), and when the power is turned off to the TV it turns the Virtual Device to OFF.

    What i would like to do, is to be able to hit a button on the HSTOUCH screen which determines what channel the TV needs to be set to, that part works well, but now instead of having to turn the TV on, i would like it to be able to turn the TV on, if it is already off, and then wait 15 seconds (the TV takes a while to start up) and then send the IR command to change the channel.

    I was hoping the code below would let me run an if statement which would wait, and then if the statement is not true, or if it finishes it would continue within the case and do the other things, for example if power is on it would skip the turn on power and wait, and just do the IR signals, but if power is off, it would turn it on, wait and then do the IR signals.

    Is there any way i can do that similar to my code below, the reason i want to avoid copying the IR code in an if, else statement is that there is around 35 - 40 different cases, so it would be easier if there was some way it would continue on, but it does not seem like it will.


    Code:
       Case 1
    'ONE
    if hs.DeviceValue("T7") = 2 then
    hs.triggerevent("POWER ON")
    hs.WaitSecs(15)
    end if
    
    hs.writelog("AV Controller","ONE")
    hs.sendIR("BAUHN,1,,")
    hs.sendIR("BAUHN,OK")
    HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

    Facebook | Twitter | Flickr | Google+ | Website | YouTube

    #2
    The If statement itself looks okay Travis. When you run the code what does it do? It could be that either triggerevent or waitsecs is not acting like you thought it would.
    HS Pro 3.0 | Linux Ubuntu 16.04 x64 virtualized under Proxmox (KVM)
    Hardware: Z-NET - W800 Serial - Digi PortServer TS/8 and TS/16 serial to Ethernet - Insteon PLM - RFXCOM - X10 Wireless
    Plugins: HSTouch iOS and Android, RFXCOM, BlueIris, BLLock, BLDSC, BLRF, Insteon PLM (MNSandler), Device History, Ecobee, BLRing, Kodi, UltraWeatherWU3
    Second home: Zee S2 with Z-Wave, CT101 Z-Wave Thermostat, Aeotec Z-Wave microswitches, HSM200 occupancy sensor, Ecolink Z-Wave door sensors, STI Driveway Monitor interfaced to Zee S2 GPIO pins.

    Comment


      #3
      Originally posted by travisdh View Post
      Code:
         Case 1
      'ONE
      if hs.DeviceValue("T7") = 2 then
      hs.triggerevent("POWER ON")
      hs.WaitSecs(15)
      end if
      
      hs.writelog("AV Controller","ONE")
      hs.sendIR("BAUHN,1,,")
      hs.sendIR("BAUHN,OK")
      I'm not sure if there is a typo in your post or in the actual code, but the If statement appears to be: if device T7 is ON, then turn power on.
      Should that be "if hs.DeviceValue("T7") = 3 then" ?
      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


        #4
        A device value of 2 for on is a bit unusual (but it could happen), usually 100 is on and 0 is off. A device status of 3 is off and 2 is on is more usual...do you mean hs.devicestatus? Another method is the more simple hs.ison/hs.isoff.

        Comment


          #5
          I actually went into the virtual device advanced settings, and had a look at the value that was being reported as "OFF", in this case it actually was 2.

          It appears when i click on the button that is meant to turn on the TV and pick the appropriate channel, it turns on the TV but the channel is not picked, almost like the waitsecs only applies within the if statement itself, is there any way i can selectively use the wait within an if statement and have it hold the rest of the script?
          HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

          Facebook | Twitter | Flickr | Google+ | Website | YouTube

          Comment


            #6
            Why not put the send ir commands in the power TV event with a delay before sending them?
            Dick
            HS PRO 2.5.0.81, WinXP, IE8, Shuttle XS35V3, 2.13GHz, 4GB, 40GB SSD drive, AC-RF2, ADIOcelot, Message Server, TI103, SNEVL CID, pjcOutlook, MCSTemperature, Powertrigger, BLBackup, BLFloorplan, BLIcon, BLOccupied, BLRadar, BLRfid, BLLogMonitor, ACPUPSD, UltraECM, WeatherXML & Stipus' script connector. 500+ devices, 260+ events, 1-wire weather station + temp/humidity sensors & Oregon Scientific temp & humidity sensors & 2 Brultech ECM-1240s

            Comment


              #7
              The reason was (or at least my logic), is to be able to pick a channel to watch (e.g. 10) and hit that button, the system would work out then if the TV is in, and if so it would send the IR signal, if not it would run the TV on event, wait 12 seconds for the TV to turn on, then send the appropriate channel.

              There are around 26 channels i will eventually program in, so that is why i was looking at having them seperate, then i could call the event if needed, and the IR signal afterwards.

              As a general habit, i normally go event crazy and have way to many events so wanted to move towards having more in a script, then that way if things change, or the TV changes, i can easily update the script in one simple replace command ,
              HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

              Facebook | Twitter | Flickr | Google+ | Website | YouTube

              Comment


                #8
                Originally posted by travisdh View Post
                It appears when i click on the button that is meant to turn on the TV and pick the appropriate channel, it turns on the TV but the channel is not picked, almost like the waitsecs only applies within the if statement itself, is there any way i can selectively use the wait within an if statement and have it hold the rest of the script?
                One more idea. Maybe you need an executable statement after the wait, but inside the If. You might try adding a writelog statement right after the waitsecs. At least it might give you some insight into the sequence in which the statements are being executed.
                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


                  #9
                  Originally posted by travisdh View Post
                  It appears when i click on the button that is meant to turn on the TV and pick the appropriate channel, it turns on the TV but the channel is not picked, almost like the waitsecs only applies within the if statement itself, is there any way i can selectively use the wait within an if statement and have it hold the rest of the script?
                  The wait statement will hold up the reset of script execution. My guess is that your script is terminating after the hs.triggerevent statement. A writelog after that statement will confirm if that's the case. Also, you may want to use hs.TriggerEventAndWait instead of hs.TriggerEvent. That will force your script to wait until the event completes before moving on.
                  HS Pro 3.0 | Linux Ubuntu 16.04 x64 virtualized under Proxmox (KVM)
                  Hardware: Z-NET - W800 Serial - Digi PortServer TS/8 and TS/16 serial to Ethernet - Insteon PLM - RFXCOM - X10 Wireless
                  Plugins: HSTouch iOS and Android, RFXCOM, BlueIris, BLLock, BLDSC, BLRF, Insteon PLM (MNSandler), Device History, Ecobee, BLRing, Kodi, UltraWeatherWU3
                  Second home: Zee S2 with Z-Wave, CT101 Z-Wave Thermostat, Aeotec Z-Wave microswitches, HSM200 occupancy sensor, Ecolink Z-Wave door sensors, STI Driveway Monitor interfaced to Zee S2 GPIO pins.

                  Comment

                  Working...
                  X