Speak EV - Electric Car Forums banner

61 - 80 of 86 Posts

·
Registered
Joined
·
19 Posts
Yeh I'm desperate for this to work with the new API. I leave home/work at different times and am gagging to have some automation ready for preheating into the winter months ahead.
 

·
Registered
Joined
·
30 Posts
I'm getting a slightly different error message back from the service
JSON:
500 could not send preheat command: Failed to send request UserLoginRequest.php (404: Not Found)
 

·
Registered
Joined
·
346 Posts
Sorry I had a couple of hours at trying to get this working again but the Nissan API won't accept the calls any more, says the parameters are wrong no matter what. Will have another go as soon as I can.
Thanks for trying. found Quickleaf on the Play store to do the same thing.
 

·
Registered
Joined
·
1,306 Posts
Anyone found a solution to this? Missing my IFTTT link to heat my car..
You can use a Raspberry Pi to host Home Assistant, one of its integration is for Nissan Leaf.

I've got Home Assistant running my home, integrating all services working together including Google home, IFTTT, Apple homekit, Zigbee stuff (Ikea lights and plugs, Xiaomi sensors).

I've got a zigbee button in the hallway to start Leaf pre-heating, just press it when getting ready. Then go out to a warm car.
I've also set the car to always charge to 80% overnight. But instead of me going out to change to 100% when needed, I have a HA automation to turn on/off which resumes charging after 80% as needed.


Alternatively, here are the changes to Nissan API back in July. They may have removed their AWS URL in favour of API calls.........
 

·
Registered
Joined
·
36 Posts
Hi guys, I've just got this working using a Lambda function and the Python pycarwings2 code from https://github.com/filcole/pycarwings2

It works just like the original by @Mark Timms except you can optionally use a POST request with a json body instead of passing URL parameters. So for example:

JSON:
{
    "username": "USERNAME",
    "password": "PASSWORD",
    "region": "NE",
    "command": "startclimate"
}
You can do this in IFTTT by selecting POST as the method, "application/json" as the Content Type and putting the json in the body.

This avoids issues with having to encode special characters in your password etc.

The URL for my Lambda function is https://6y4516lpkf.execute-api.eu-west-1.amazonaws.com/myLeaf

Anyone here is welcome to use it. The lambda code is as follows if you want to host it yourself:

Python:
import json
import pycarwings2

def param(event,key):
    body = json.loads(event['body'])
    params = event['queryStringParameters']
   
    try:
        value = params[key]
    except (KeyError, TypeError):
        value = body[key]

    return value

def lambda_handler(event, context):
   
    username = param(event,'username')
    password = param(event,'password')
    region   = param(event,'region')
    command  = param(event,'command')

    s = pycarwings2.Session(username, password, region)

    leaf = s.get_leaf()

    if command == 'startclimate':
        msg = "Starting climate control"
        result_key = leaf.start_climate_control()

    if command == 'stopclimate':
        msg = "Stopping climate control"
        result_key = leaf.stop_climate_control()

    return {
        'statusCode': 200,
        'body': json.dumps(msg)
    }
Please let me know if you use this, I'll do a full tutorial when I have time.

James
 

·
Registered
Joined
·
241 Posts
Discussion Starter #72
Hi guys, I've just got this working using a Lambda function and the Python pycarwings2 code from https://github.com/filcole/pycarwings2

It works just like the original by @Mark Timms except you can optionally use a POST request with a json body instead of passing URL parameters. So for example:

JSON:
{
    "username": "USERNAME",
    "password": "PASSWORD",
    "region": "NE",
    "command": "startclimate"
}
You can do this in IFTTT by selecting POST as the method, "application/json" as the Content Type and putting the json in the body.

This avoids issues with having to encode special characters in your password etc.

The URL for my Lambda function is https://6y4516lpkf.execute-api.eu-west-1.amazonaws.com/myLeaf

Anyone here is welcome to use it. The lambda code is as follows if you want to host it yourself:

Python:
import json
import pycarwings2

def param(event,key):
    body = json.loads(event['body'])
    params = event['queryStringParameters']
  
    try:
        value = params[key]
    except (KeyError, TypeError):
        value = body[key]

    return value

def lambda_handler(event, context):
  
    username = param(event,'username')
    password = param(event,'password')
    region   = param(event,'region')
    command  = param(event,'command')

    s = pycarwings2.Session(username, password, region)

    leaf = s.get_leaf()

    if command == 'startclimate':
        msg = "Starting climate control"
        result_key = leaf.start_climate_control()

    if command == 'stopclimate':
        msg = "Stopping climate control"
        result_key = leaf.stop_climate_control()

    return {
        'statusCode': 200,
        'body': json.dumps(msg)
    }
Please let me know if you use this, I'll do a full tutorial when I have time.

James
Absolutely top notch thanks for fixing what I couldn't!!! Cheers
 

·
Registered
Joined
·
36 Posts
Hi all, I can see that my lambda function is being used! :)

I noticed that it wasn't as reliable as I would have liked, so I made some changes to the code. As the Nissan API seems to be a bit flaky sometimes, the function will now automatically retry the API call until it succeeds.

Since I made this change, the success rate shown in the AWS monitoring is 100% :D
 

·
Registered
Joined
·
1 Posts
Hi.

I can't seem to get it working. I had the earlier version working, is this the right setup in IFTTT? Is it also possible to use it as an url like before? Will be very happy for some help here.
126139
 

·
Registered
Joined
·
36 Posts
Hi @Smafly are you looking to use Google Assistant to trigger the action or something else? If Google Assistant then the setup should be like this:

  1. Go to IFTTT
  2. Click on the plus to add your "if this" action.
  3. Select Google Assistant then "say a simple phrase"
  4. Enter your desired phrase and response.
  5. Click on the plus to add your "then that" action.
  6. Select webhooks and "make a web request"
  7. Enter the URL and json payload.
The way you have filled in the details for the web request in your screenshot looks correct. But I'm not sure if you have followed all the steps, I'm not sure why you are seeing "receive a web request" above that. On my screen this step looks like this:

126196


I hope that helps. I'm still intending to do a full tutorial on my blog but I haven't had time yet.

James
 

·
Registered
Joined
·
36 Posts
Hi all, here's my full step by step guide for setting this up in IFTTT. I've also posted it on my blog: OK Google, preheat my Nissan Leaf – jwilf.uk

@Mark Timms I hope you don't mind that I gave you a shout out!

OK so here's the steps:

First, sign up for IFTTT if you don’t already have an account.

Then go to ifttt.com/create to create a new applet:

126239


Click on “this” to select your trigger. On the next page select “Google Assistant”:

126240


Then select “Say a simple phrase”. Enter your desired phrase and canned response:

126241


The phrase and response can be anything you like. Click on “Create trigger”. Next click on “that” to create your action:

126242

On the next page, select “Webhooks”:

126243

Then select “Make a web request”. On the next page, enter the web request details to call the Lambda function:

126244



The URL to call the function is:


Select POST as the method and “application/json” as the content type. This allows you to pass in your Nissan account details via a JSON body:

JSON:
{
"username": "USERNAME",
"password": "PASSWORD",
"region": "NE",
"command": "startclimate"
}
Obviously, substitute your own Nissan account details here.

And finally, review and finish:
126245

Now, when you say your chosen phrase to Google Assistant, a request will be made which will turn on the climate control in your car.

You can follow the same process to create another applet to cool the car, for the summer. Only the phrase and response need to differ, the call to the Lambda function is exactly the same.

Thanks, if this helps you then please consider using my Octopus referral link in my signature! :cool:

James
 

·
Registered
Joined
·
378 Posts
Hi @jwilf ,

The original webhooks never worked for me so I was pretty excited to see your update. Sadly I get "Applet skipped... Unable to make web request: Error: ETIMEDOUT "

Don't know if it makes any difference or you can help but My email address contains numbers and is a gmail.com account and my password may contain special characters :sneaky:

All the best
 

·
Registered
Joined
·
36 Posts
Hi @jwilf ,

The original webhooks never worked for me so I was pretty excited to see your update. Sadly I get "Applet skipped... Unable to make web request: Error: ETIMEDOUT "

Don't know if it makes any difference or you can help but My email address contains numbers and is a gmail.com account and my password may contain special characters :sneaky:

All the best
I get that same error sometimes, although only twice since I modified the code to retry the Nissan API call if it fails.

Your email address shouldn't be a problem. Mine is also gmail and numbers won't make any difference. It's possible that special characters in your password could be the problem. Most likely to be an issue if you have any quotes in your password.

Try escaping your password using the online tool here: Free Online JSON Escape / Unescape Tool - FreeFormatter.com

James
 
61 - 80 of 86 Posts
Top