Announcement

Collapse
No announcement yet.

Can we declare constants in homeseer?

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

  • Can we declare constants in homeseer?

    I am writing a script that needs some values that dont or never change.
    Variables are not saved when the system restarts so they can't be used unless I populate them with in the startup.vb

    Sorry I am new to homeseer, I came from Fibaro and there we could set a variable that stayed even if we restarted the system.
    So I am still trying to get this puzzle called homeseer together

    In short can we declare constants or how do you guys handle that?

  • #2
    In HS, virtual devices can serve as variables. If you assign a value to a virtual device it can be retrieved (and changed) by a script and will be retained through a system restart.
    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
      You could also store them in an INI file in the config folder and then use the HS scripting functions for INI files to retrieve them.
      HS 3.0.0.548: 1976 Devices 1156 Events
      Z-Wave 3.0.1.262: 123 Nodes on one Z-Net

      Comment


      • #4
        So if they never change can you not just hard code in VB script. Ie

        Dim Pi = 3.14

        the use Pi in the equation so if the radius was a variable that changes occasionally do as suggested store it in a virtual device with SetDeviceValue and retrieve it as needed with DeviceValueEx

        a = Pi * DeviceValueEx(devref) ^ 2

        Comment


        • #5
          Originally posted by phillb View Post
          So if they never change can you not just hard code in VB script. Ie

          Dim Pi = 3.14

          the use Pi in the equation so if the radius was a variable that changes occasionally do as suggested store it in a virtual device with SetDeviceValue and retrieve it as needed with DeviceValueEx

          a = Pi * DeviceValueEx(devref) ^ 2
          They hardly change but they can seasonal. So I need a way of storing.

          The virtual device option might be good.

          I gues I can store strings in a virtual device. But It might be intresting to store a json string (that was how I did it with fibaro).
          And the retrieve the "const vars" that I need.




          Comment


          • #6
            Virtual switches are good, and I use them for stuff I want to be visible. But for storing multiple related values, I think the .ini files are the better way to go. I have a morning alarm clock with different default wake up times during the week, and I store those default times in an .ini file. Ini files are not all that efficient, but then again having 14 additional virtual switches would not be very efficient either.

            Scripting does allow you to read and write normal disk files. If you have data that does not fit well with what is readily available, perhaps just write and read the data directly from a disk file.

            Comment


            • #7
              I will look into the GetINI / SaveInI"Section/setting) thx

              Comment


              • #8
                I do something similar with my sprinkler control.

                The setup for the variables is done in Startup.vb

                Dim FQPN As String = "Watering6120.ini"
                Dim ZoneTime As Integer = hs.GetINISetting("Watering", "ZoneTime", "540", FQPN) 'Create a default
                Dim FlowerTime As Integer = hs.GetINISetting("Watering", "FlowerTime", "960", FQPN)'Create a default
                Dim sCycles As Integer = hs.GetINISetting("Watering", "SoakCycles", "1", FQPN) 'Create a default

                I create the global variables at start up

                'Create the global variables needed
                '7-3-2019 Add Watering Global variables.
                '-------------------------------------------

                errst = hs.CreateVar("zntime")
                errst = hs.CreateVar("znflwrtime")
                errst = hs.CreateVar("soakcycles")


                errst = hs.SaveVar("zntime",ZoneTime)
                errst = hs.SaveVar("znflwrtime",FlowerTime)
                errst = hs.SaveVar("soakcycles",sCycles)

                I have a script run from HSTouch that allows me to control the variable and write to the ini file. See Below


                IMPORTS System.IO
                IMPORTS System.Net
                IMPORTS System.Threading


                Sub Main(ByVal Parm As Object)

                Dim ZoneTime As Integer = hs.GetVar("zntime") 'Min should be 1
                Dim sZoneTime As String
                Dim errst

                ZoneTime = ZoneTime + 15
                If ZoneTime > 1800 Then
                ZoneTime = 1800
                End If


                sZoneTime = CStr(ZoneTime)
                errst = hs.SaveVar("zntime", ZoneTime)
                hs.SaveINISetting("Watering", "ZoneTime", sZoneTime, "Watering6120.ini")

                End Sub


                Here is the ini file

                [Watering]
                ZoneTime=390
                FlowerTime=720
                SoakCycles=4


                Hope this helps

                Comment


                • #9
                  just noticed a faux paux on my part - should be startup.vb not startup.ini

                  Comment


                  • #10
                    Originally posted by AllHailJ View Post
                    just noticed a faux paux on my part - should be startup.vb not startup.ini
                    You can edit your own posts and fix it ;-)
                    HS 3.0.0.548: 1976 Devices 1156 Events
                    Z-Wave 3.0.1.262: 123 Nodes on one Z-Net

                    Comment

                    Working...
                    X