Announcement

Collapse
No announcement yet.

Operations with Device

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

    Operations with Device

    Hi all,
    I have just installed HS3 and being a newbie, would like some help for the following:
    I have a device that brings back the value of a gaz value (ex :254362). This value increases according to the gaz consumption every minute or hours or days depending of the usage (shower / heating system).
    I would like to have , through the use of a counter or a script, the real consumption between two dates (or minutes).
    Is it possible to do this with the new "event" system or should it be a script ?
    If so, I am not a programmer so I would appreciate some help with the script....
    Thanks a lot in advance
    Regards

    #2
    Operations with Device

    Any help ?
    Thanks

    Comment


      #3
      You could achieve this with an event and script command, but I think it would be easier to implement and maintain later using a small script. Remember that global variables are removed on reboot, so you'll need some other way of persistently keeping the 'previous' value for your calculations.

      I'd suggest an INI file but if you don't mind the 'clutter' you could use a virtual device in HS and write the old value there after you perform your calculations.

      Shout if you need further help.


      Sent from my iPad using Tapatalk HD
      Author of Highpeak Plugins | SMS-Gateway Plugin | Blue Iris Plugin | Paradox (Beta) Plugin | Modbus Plugin | Yamaha Plugin

      Comment


        #4
        Operations with device

        Thanks a lot for your answer.
        I am really a newbie so would appreciate a script model to make what you recommended ?
        Not sure how to make the addition.....
        Could you indicate the different steps to perform ?
        Thanks a lot
        Regards

        Comment


          #5
          Sorry for the delay, I missed your response. Try something like this:

          PHP Code:
          Public Sub Main(ByVal parms As String)
                  
          Dim parm() As String
                  parm 
          parms.Split("|")
                  If 
          parm.Count <> 2 Then
                      hs
          .WriteLog("Error""Usage: Send two integers separated by '|'.  Device ref of counter, Device ref of virtual usage device (e.g. Main(""100|101"")")
                      Exit 
          Sub
                  End 
          If
                  
          Dim GasCounterDevice As Integer CInt(parm(0))
                  
          Dim VirtualUsageDevice As Integer CInt(parm(1))
                  
          Dim OldValue As Integer CInt(hs.GetINISetting("data""PreviousValue"0"GASDATA.INI"))
                  
          Dim CurrentValue As Integer hs.DeviceValue(GasCounterDevice)
                  
          Dim Usage As Integer CurrentValue OldValue
                  hs
          .WriteLog("Gas Usage""The gas usage since I last checked is " Usage.ToString())
                  
          hs.SetDeviceValueByRef(VirtualUsageDeviceUsageTrue)
                  
          hs.SaveINISetting("data""PreviousValue"CurrentValue.ToString"GASDATA.INI")
              
          End Sub 
          Save tihs to a script "Gas.vb" and put the file in your \scripts folder. Create a new virtual device in HomeSeer, note it's device reference ID (in the "Advanced" tab of the device). Note the device reference ID of your Gaz counter too.

          Create an event to run the script every 5 minutes and pass the script two parameters to the Main method, separated by '|' e.g. Main("320|150") - Counter first, virtual device second.

          It will moan about the INI file not being there the first time, but after that all should be good.
          Author of Highpeak Plugins | SMS-Gateway Plugin | Blue Iris Plugin | Paradox (Beta) Plugin | Modbus Plugin | Yamaha Plugin

          Comment


            #6
            operation with device

            Thanks a LOT for your help !!
            I will test this
            Regards

            Comment


              #7
              operation with device

              Hi,
              I followed the process from Berrygaz and got errors.
              See pictures


              Any Help ?
              Thanks
              Attached Files

              Comment


                #8
                Sorry, replace

                PHP Code:
                If parm.Count <> 2 Then 
                with

                PHP Code:
                If parm.Length <> 2 Then 
                Author of Highpeak Plugins | SMS-Gateway Plugin | Blue Iris Plugin | Paradox (Beta) Plugin | Modbus Plugin | Yamaha Plugin

                Comment


                  #9
                  operations with device

                  Super ! It works perfectly.
                  Now I have a question: How can the result of the calculation be reported in the device list .....or through a graph ?
                  Hope this is possible
                  Thanks

                  Comment


                    #10
                    Well the result is reported in your virtual device which is updated every time the script runs. You can look at BDGraph or Jon00's VirtualGraphing scripts to graph the virtual device over time.
                    Author of Highpeak Plugins | SMS-Gateway Plugin | Blue Iris Plugin | Paradox (Beta) Plugin | Modbus Plugin | Yamaha Plugin

                    Comment


                      #11
                      Analysis

                      Originally posted by beerygaz View Post
                      Sorry for the delay, I missed your response. Try something like this:

                      PHP Code:
                      Public Sub Main(ByVal parms As String)
                              
                      Dim parm() As String
                              parm 
                      parms.Split("|")
                              If 
                      parm.Count <> 2 Then
                                  hs
                      .WriteLog("Error""Usage: Send two integers separated by '|'.  Device ref of counter, Device ref of virtual usage device (e.g. Main(""100|101"")")
                                  Exit 
                      Sub
                              End 
                      If
                              
                      Dim GasCounterDevice As Integer CInt(parm(0))
                              
                      Dim VirtualUsageDevice As Integer CInt(parm(1))
                              
                      Dim OldValue As Integer CInt(hs.GetINISetting("data""PreviousValue"0"GASDATA.INI"))
                              
                      Dim CurrentValue As Integer hs.DeviceValue(GasCounterDevice)
                              
                      Dim Usage As Integer CurrentValue OldValue
                              hs
                      .WriteLog("Gas Usage""The gas usage since I last checked is " Usage.ToString())
                              
                      hs.SetDeviceValueByRef(VirtualUsageDeviceUsageTrue)
                              
                      hs.SaveINISetting("data""PreviousValue"CurrentValue.ToString"GASDATA.INI")
                          
                      End Sub 
                      Save tihs to a script "Gas.vb" and put the file in your \scripts folder. Create a new virtual device in HomeSeer, note it's device reference ID (in the "Advanced" tab of the device). Note the device reference ID of your Gaz counter too.

                      Create an event to run the script every 5 minutes and pass the script two parameters to the Main method, separated by '|' e.g. Main("320|150") - Counter first, virtual device second.

                      It will moan about the INI file not being there the first time, but after that all should be good.


                      Hello,
                      I would like to have a second script to check if the gaz counter is not blocked (breakdown or something else..) .
                      Can I use the same script as the one above (will it create conflict in the INI file or any values) ? or should I create a different script with other values and then test every X minutes if the consumption is not equal to Zero ?
                      Thanks in advance

                      Comment

                      Working...
                      X