Announcement

Collapse
No announcement yet.

Script not working as expected

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

  • Script not working as expected

    I have got a script, which depending on the value of the device Immersun determines of how long my hot water boiler runs.
    This is the script:

    Code:
    Sub Main(ByVal Parms As Object)
             Dim Immersun As Double
            Immersun = hs.DeviceValueEx(68)
            Dim dateValue As Date = #21:55#
            dim Evref as Integer
     dim Delay as Integer   
     dim Ok as Boolean 
     dim CC as CAPIControl
     dim DeviceRef As Integer = 228  'deviceref of the device I want to control
    Dim StopDateTime As Date = dateValue.AddMinutes(Delay)
     
            Select Case Immersun
    
                 Case 1 to 1.5
    
                 StopDateTime = dateValue.AddMinutes(40)
    
                 Case 1.5 To 2
    
                 StopDateTime = dateValue.AddMinutes(35)
    
                 Case 2 to 2.5
    
                 StopDateTime = dateValue.AddMinutes(30)
    
                 Case 2.5 To 3
    
                StopDateTime = dateValue.AddMinutes(25)
    
                Case 3 To 3.5
    
                StopDateTime = dateValue.AddMinutes(20)
    
               Case 3.5 To 4
    
                StopDateTime = dateValue.AddMinutes(15)
    
               Case 4 To 4.5
    
                StopDateTime = dateValue.AddMinutes(10)
               
             End Select
    
          If Immersun <= 4.5 Then
       
             Evref = hs.NewEventEx("Immersun temp event", "Hot Water","")
                ' set the trigger time of the event 
             Ok = hs.EventSetTimeTrigger(Evref, CStr(StopDateTime))
                ' set the event to delete itself after it runs
             hs.DeleteAfterTrigger_Set(Evref)
                ' add a device action to the event
             CC = hs.CAPIGetSingleControlByUse(DeviceRef, ePairControlUse._Off)
             hs.AddDeviceActionToEvent(Evref, CC)
             hs.EnableEventByRef(Evref) 
    
          End If
     
        End Sub
    I did see yesterday when it ran, Immersun had a value of 2.3, so I would have expected my hot water to turn off at 22.25 (start time +30 mins)
    But it ran as if Immersun was 0. Ichecked the log, and found this every 5 minutes in the log:

    Sep-02 22:10:00 Warning In ProcessEventItem, Cannot process event
    Immersun temp event - 1, there are no actions.

    Sep-02 22:34:00 Event Event Trigger "Hot Water Hot water off"
    Sep-02 22:34:00 Warning In ProcessEventItem, Cannot process event
    Immersun temp event, there are no actions.
    Sep-02 22:34:00 Warning In ProcessEventItem, Cannot process event
    Immersun temp event - 2, there are no actions.

  • #2
    Are you able to post a screenshot of the status graphics page for device reference 288, I'd guess from that error that you are not adding the correct CAPI control to the event. Whether this is because that device does not have a Off control use pair or it is perhaps too quick after creating the event to add it I don't know. One thing to try would be;

    Code:
     Evref = hs.NewEventEx("Immersun temp event", "Hot Water","")
                ' set the trigger time of the event 
             Ok = hs.EventSetTimeTrigger(Evref, CStr(StopDateTime))
                ' set the event to delete itself after it runs
             hs.DeleteAfterTrigger_Set(Evref)
                ' add a device action to the event
    hs.saveeventsdevices
             CC = hs.CAPIGetSingleControlByUse(DeviceRef, ePairControlUse._Off)
    hs.writelog("", "CAPI Control Is Real: " & IsNothing(CC)) 'this will just check the device has that CAPI control
             hs.AddDeviceActionToEvent(Evref, CC)
             hs.EnableEventByRef(Evref)
    My Plugins:

    Pushover 3P | DoorBird 3P | Current Cost 3P | Velleman K8055 3P | LAMetric 3P | Garadget 3P | Hive 3P |
    Yeelight 3P | Nanoleaf 3P

    Comment


    • #3
      Originally posted by mrhappy View Post
      Are you able to post a screenshot of the status graphics page for device reference 288, I'd guess from that error that you are not adding the correct CAPI control to the event. Whether this is because that device does not have a Off control use pair or it is perhaps too quick after creating the event to add it I don't know. One thing to try would be;

      Code:
       Evref = hs.NewEventEx("Immersun temp event", "Hot Water","")
                  ' set the trigger time of the event 
               Ok = hs.EventSetTimeTrigger(Evref, CStr(StopDateTime))
                  ' set the event to delete itself after it runs
               hs.DeleteAfterTrigger_Set(Evref)
                  ' add a device action to the event
      hs.saveeventsdevices
               CC = hs.CAPIGetSingleControlByUse(DeviceRef, ePairControlUse._Off)
      hs.writelog("", "CAPI Control Is Real: " & IsNothing(CC)) 'this will just check the device has that CAPI control
               hs.AddDeviceActionToEvent(Evref, CC)
               hs.EnableEventByRef(Evref)
      I have added your test code to my script, had a look in the log when it ran last night, but cannot see any reference to that code, it looks as if that part of the script ddi not run. It is possible that last night Immersun was <1, which would mean it should have run 39 minutes which it did. But I still see this error in teh log every 10 minutes agter Hot water is set to on and that script has run, so something is definetley not right.

      This is the error:

      Sep-03 22:15:00 Warning In ProcessEventItem, Cannot process event Immersun temp event - 3, there are no actions.

      Having looked at your comments and my script, I noticed I had the wrong deviceRef, the device I am trying to control, my hot water, is Ref 145, so I had changed that before the script ran last night.
      This is the script with your added lines of code. I think what I should try to add is a line which writes into the log how many minutes have been added after the script has run. That way it'll be more easy to see what the script did, also maybe we can write the Immersun value to the log at the same time.

      Code:
      Sub Main(ByVal Parms As Object)
               Dim Immersun As Double
              Immersun = hs.DeviceValueEx(68)
              Dim dateValue As Date = #21:55#
              dim Evref as Integer
       dim Delay as Integer   
       dim Ok as Boolean 
       dim CC as CAPIControl
       dim DeviceRef As Integer = 145  'deviceref of the device I want to control
      Dim StopDateTime As Date = dateValue.AddMinutes(Delay)
       
              Select Case Immersun
      
                   Case < 1
                   StopDateTime = dateValue.AddMinutes(39)
                   Case 1.0 To 1.5
                  StopDateTime = dateValue.AddMinutes(30)
                  Case 1.5 To 2
                  StopDateTime = dateValue.AddMinutes(20)
                 Case 2.0 To 2.5
                  StopDateTime = dateValue.AddMinutes(15)
                 Case 2.5 To 3
                  StopDateTime = dateValue.AddMinutes(10)
                 
               End Select
      
            If Immersun <= 3 Then
         
               Evref = hs.NewEventEx("Immersun temp event", "Hot Water","")
                  ' set the trigger time of the event 
               Ok = hs.EventSetTimeTrigger(Evref, CStr(StopDateTime))
                  ' set the event to delete itself after it runs
               hs.DeleteAfterTrigger_Set(Evref)
                  ' add a device action to the event
             hs.saveeventsdevices
               CC = hs.CAPIGetSingleControlByUse(DeviceRef, ePairControlUse._Off)
             hs.writelog("", "CAPI Control Is Real: " & IsNothing(CC)) 'this will just check the device has that CAPI control
               hs.AddDeviceActionToEvent(Evref, CC)
               hs.EnableEventByRef(Evref) 
      
            End If
       
          End Sub
      and here is a scrren shot of the device 145 I am trying to control:
      Attached Files

      Comment


      • #4
        Also try and tonight when that event fires to check the event that it creates and take a look at it, look whether or not the action has been added and look what time it creates to see whether it is sensible.
        My Plugins:

        Pushover 3P | DoorBird 3P | Current Cost 3P | Velleman K8055 3P | LAMetric 3P | Garadget 3P | Hive 3P |
        Yeelight 3P | Nanoleaf 3P

        Comment


        • #5
          Ok I can see what the problem is. Its creating 5 temp events (and it should only be 1 ?). Also all the temp events do not have any action. So there are 2 issues, too many events, and no actions.
          Attached Files

          Comment


          • #6
            I was just looking at the other temp events, and the last one looked ok. Maybe the other temp ones were there from earlier days.

            And I have got this in the log:

            Sep-04 21:54:00 CAPI Control Is Real: False
            Script.NET_04-Sep-2016 21:54:00.70534527_immersun.vb
            Attached Files

            Comment

            Working...
            X