Announcement

Collapse
No announcement yet.

Javascript If Then question

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

    Javascript If Then question

    I am trying to have the text on a page change color depending on the status of one of my devices. I've got all the code working except the if statement for setting the hex value used in the color statement.
    Here's the code I'm having trouble with. I'm guessing I'm missing something that let' it evaluate the device status properly.

    var hex="666666";
    var hds=hs.devicestatus("V26")
    if(hds<3){
    hex="00FF00";
    }

    If I replace the "var hds=hs.devicestatus("V26")" line with "hds=2" or "hds=3" it works OK.
    Any ideas what I'm missing?
    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

    #2
    Try:
    Code:
    var hex="666666";
    var hds=parseInt(hs.devicestatus("V26"))
    if(hds<3){
    hex="00FF00";
    }
    💁‍♂️ Support & Customer Service 🙋‍♂️ Sales Questions 🛒 Shop HomeSeer Products

    Comment


      #3
      Originally posted by Rupp View Post
      Try:
      Code:
      var hex="666666";
      var hds=parseInt(hs.devicestatus("V26"));
      if(hds<3){
      hex="00FF00";
      }
      Nope... apparently hs.devicestatus (fyi, I also tried hs.ison) doesn't return anything or at least nothing that an be interpreted/converted and acted upon by the if statement.

      Anyone else have any other ideas?
      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


        #4
        javascript is executed in the browser, whereas the HS object exists on the server, so you wont be able to access HS with this method. If the page is an ASP page, then you would be able to access the HS object and set the color as needed:

        PHP Code:
        if(hs.deviceStatus("_9")=2then     'on
           cls="'
        tablecellon'"
        else
           cls="'
        tablecelloff'"
        end if
        response.write "<td class=" & cls & ">" & GetDeviceName("_9") & "</td>" 
        HS4Pro on a Raspberry Pi4
        54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
        Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

        HSTouch Clients: 1 Android

        Comment

        Working...
        X