Renault Zoe API

From Domoticz
Jump to: navigation, search

Purpose

I created this script so I could get information about my Renault Zoe and display it on 3 virtual sensors.

Dependencies

The script needs to be run on a linux system or the Raspberry Pi that Domoticz is running on.

Domoticz Setup

You need to create 3 virtual sensor

1. Text Sensor for charge status
2. Custom sensor with an Axis Label of Miles or KM
3. A percentage sensor for the battery percent

Installation instructions

1. Place the script in a location of your choosing
2. Make the script executable
   chmod +x /path/to/script/
3. Edit the infomation at the top of the script
4. Run the script!

Script for Miles

For miles to be converted from KM, you need to install bc.

sudo apt-get install bc

Script:

#!/bin/sh
#User Variables ****EDIT THESE***** DO NOT DELETE THE """"""""
vin="VIN NUMBER"
renaultusername="Renault Email Address"
renaultpassword="Renault Username"
domtoiczusername="Domtoicz username"
domtoiczpassword="Domtoicz password"
domtoiczip="Domoticz IP address"
peridx="Perecnt IDX"
textidx="Text sensor IDX"
milesidx="Miles IDX"
scriptpath="Directory to script eg. /home/user/zoe.sh"

#Script Variables
token=`curl -H "Content-Type: application/json"    -X POST    -d "{\"username\":\"$renaultusername\",\"password\":\"$renaultpassword\"}"    https://www.services.renault-ze.com/api/user/login | sed 's/.*"token":"//' | sed 's/".*//'`

batpercent=`curl    -H "Authorization: Bearer $token" "https://www.services.renault-ze.com/api/vehicle/$vin/battery" | sed 's/.*level"://' | sed 's/,.*//'`
charging1=`curl    -H "Authorization: Bearer $token" "https://www.services.renault-ze.com/api/vehicle/$vin/battery" | sed 's/.*charging"://' | sed 's/,.*//'`
plugged1=`curl    -H "Authorization: Bearer $token" "https://www.services.renault-ze.com/api/vehicle/$vin/battery" | sed 's/.*plugged"://' | sed 's/,.*//'`
rangekm=`curl    -H "Authorization: Bearer $token" "https://www.services.renault-ze.com/api/vehicle/$vin/battery" | sed 's/.*range"://' | sed 's/,.*//'`
chargertype=`curl    -H "Authorization: Bearer $token" "https://www.services.renault-ze.com/api/vehicle/$vin/battery" | sed 's/.*_point":"//' | sed 's/",.*//'`
remaining=`curl    -H "Authorization: Bearer $token" "https://www.services.renault-ze.com/api/vehicle/$vin/battery" | sed 's/.*_time"://' | sed 's/}//'`

#Script
if [ $chargertype = "ACCELERATED" ]
then
chargetype="Fast"
elif [ $chargertype = "SLOW" ]
then
chargetype="Slow"
fi

if [ $plugged1 = "false" ] 
then
curl -i  -H "Content-Type: application/json" "http://$domtoiczusername:$domtoiczpassword@$domtoiczip:8080/json.htm?type=command&param=udevice&idx=$textidx&nvalue=0&svalue=Not%20Plugged%20In"
elif [ $plugged1 = "true" ] 
then
if [ $charging1 = "false" ]
then
curl -i  -H "Content-Type: application/json" "http://$domtoiczusername:$domtoiczpassword@$domtoiczip:8080/json.htm?type=command&param=udevice&idx=$textidx&nvalue=0&svalue=Finished%20Charging"
elif [ $charging1 = "true" ]
then
curl -i  -H "Content-Type: application/json" "http://$domtoiczusername:$domtoiczpassword@$domtoiczip:8080/json.htm?type=command&param=udevice&idx=$textidx&nvalue=0&svalue=$chargetype%20Charging%0A$remaining%20Mins%20Remaining"
fi 
fi

range=`echo "scale=0 ; $rangekm * 0.63" | bc`

curl -i  -H "Content-Type: application/json" "http://$domtoiczusername:$domtoiczpassword@$domtoiczip:8080/json.htm?type=command&param=udevice&idx=$peridx&nvalue=0&svalue=$batpercent"
curl -i  -H "Content-Type: application/json" "http://$domtoiczusername:$domtoiczpassword@$domtoiczip:8080/json.htm?type=command&param=udevice&idx=$milesidx&nvalue=0&svalue=$range"


sleep 150

sh $scriptpath && exit

Script for Kilometres

#User Variables ****EDIT THESE***** DO NOT DELETE THE """"""""
vin="VIN NUMBER"
renaultusername="Renault Email Address"
renaultpassword="Renault Username"
domtoiczusername="Domtoicz username"
domtoiczpassword="Domtoicz password"
domtoiczip="Domoticz IP address"
peridx="Perecnt IDX"
textidx="Text sensor IDX"
milesidx="Miles IDX"
scriptpath="Directory to script eg. /home/user/zoe.sh"

#Script Variables
token=`curl -H "Content-Type: application/json"    -X POST    -d "{\"username\":\"$renaultusername\",\"password\":\"$renaultpassword\"}"    https://www.services.renault-ze.com/api/user/login | sed 's/.*"token":"//' | sed 's/".*//'`

batpercent=`curl    -H "Authorization: Bearer $token" "https://www.services.renault-ze.com/api/vehicle/$vin/battery" | sed 's/.*level"://' | sed 's/,.*//'`
charging1=`curl    -H "Authorization: Bearer $token" "https://www.services.renault-ze.com/api/vehicle/$vin/battery" | sed 's/.*charging"://' | sed 's/,.*//'`
plugged1=`curl    -H "Authorization: Bearer $token" "https://www.services.renault-ze.com/api/vehicle/$vin/battery" | sed 's/.*plugged"://' | sed 's/,.*//'`
rangekm=`curl    -H "Authorization: Bearer $token" "https://www.services.renault-ze.com/api/vehicle/$vin/battery" | sed 's/.*range"://' | sed 's/,.*//'`
chargertype=`curl    -H "Authorization: Bearer $token" "https://www.services.renault-ze.com/api/vehicle/$vin/battery" | sed 's/.*_point":"//' | sed 's/",.*//'`
remaining=`curl    -H "Authorization: Bearer $token" "https://www.services.renault-ze.com/api/vehicle/$vin/battery" | sed 's/.*_time"://' | sed 's/}//'`

#Script
if [ $chargertype = "ACCELERATED" ]
then
chargetype="Fast"
elif [ $chargertype = "SLOW" ]
then
chargetype="Slow"
fi

if [ $plugged1 = "false" ] 
then
curl -i  -H "Content-Type: application/json" "http://$domtoiczusername:$domtoiczpassword@$domtoiczip:8080/json.htm?type=command&param=udevice&idx=$textidx&nvalue=&svalue=Not%20Plugged%20In"
elif [ $plugged1 = "true" ] 
then
if [ $charging1 = "false" ]
then
curl -i  -H "Content-Type: application/json" "http://$domtoiczusername:$domtoiczpassword@$domtoiczip:8080/json.htm?type=command&param=udevice&idx=$textidx&nvalue=0&svalue=Finished%20Charging"
elif [ $charging1 = "true" ]
then
curl -i  -H "Content-Type: application/json" "http://$domtoiczusername:$domtoiczpassword@$domtoiczip:8080/json.htm?type=command&param=udevice&idx=$textidx&nvalue=0&svalue=$chargetype%20Charging%0A$remaining%20Mins%20Remaining"
fi 
fi



curl -i  -H "Content-Type: application/json" "http://$domtoiczusername:$domtoiczpassword@$domtoiczip:8080/json.htm?type=command&param=udevice&idx=$peridx&nvalue=0&svalue=$batpercent"
curl -i  -H "Content-Type: application/json" "http://$domtoiczusername:$domtoiczpassword@$domtoiczip:8080/json.htm?type=command&param=udevice&idx=$milesidx&nvalue=0&svalue=$rangekm"


sleep 150

sh $scriptpath && exit

Editing the Scirpt

Feel free to change the text shown in the if statements to suit your taste/language.

You can also change the update time at the bottom of the script after sleep

sleep 150

Example

Screenshot from 2018-12-02 21-08-51.jpg