Announcement

Collapse
No announcement yet.

Tesla Monitoring from HSTouch

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

    Tesla Monitoring from HSTouch

    I have built a "Tesla" screen in HSTouch and I want to be able to update the Tesla devices when I click on a button in HSTouch.

    I see that the Status device has a status of "Waiting on Sleep" and a value of 4 and when i issue the "Update " command, after a short delay, the status changes to "Success" with a value of 1.
    Do I need to issue the Update command to the Status device and then check for the Status value to change to 1 before I check the value of the Charge Port device?

    I want to create a script that:
    1. requests an update of tesla devices
    2. Verifies the tesla devices update occurred
    3 check for charge port closed
    4. if closed, issue a voice command from homeseer that the charging cable is not plugged in.

    I know the charge port device is a 1 when open and 0 when closed.
    My question is what is the correct way to force an update of the tesla device, and verify the update occurred?

    I don't think I can really do what I want with events and that I will need to write a script(i am a beginner). When I try the following two script commands, I always get a value of -1 for both devices instead of 0 or 1 for Charge Port and 1 or 4 for Status as I get from HSTouch:
    hs.WriteLog("Tesla", "Charge Port = " & hs.DeviceValueByName("(MAS Dream Car) Charge Port" ))
    hs.WriteLog("Tesla", "Status = " & hs.DeviceValueByName("(MAS Dream Car) Status" )) '(MAS Dream Car is the Room Name)

    Any help would be much appreciated.
    Thanks,
    Wallis

    #2
    Because of the unpredictable sleep schedule of the car and the unpredictable time it takes to wake up a sleeping car, all the commands the plugin issues are asynchronous. The best you can do is write a script that:
    • Checks the time of the last update of the status device
    • Calls for an update
    • Waits for a bit and checks the last update of the status device, keep doing this until it changes
    • Once it changes, if the status is "Success" (1) or back to "Waiting on Sleep" (4), then you can assume it worked and continue;
      • if it fails, then stop or do start over or something.
    • Check the "Charging State" device for "Disconnected" (or you can check the charge port, either way)
    Code:
    Sub Main(parm as object)
    
         Dim objCAPIControl As CAPIControl
         Dim intRef As Integer
         Dim dtmChanged As Date
         Dim blnChanged As Boolean
    
         'customizable variables/constants
         Dim strStatus = "MAS Dream Car Status"
         Dim strChargeState = "MAS Dream Car Charging State"
    
         Const TIMEOUT As Integer = 30
    
         '==============================
         ' 1. Request an Update
         '==============================
         'get the Update control
         intRef = hs.GetDeviceRefByName(strStatus)
         If intRef Then
    
              objCAPIControl = hs.CAPIGetSingleControl(intRef, True, "Update", True, False)
              If objCAPIControl IsNot Nothing Then
    
                   'execute the command
                   hs.CAPIControlHandler(objCAPIControl)
    
              Else
                   hs.WriteLog("ERROR", "CAPI Control 'Update' not found for device '" & strStatus & "'.")
              End If
    
         Else
              hs.WriteLog("ERROR", "Device '" & strStatus & "' not found.")
         End If
    
         '==============================
         ' 2. Wait for it to change
         '==============================
         'when did it change last?
         dtmChanged = hs.DeviceDateTime(intRef)
         hs.WaitEvents()
         For i = 1 to TIMEOUT
    
              'once a second for 30 seconds, check to see if it changed
              hs.WaitSecs(1)
              If hs.DeviceDateTime(intRef) > dtmChanged Then
                   blnChanged = (hs.DeviceValue(intRef) = 1 Or hs.DeviceValue(intRef) = 4)
                   Exit For
              End If
    
         Next
    
         '==============================
         ' 3. If it changed, check the charge state
         '==============================
         'stop here if it didn't
         If blnChanged Then
    
              'do something if it's not connected
              If hs.DeviceValueByName(strChargeState) = 0 Then
    
                   '<<<<< YOUR CODE TO TAKE ACTION ON THIS FACT GOES HERE >>>>>
    
              End If
    
         Else
              hs.WriteLog("ERROR", "Device failed to change successfully within " & TIMEOUT & " seconds.")
         End If
    
    End Sub
    (Note: I wrote this code in the forum text editor and have not tested it so there may be syntactical errors, but hopefully it's a good starting point!)

    I prefer to concentrate on what events should trigger this reminder. For my car, I have an event that says "If location has been 'Home' for exactly 5 minutes AND charge state is disconnected AND battery range < 150" then send me a push notification reminding me to plug in the car. That way it's not dependent on me pushing any buttons - the goal is to automate all this stuff, right?

    Comment


      #3
      Thanks for your response. I will play with the scripting, but I like your event concept and I will implement that tonight.

      Thanks again,
      Wallis

      Comment

      Working...
      X