nfarina / homebridge-tesla

Tesla plugin for homebridge: https://github.com/nfarina/homebridge
154 stars 38 forks source link

Add Homelink #45

Closed focher closed 4 years ago

focher commented 4 years ago

It appears that teslajs does not require the latitude and longitude values, so the code I added just makes a call to homelink().

Forgive any mistakes. I'm not really a coder but it looked pretty straightforward to add new commands.

nfarina commented 4 years ago

Does this work for you? Also, it seems like it should be exposed as a "garage door" accessory instead of a "switch", what do you think?

focher commented 4 years ago

To be honest, I was only able to test using Postman to call the teslajs API call of homelink() and that worked. I do not know how to build this and install into Homebridge.

I think exposing it as a Garage Door Opener sensor type would be overkill, as the Homelink functionality in the car simply sends the garage door signal. There's no ability for the car to receive information back like whether the door is open or closed, if there's an obstruction, etc.

In the Homebridge Garage Door Sensor type, the following Characteristics are supported. However, the car cannot use any of them.

Required Characteristics Current Door State Target Door State Obstruction Detected

Optional Characteristics Lock Current State Lock Target State Name

focher commented 4 years ago

Unfortunately, I am not getting this to successfully work. I've now tried:

Switch Garage Door Opener Stateless Programmable Switch

None appear to actually call the homelink() API. I believe it is something to do with the latitude and longitude being necessary. I'll play a bit more to see if I can make progress.

focher commented 4 years ago

I recommend to cancel / reject this pull request until I can successfully test it. So far, no go. But I'll keep trying.

focher commented 4 years ago

I finally got back to this and have it working. However, the Homelink API call in the TeslaJS library needs to be fixed first. I have provided the fixes to that developer here. Once that fix is applied, I'll create a new pull request with the final code.

focher commented 4 years ago

Discovered the change needed in the TeslaJS library. There's a code commit to fix the Homelink API call. Once that's deployed, I'll do another pull request with the Homelink that I've added.

I'm still experiencing one strange issue. Homelink only works if the car is awake. I've added an

`await this.setConnectionOn;

but found this does not does not really work. Instead I have to use the explicit call from the Homebridge - Accessories UI to wake the car, then wait for the car to be awake before I can call the Homelink trigger.

Any ideas why that's happening so that I can handle it differently?

nfarina commented 4 years ago

Calling await this.wakeUp(); should be sufficient to wake up the car - that's what all the other commands do internally?

focher commented 4 years ago

I'm just waiting for the patched release of TeslaJS and then the code is good to go. I also added a Charge Level indicator (in %).

You'll also see a small change I made in one of your logging messages. It appears there might have been a hidden character, as it was messing up in the log display.

this.log("Waiting for vehicle to wake up...");

focher commented 4 years ago

This is good to go. Unfortunately, the TeslaJS version wasn't bumped when he applied the Homelink API fix but I set it to the 4.8.1 (current) in package.json

So the pull request should be good to go and now there's Homelink support!

nfarina commented 4 years ago

Seems great to me, thanks for all this work! Can you update the README with information about these two new features? Also since some people don't have HomeLink support in their car (or a home with a garage door), could the HomeLink service be opt-in instead of opt-out?

nfarina commented 4 years ago

Oh and could you update config.schema.json to reflect these new options, for those who are using GUI configuration tools like config-ui-x?

focher commented 4 years ago

Funny. I had actually already done the stuff to support GUI config but neglected to commit it. Those two commits:

  1. Make Homelink default to disabled
  2. Add the GUI support for both Homelink and Charge Level services
  3. Added documentation in the README.md file
nfarina commented 4 years ago

Awesome, thank you! I think this is good to merge.

nfarina commented 4 years ago

I pushed one more commit with some aesthetic changes and will publish v2.5.0 now!