Announcement

Collapse
No announcement yet.

Scripting with variables

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

    Scripting with variables

    I made this short script to get the latest weather warning from the weather XML plugin.

    Code:
    Sub Main(ByVal Params As Object)
    
    Dim AlrtTitle As String
    
    AlrtTitle = hs.GetVar("wxmlAlertTitle_1")
    
    hs.SetDeviceString( 1381, AlrtTitle, True)
    
    
    end sub
    How do set the device string to something else once the alert is over and the variable is no longer there?

    Thanks,
    Tim
    FB Page - https://www.facebook.com/pages/Capt-Tim/209398425902188

    HSTouch Layouts - https://www.facebook.com/media/set/?...5902188&type=3

    #2
    Originally posted by fungun View Post
    How do set the device string to something else once the alert is over and the variable is no longer there?
    To set the device string to something else, you need to repeat the hs.SetDeviceString function. If you want to remove the string and leave it blank set it to null:
    hs.SetDeviceString( 1381, "", True)
    (You can use an immediate script command if you want to do without creating another script.)
    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


      #3
      Hey Tim... Long time no talk...

      You probably can use the following as well. Note "desiredvariable" is the name of the variables contents that you want to put into the device string.

      hs.SetDeviceStringByName("Kitchen Counter Lights", desiredvariable, True)

      If not, then let me know.

      Make sense?
      HomeSeer 2, HomeSeer 3, Allonis myServer, Amazon Alexa Dots, ELK M1G, ISY 994i, HomeKit, BlueIris, and 6 "4k" Cameras using NVR, and integration between all of these systems. Home Automation since 1980.

      Comment


        #4
        I think I didn't explain it right.
        When a weather alert becomes active, the Weather-XML plugin creates a variable for that alert. Once the alert has expired, that variable is no longer accessible. It just disappears from the list of variables for Weather-XML.
        So if there is an alert I can use it, if there is no alert I want to put "No Active Alert" in the device string.

        Thanks,
        Tim
        FB Page - https://www.facebook.com/pages/Capt-Tim/209398425902188

        HSTouch Layouts - https://www.facebook.com/media/set/?...5902188&type=3

        Comment


          #5
          Sill can't figure this out.
          How do I tell the script to either use the variable (when it's available) or to use "No active alerts" (when it's not available) ?

          Thanks,
          Tim
          FB Page - https://www.facebook.com/pages/Capt-Tim/209398425902188

          HSTouch Layouts - https://www.facebook.com/media/set/?...5902188&type=3

          Comment


            #6
            I did this by creating a virtual device and two events. I can then use the virtual device value to set or remove messages.
            Attached Files
            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


              #7
              Originally posted by fungun View Post
              Sill can't figure this out.
              How do I tell the script to either use the variable (when it's available) or to use "No active alerts" (when it's not available) ?

              Thanks,
              Tim
              Try this:

              Code:
                  Sub Main(ByVal Params As Object)
              
                      Dim AlrtTitle As String
                      hs.CreateVar("wxmlAlertTitle_1")
                      AlrtTitle = hs.GetVar("wxmlAlertTitle_1")
                      If AlrtTitle = "" Then
                          hs.SetDeviceString(1381, "No active alerts", True)
                      Else
                          hs.SetDeviceString(1381, AlrtTitle, True)
                      End If
                  End Sub
              Jon

              Comment


                #8
                Thank you, Jon
                It works for now, will have to wait for a weather warning now.

                Thanks,
                Tim
                FB Page - https://www.facebook.com/pages/Capt-Tim/209398425902188

                HSTouch Layouts - https://www.facebook.com/media/set/?...5902188&type=3

                Comment

                Working...
                X