[609] Nissan Leaf

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.

Moderators: leecollings, remb0

alfredo
Posts: 21
Joined: Thursday 04 June 2015 21:32
Target OS: Linux
Domoticz version:
Contact:

Re: [609] Nissan Leaf

Post by alfredo »

You need to install bc, apt-get install bc.
GNU bc is a commandline calculator, I'm using it to calculate percent of your battery which is charged.
Leaf only has 12 "levels" of charge though, where 100% is 12 and 6 is 50%.
pycarwings returns total capacity and remaining capacity, I'm calculating based on that.
... not sure if that's a good thing though, but I guess owners of cars with reduced batterycapacity already know that.
BluesBro
Posts: 54
Joined: Tuesday 13 August 2013 19:55
Target OS: -
Domoticz version:
Contact:

Re: [609] Nissan Leaf

Post by BluesBro »

The code finished without error, but the value that was sent to domoticz was 100%. The car only has about 40%.
BluesBro
Posts: 54
Joined: Tuesday 13 August 2013 19:55
Target OS: -
Domoticz version:
Contact:

Re: [609] Nissan Leaf

Post by BluesBro »

I echoed the content of the variables that is supposed to be divided and got som strange numbers:

pi@raspberrypi ~ $ sudo sh LEAF.sh
HTTP/1.1 200 OK
Content-Length: 53
Content-Type: application/json;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache
Access-Control-Allow-Origin: *

{
"status" : "OK",
"title" : "Update Device"
}
0601969420121011260801043280201512090753290000201512090752430000201512090752210000021600020144000

You are definately on to something but it seems the numbers extracted from GREP is wrong somehow...
BluesBro
Posts: 54
Joined: Tuesday 13 August 2013 19:55
Target OS: -
Domoticz version:
Contact:

Re: [609] Nissan Leaf

Post by BluesBro »

I wanted remaining km with AC off so I solved my problem by modifying Alfredos code:

Code: Select all

#!/bin/sh
 
# Domoticz server
SERVER="IP_ADRESS"
 
# Get data
INDATA=`/usr/bin/python /home/pi/pycarwings-master/test.py <USER> <PASSWORD> | grep ac_off | cut -c 44-47`
BAT=`echo "$INDATA*1.029/100" | bc | cut -c 1-6`
echo $BAT
 
# If BAT contains value then send it to Domoticz
if [ -z "$BAT" ];
then
        echo "Error: Value variable empty"
else
        # Sensor parameters
        IDX="291"
        NVALUE="Leaf"
        SVALUE="$BAT"
 
        # Send data
        curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=udevice&idx=$IDX&nvalue=$NVALUE&svalue=$SVALUE"
	
fi
But the sensor comes up with wrong numbers in the top (2482287), but the number in the middle (92) is correct.
See attached pic.
Any good ideas why?
Attachments
2015-12-09 14_32_29-NUC - TeamViewer.png
2015-12-09 14_32_29-NUC - TeamViewer.png (36.64 KiB) Viewed 4633 times
alfredo
Posts: 21
Joined: Thursday 04 June 2015 21:32
Target OS: Linux
Domoticz version:
Contact:

Re: [609] Nissan Leaf

Post by alfredo »

I'm a little busy at the moment, I'll post something updated later.
I noticed the insane amount of numbers myself and have fixed it, I'll try to integrate remaning km too, good idea.
alfredo
Posts: 21
Joined: Thursday 04 June 2015 21:32
Target OS: Linux
Domoticz version:
Contact:

Re: [609] Nissan Leaf

Post by alfredo »

The problem is that there is no sensor/switch which supports everything I need!

I have three sensors now, one percentage-sensor which accepts the charge %, one text-sensor which accepts the status (Normal Charging, Connected - Not Charging, etc.), and one distance-sensor which attempts to give out the range with AC off.
Three sensors for one thing is a little useless, and the range is displayed as in centimeters. (obviously my input is in km)

Thinking about dumping some info to a user variable instead....

Latest code:
http://pastebin.com/iKtUAxFu
BluesBro
Posts: 54
Joined: Tuesday 13 August 2013 19:55
Target OS: -
Domoticz version:
Contact:

Re: [609] Nissan Leaf

Post by BluesBro »

Great work alfredo! :-D

I added this:
BAT_RNG=`echo "$BAT_RNG_MTR/10000" | bc -l | cut -c 1-5`

to cut out all the decimals....
I'm happy with having all three sensors, don't mind at all as long as it "just works"

Have you any idea how the AC works? Would it be possible to turn it on/off via scripting?
I know it's a specific command to turn it on that also contains a timestamp for when. If the timestamp is in the past it turns on imediatly. If it's in the future, well, you can imagine...
alfredo
Posts: 21
Joined: Thursday 04 June 2015 21:32
Target OS: Linux
Domoticz version:
Contact:

Re: [609] Nissan Leaf

Post by alfredo »

Actually... yeah.
I just managed to do this.... I have to refine it some, but I did make it work.

If you copy test.py, and edit the new one - edit the line containing:
v.request_status(vin)
to:
v.start_ac_now(vin)

When you run the new test.py it will start ac now.
Haven't looked that much on Domoticz-script abilities - but if it can run an external script then it can.
BluesBro
Posts: 54
Joined: Tuesday 13 August 2013 19:55
Target OS: -
Domoticz version:
Contact:

Re: [609] Nissan Leaf

Post by BluesBro »

GENIUS!! :-D
Just in time for the winthercold in Norway!
A dummyswitch in Domoticz handles scripting. Just edit the Switch and add the path to the script.
I tried to edit the line to

v.stop_ac_now(vin)

but that one did not stop the AC. Any takes on this?
alfredo
Posts: 21
Joined: Thursday 04 June 2015 21:32
Target OS: Linux
Domoticz version:
Contact:

Re: [609] Nissan Leaf

Post by alfredo »

cancel_ac_now ;-)
alfredo
Posts: 21
Joined: Thursday 04 June 2015 21:32
Target OS: Linux
Domoticz version:
Contact:

Re: [609] Nissan Leaf

Post by alfredo »

Just posting back after using this for awhile, finalized script for getting status is posted here:
http://pastebin.com/qDTJTCQV
This allows you to skip certain status-updates, if you don't want/need them.

I have not implemented anything for starting ac now, but I'm testing a solution using cron at the moment.
BluesBro
Posts: 54
Joined: Tuesday 13 August 2013 19:55
Target OS: -
Domoticz version:
Contact:

Re: [609] Nissan Leaf

Post by BluesBro »

Does your script work for you? Mine keeps returning wrong username..? Has something been switched?
BluesBro
Posts: 54
Joined: Tuesday 13 August 2013 19:55
Target OS: -
Domoticz version:
Contact:

Re: [609] Nissan Leaf

Post by BluesBro »

Snippet from: http://www.mynissanleaf.com/ Discussion board Topic: Carwings API


"Re: Carwings API?
Report this postQuote
Tue Feb 02, 2016 5:07 am

Hi all,

I suddenly started getting HTTP 500 "Internal Server Error" responses from both my scripted Carwings API calls and from "unofficial" apps on my phone, yet the official apps and the Nissan web site seemed to be updating fine. Odd.

So, I set up a proxy to look at the traffic, and saw that the official iOS app ("NissanConnect EV") is connecting to a different URL endpoint and speaking JSON rather than XML. The new endpoint I see is: https://gdcportalgw.its-mo.com All API calls seem to be HTTP GET requests, and all parameters are on the query string.

Is anyone else familiar with this 'new' API? I see no mention of it anywhere on the web. I'm wondering if I need to try to figure it out and modify my scripts to use it rather than the old one that speaks XML.

Thanks!"

Does anyone know how to extract the json-commands?
alfredo
Posts: 21
Joined: Thursday 04 June 2015 21:32
Target OS: Linux
Domoticz version:
Contact:

Re: [609] Nissan Leaf

Post by alfredo »

I'm seeing the same here, not much to do if they changed the API - pitty, I had a nice integration with my Pebble going on here....

We will see if someone hacks the protocol and a new library appears because of this, that might be for the best - pycarwings isn't... great. :)

I guess you know but if you don't: https://play.google.com/store/apps/deta ... n.carwings
Works good in Norway, alot better than the previous Carwings-app.
BluesBro
Posts: 54
Joined: Tuesday 13 August 2013 19:55
Target OS: -
Domoticz version:
Contact:

Re: [609] Nissan Leaf

Post by BluesBro »

Someone is getting close...

// Thanks for putting my credentials in the URL so they can be logged by servers and proxies.
GET https://gdcportalgw.its-mo.com/orchestr ... upers3kr3t

// Yes, if you paste this URL in your browser you will get JSON data about your car's state dumped to you
// assuming DCMID (found in the Login reponse) and VIN parameters are specified. No other authentication necessary!
GET https://gdcportalgw.its-mo.com/orchestr ... 4T20:42:40

For AC control

Code: Select all

GET https://gdcportalgw.its-mo.com/orchestr ... ica/Denver

Havent got the time to test it yet, but RegionCode and tz might be troublesome off the bat...
BluesBro
Posts: 54
Joined: Tuesday 13 August 2013 19:55
Target OS: -
Domoticz version:
Contact:

Re: [609] Nissan Leaf

Post by BluesBro »

Someone has provided a pythonscript for the new api

https://github.com/jdhorne/pycarwings2/ ... rwings2.py
Raspberry Piet
Posts: 158
Joined: Saturday 11 January 2014 16:21
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: NL
Contact:

Re: [609] Nissan Leaf

Post by Raspberry Piet »

BluesBro
Posts: 54
Joined: Tuesday 13 August 2013 19:55
Target OS: -
Domoticz version:
Contact:

Re: [609] Nissan Leaf

Post by BluesBro »

BluesBro
Posts: 54
Joined: Tuesday 13 August 2013 19:55
Target OS: -
Domoticz version:
Contact:

Re: [609] Nissan Leaf

Post by BluesBro »

We now have a working python script for the Leaf again:

https://github.com/jdhorne/pycarwings2

I'm trying to implement it, but it just won't run. Tosses back a 256 error.
Runs fine from Putty and permissions set to 777 just i case, but still won't run.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests