Announcement

Collapse
No announcement yet.

"Playing" with Timers and scripts

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

    "Playing" with Timers and scripts

    Hi all, I hope I am in the right thread. I try to explain you what I'd like to do. Sorry for my bad english.
    I have 2 Timers and they start and stop (through an event) when a state of a device change. For example it start when a device is on (1-2-3-....) and stop then few seconds when the device is off. Attached the two events.
    Through a script I'd like to:

    - do an algebric operation (in this case "-") of the two timers
    - set the above result into a virtual device
    - reset the two timers

    What I tried to do with a script is the follow:




    Public Sub Main(param As Object)

    Dim valore_su As String
    Dim valore_giu As String
    Dim risultato As String


    valore_su = hs.TimerValue("Timer_Tapp_cucina_SU")
    valore_giu = hs.TimerValue("Timer_Tapp_cucina_GIU")
    risultato = valore_su - valore_giu
    hs.SetDeviceValueByRef(515, risultato, TRUE)
    hs.TimerReset("Timer_Tapp_cucina_SU")
    hs.TimerReset("Timer_Tapp_cucina_GIU")

    End Sub


    It doesn't work. I also have a lot of doubts like "String" (maybe Double or TimeSpan, even if I tried anyway) and if I have to insert some "hs.WaitSec()".....

    Please can anyone help me?
    Thanks
    Regards
    Attached Files

    #2


    Code:
    valore_su = hs.TimerValue("Timer_Tapp_cucina_SU")
    Several of your hs statements look like you are using a Device Name for the parameter when you should use the Device Ref value
    tenholde

    Comment


      #3
      Hi,
      I have tried to get around the obstacle in this way with success....:


      Public Sub Main(param As Object)

      Dim valore_su as Integer
      Dim valore_giu as Integer
      Dim risultato_temporaneo as Integer
      Dim risultato_finale as Integer

      valore_su = Convert.ToInt32(hs.TimerValue("Timer_Tapp_cucina_SU").TotalS econds)
      valore_giu = Convert.ToInt32(hs.TimerValue("Timer_Tapp_cucina_GIU").Total Seconds)

      risultato_temporaneo = hs.DeviceValue(515)

      hs.WaitSecs(1)

      risultato_finale = risultato_temporaneo + valore_su - valore_giu

      If risultato_finale < 0 Then
      risultato_finale = 0
      hs.SetDeviceValueByRef(515, risultato_finale, True)
      Exit Sub
      End If

      If risultato_finale > 20 Then
      risultato_finale = 20
      hs.SetDeviceValueByRef(515, risultato_finale, True)
      Exit Sub
      End If

      hs.WaitSecs(1)

      hs.SetDeviceValueByRef(515, risultato_finale, True)

      hs.WaitSecs(3)

      End Sub


      Thanks anyway for help.
      Regards
      Rinpe

      Comment

      Working...
      X