Announcement

Collapse
No announcement yet.

Setting a device value to a variable

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

    Setting a device value to a variable

    I am trying to set a device vale to a variable. I am using "a = hs.DeviceValue(2395)
    a=a+1
    hs.SetDeviceValueByRef(2404, a, True)", does not work.

    any ideas?
    sigpic
    A founder member of "The HA Pioneer Group" otherwise known as the "Old farts club!"

    #2
    has 'a' been declared in a Dim statement?

    How about hs.SetDeviceValueByRef(2404, hs.DeviceValue(2395), True)?

    I do not expect type conversion issues, but by memory is that DeviceValue is an integer and SetDeviceValue is a Double. Explicit type management may be needed. I think there is a method DeviceValueEx that returns a Double.

    Comment


      #3
      The following works for me (I changed DevRef to match my system):

      Code:
      Dim a As Integer
      a = hs.DeviceValue(1777)
      a = a + 1
      hs.SetDeviceValueByRef(1777, a, True)
      tenholde

      Comment


        #4
        Thanks tenholde, I get his error
        Dec-08 10:41:29 Error Running script, script run or compile error in file: C:/Program Files (x86)/HomeSeer HS3/scripts/Temp up.txt1025:Expected end of statement in line 2 More info: Expected end of statement/quote
        My full script is

        sub main()
        Dim a As Integer
        a = hs.DeviceValue(2395)
        a = a + 1
        hs.SetDeviceValueByRef(2395, a, True)
        end sub
        sigpic
        A founder member of "The HA Pioneer Group" otherwise known as the "Old farts club!"

        Comment


          #5
          Try this. Make sure it has a script name with a .vb extension (not .txt)

          Code:
              Sub Main(ByVal Parm As Object)
                  Dim a As Integer
                  a = hs.DeviceValue(2395)
                  a = a + 1
                  hs.SetDeviceValueByRef(2395, a, True)
              End Sub
          Jon

          Comment


            #6
            Thanks for your help. I fumbled about till I eventually got it to work! Final txt script is this:

            sub main()
            Dim a
            a = hs.DeviceValue(2395)
            a = a + 1
            if a=30 then
            a=5
            end if
            hs.SetDeviceValueByRef(2395), a, (True)
            end sub

            Thanks again.
            sigpic
            A founder member of "The HA Pioneer Group" otherwise known as the "Old farts club!"

            Comment


              #7
              You need to wean yourself off VBScript... its not even supported on Linux HS systems 😉
              Jon

              Comment


                #8
                😉
                sigpic
                A founder member of "The HA Pioneer Group" otherwise known as the "Old farts club!"

                Comment


                  #9
                  Originally posted by jon00 View Post
                  You need to wean yourself off VBScript... its not even supported on Linux HS systems 😉
                  OK thought I would try modifying one of your scripts, immediately got into sh1. trying to set the time of a event to variable, My latest disaster is :-

                  Sub Main(ByVal Parm As Object)

                  Dim h As Integer
                  dim m As Integer
                  dim s As Integer

                  hs.enableevent("GC Alarm")

                  h = hs.DeviceValue(2405)
                  m = hs.DeviceValue(2406)
                  s = "00"



                  Dim d As Date = DateTime.Parse(DateTime.Today.AddDays(1),h,m,s)
                  Dim RefVal As Integer = hs.GetEventRefByName("GC Alarm")
                  Dim res As Boolean = hs.EventSetTimeTrigger(RefVal, d)
                  hs.SaveEventsDevices()
                  hs.EnableEvent("GC Alarm")
                  hs.speak ("Gordon's alarm set for 03:40")
                  hs.SetDeviceString(819, "03:10", True)
                  hs.CAPIControlHandler(hs.CAPIGetSingleControl(729,true ,"on",false,true))


                  End Sub

                  I know it's a mess.

                  can anyone help?
                  sigpic
                  A founder member of "The HA Pioneer Group" otherwise known as the "Old farts club!"

                  Comment


                    #10
                    Code:
                    Dim d As Date = DateTime.Parse(DateTime.Today.AddDays(1).AddHours(h).AddMinutes(m).AddSeconds(s))
                    Jon

                    Comment


                      #11
                      Thanks Jon00, worked perfectly.
                      sigpic
                      A founder member of "The HA Pioneer Group" otherwise known as the "Old farts club!"

                      Comment


                        #12
                        Is vbscript still supported on hs4 for windows?
                        HS3PRO 3.0.0.500 as a Fire Daemon service, Windows 2016 Server Std Intel Core i5 PC HTPC Slim SFF 4GB, 120GB SSD drive, WLG800, RFXCom, TI103,NetCam, UltraNetcam3, BLBackup, CurrentCost 3P Rain8Net, MCsSprinker, HSTouch, Ademco Security plugin/AD2USB, JowiHue, various Oregon Scientific temp/humidity sensors, Z-Net, Zsmoke, Aeron Labs micro switches, Amazon Echo Dots, WS+, WD+ ... on and on.

                        Comment


                          #13
                          Originally posted by langenet View Post
                          Is vbscript still supported on hs4 for windows?
                          Yes!
                          Jon

                          Comment


                            #14
                            Originally posted by jon00 View Post
                            You need to wean yourself off VBScript... its not even supported on Linux HS systems 😉
                            What do you recommend over VBScript? (Please don't say C#! What a mess!)


                            Jim Speiser
                            38-year veteran of Home Automation
                            Still don't know squat

                            Comment


                              #15
                              IBM System 370 machine language!

                              If you wrote operating system code the Load PSW (LPSW) command was your best buddy and forgiver of sins! LOL

                              Comment

                              Working...
                              X