Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically close the garage when parked at home #18

Closed
wants to merge 1 commit into from

Conversation

dhnoronha
Copy link
Contributor

No description provided.

Copy link
Owner

@brchri brchri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea and appreciate the PR. I've left a couple of implementation comments. Also, I think auto closing on park at home should be a configurable option, as not everyone may want this. Some people may park and then walk out to the street to get their mail, for example, and don't want the auto close, so it should be added to the config to enable this feature. It should probably be a per-car config item, as some drivers in a household may want this, and others may not.

I'm open to further discussion on this and the other comments I've left.

@@ -100,6 +101,10 @@ func CheckGeofence(config util.ConfigStruct, car *util.Car) {
for i := 3; i > 0; i-- {
if err := setGarageDoor(config, car.GarageDoor.MyQSerial, action); err == nil {
// no error received, so breaking retry loop
if action == "open" && len(responseChannel) == 0 {
responseChannel <- true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it makes sense to use a channel for this, as it's not tied to a specific car or garage, and if there's a message waiting to be consumed in the channel while a separate vehicle in the config parks elsewhere, it could falsely trigger the close process. I think it would make more sense to make this a bool property of the car so that only the car that triggers the garage open can trigger a follow-up auto-close-on-park operation. So the value would be set to true here, and then reset to false when it's consumed (i.e. when the car shifts to Park).

@@ -113,6 +118,52 @@ func CheckGeofence(config util.ConfigStruct, car *util.Car) {
car.GarageDoor.OpLock = false // release garage door's operation lock
}

// when parked, check if the car is at the home location and close the garage door.
func VailidateGeofenceAndClose(config util.ConfigStruct, car *util.Car, action string) {
timeout := 40
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This timeout seems arbitrary, as any cooldown configured for more than a minute would likely never fire. This should probably either be configurable, or be dynamic based on the cooldown value. Another alternative is it could ignore oplock given that it's a special case operation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching to closing the garage from within the CheckGeofence function based on a car configuration should avoid the need for this timeout.

@@ -113,6 +118,52 @@ func CheckGeofence(config util.ConfigStruct, car *util.Car) {
car.GarageDoor.OpLock = false // release garage door's operation lock
}

// when parked, check if the car is at the home location and close the garage door.
func VailidateGeofenceAndClose(config util.ConfigStruct, car *util.Car, action string) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know that we need the action string parameter here, as the function's purpose (and name) is to close the garage, and this should never be called unless that is the intended operation. So specifying the action string as a parameter is redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, Will be removed.

@dhnoronha
Copy link
Contributor Author

dhnoronha commented Sep 11, 2023

I like this idea and appreciate the PR. I've left a couple of implementation comments. Also, I think auto closing on park at home should be a configurable option, as not everyone may want this. Some people may park and then walk out to the street to get their mail, for example, and don't want the auto close, so it should be added to the config to enable this feature. It should probably be a per-car config item, as some drivers in a household may want this, and others may not.

I'm open to further discussion on this and the other comments I've left.

Thank you for taking the time to review the PR. I had originally planned on making this a configurable feature, but in testing found if I were using the garage more than once a day, it made it easy just to leave the feature on. I now realize there maybe some that don't need this feature. I will work on making this configurable per car. I can then use the configuration to detect if the garage should be auto closed from the CheckGeofence function and initiate the auto close from there, rather than passing the control back to main.

@DjAnu
Copy link

DjAnu commented Sep 15, 2023

Wow this is awesome, I had been googling around for past few days to somehow Auto open/close Garage using Tesla location. I have read hundreds of forums , tried using HA, Homebridge and what not, none of those are perfect solutions. Code you guys are working on is way more perfect. One of the major issue I have with using Geolocation is that my home at a location where for circular geofences (which is the only option for iOS and all other devices / HA I use) I cross the geofence a couple of times everytime I am leaving or coming home (see the screenshot below). I love the idea of having polygon fences. Hope at a later time I can somehow use it for other automations.......This is a perfect project to work on this weekend. I am not a programmer though so I hope I'll be able to figure out the integration process you have outlined here and if not may be I can reach out to you guys for help.....
Screenshot 2023-09-15 152033

@brchri
Copy link
Owner

brchri commented Sep 16, 2023

Wow this is awesome, I had been googling around for past few days to somehow Auto open/close Garage using Tesla location. I have read hundreds of forums , tried using HA, Homebridge and what not, none of those are perfect solutions. Code you guys are working on is way more perfect. One of the major issue I have with using Geolocation is that my home at a location where for circular geofences (which is the only option for iOS and all other devices / HA I use) I cross the geofence a couple of times everytime I am leaving or coming home (see the screenshot below). I love the idea of having polygon fences. Hope at a later time I can somehow use it for other automations.......This is a perfect project to work on this weekend. I am not a programmer though so I hope I'll be able to figure out the integration process you have outlined here and if not may be I can reach out to you guys for help..... Screenshot 2023-09-15 152033

@DjAnu Hey thanks for the love. I agree there are some other good solutions out there but none of them did what I wanted, so I started this project and open sourced it in hopes others might find it useful. If you have any issues getting it going, feel free to open an issue on the repo and I'm happy to help out, and it would help me learn what gaps there are in the documentation to try and make it as self-serve as possible. 😄

@DjAnu
Copy link

DjAnu commented Sep 16, 2023

@DjAnu Hey thanks for the love. I agree there are some other good solutions out there but none of them did what I wanted, so I started this project and open sourced it in hopes others might find it useful. If you have any issues getting it going, feel free to open an issue on the repo and I'm happy to help out, and it would help me learn what gaps there are in the documentation to try and make it as self-serve as possible. 😄

Hey thanks for your reply. I was able to set up telsamate using following instructions :
https://geekjournal.ch/how-to-install-teslamate-a-great-data-logger-and-visualizer-for-your-tesla/

I also updated the config file and added polygon coordinates. However as I am running docker on my synology NAS, I couldn't figure out how to load and run your image on my docker. Sorry I am not a programmer :-(. I am still searching to see if I can find any tutorial. If you have some time can you please give me some pointers. OR if we can hop on a char or something that would be great. Tx.

@DjAnu
Copy link

DjAnu commented Sep 17, 2023

Okay seems like I am getting close. I was able to load and run the docker using the instructions below:
https://mariushosting.com/how-to-install-firefox-on-your-synology-nas/
I ran the user defined scripts for both loading the docker & to get the MyQ serial number and was able to run it successfully.

I am still running into 2 issues.

  1. app isn't able to connect to MQTT broker
    2023/09/16 18:16:48 could not connect to mqtt broker: network Error : dial tcp 143.244.220.150:1883: i/o timeout
  2. Where do I get teslamate_car_id

@brchri
Copy link
Owner

brchri commented Sep 17, 2023

@DjAnu Congrats on getting that far.

  1. The message dial tcp 143.244.220.150:1883: i/o timeout looks like it's trying to connect to a public IP address, which I highly doubt is correct. You'd want it to be the IP address of your synology most likely, if that's where you're hosting Teslamate. So in your Tesla-YouQ config.yml file, you'd set mqtt_host: <ip of synology>.
  2. The short answer is that if this is the first car you've connected, your teslamate_car_id almost certainly 1. The long answer is there are a few ways to get the teslamate car id, either by looking at the database or exploring the MQTT broker. You can use a tool like this to connect to your MQTT broker and look around, and as you expand the tree, you'll see <your synology IP>/cars/<your teslamate car id>. Using this tool will also help you validate that your MQTT broker from Teslamate is exposed properly so Tesla-YouQ can access it.

Hope that helps.

@DjAnu
Copy link

DjAnu commented Sep 17, 2023

Thanks for your comment. I was able to figure out car-id from teslamate logs but I am still not able to find MQTT broker IP. I have tried synology IP, container name etc but still no go :-(. I downloaded the MQTT explorer portable but I can't seem to connect using IP or hostname using that too. Not sure how can I find MQTT server. Teslamate seem to connect fine though. Any pointer here ? Screenshot 2023-09-16 200421

@brchri
Copy link
Owner

brchri commented Sep 17, 2023

@DjAnu Based on that log it looks like the host should be 192.168.0.11. I took a look at the guide you linked, and it looks like the docker-compose.yml example they provided has commented out the port exposure for the MQTT broker. If you also have those commented out in your config file, you'll want to remove the comments so the ports will actually be exposed. That would cause your problem.

So instead of this:

mosquitto:
    image: eclipse-mosquitto:2
    restart: always
    command: mosquitto -c /mosquitto-no-auth.conf
    # ports:
    #   - 1883:1883
    volumes:
      - mosquitto-conf:/mosquitto/config
      - mosquitto-data:/mosquitto/data

You'd have this:

mosquitto:
    image: eclipse-mosquitto:2
    restart: always
    command: mosquitto -c /mosquitto-no-auth.conf
    ports:
      - 1883:1883
    volumes:
      - mosquitto-conf:/mosquitto/config
      - mosquitto-data:/mosquitto/data

Note I removed the # from two lines.

Hope that helps.

@DjAnu
Copy link

DjAnu commented Sep 17, 2023 via email

@brchri brchri closed this Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants