Announcement

Collapse
No announcement yet.

Can we declare constants in homeseer?

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

  • sparkman
    replied
    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 ;-)

    Leave a comment:


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

    Leave a comment:


  • AllHailJ
    replied
    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

    Leave a comment:


  • deloosem
    replied
    I will look into the GetINI / SaveInI"Section/setting) thx

    Leave a comment:


  • aa6vh
    replied
    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.

    Leave a comment:


  • deloosem
    replied
    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.




    Leave a comment:


  • phillb
    replied
    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

    Leave a comment:


  • sparkman
    replied
    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.

    Leave a comment:


  • Uncle Michael
    replied
    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.

    Leave a comment:


  • deloosem
    started a topic Can we declare constants in homeseer?

    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?
Working...
X