Page 1 of 1

Renault Zoe API

Posted: Wednesday 15 April 2020 21:11
by timmchugh
I created a bash script to get the status from a Renault Zoe using an unofficial API back in 2018. Since then Renault have updated their API and it was recently rolled out in the UK.

I have adjusted the script to work with the new API and i would like to add it to the wiki, but I saw that the permissions have changed and I am no longer able to change anything. I saw I needed to PM a moderator to gain access, but I cannot PM anyone as I havnt posted enough, so i thought i would kill 2 birds with 1 stone, post more and share my script.

I have let jamesremuscat on github do all the hard work, he created pyze, then just use that to send the information to domoticz.

To install pyze I used the commands

Code: Select all

git clone https://github.com/jamesremuscat/pyze
cd pyze/
sudo python3 setup.py install
You then need to add two API keys, you can see what infomation you need and the commands to add them here

Then login to pyze

Code: Select all

pyze login
Check everything is working with

Code: Select all

pyze status


Once setup you can fill out the domoticz info at the top of the script and run it

Code: Select all

#!/bin/bash
while true
do
#Domoticz Variables
username="Domoticz username"
password="Domoticz password"
domoticzIP="Domoticz IP address"
peridx="Percent IDX"
textidx="Text sensor IDX"
milesidx="Miles IDX"
battempidx="Battery temperature IDX"
updatetime="60" #not sure of the update frequency on the new api

#Variables
pyze status > ./zoeinfo.txt
info=`cat ./zoeinfo.txt`
battemp=`cat ./zoeinfo.txt | grep "Battery temp" | sed 's/Battery temperature   //; s/.C//'`
batpercent=`cat ./zoeinfo.txt | grep "Battery level" | sed 's/Battery level         //; s/ //; s/\%//'`
charging=`cat ./zoeinfo.txt | grep "Charging state" | sed 's/Charging state        //; s/Not charging or plugged in/NotCharging/'`
plugged=`cat ./zoeinfo.txt | grep "Plug state" | sed 's/Plug state            //; s/ //'`
range=`cat ./zoeinfo.txt | grep "Range es" | sed 's/Range estimate        //; s/\..*//'`
chargecurrent=`cat ./zoeinfo.txt | grep "Charge rate" | sed 's/Charge rate           //'`
remaining=`cat ./zoeinfo.txt | grep "Time rem" | grep -o ".:.." | sed 's/:/%20hours%20/'`

#Script
if [ $plugged = "Unplugged" ]
	then
		curl -i  -H "Content-Type: application/json" "http://$username:$password@$domoticzIP:8080/json.htm?type=command&param=udevice&idx=$textidx&nvalue=0&svalue=Not%20Plugged%20In"
	elif [ $plugged = "Pluggedin" ]
		then
			if [ $charging = "Charging" ]
			then
				if [ -z "$remaining" ]
				then
					curl -i  -H "Content-Type: application/json" "http://$username:$password@$domoticzIP:8080/json.htm?type=command&param=udevice&idx=$textidx&nvalue=0&svalue=Charging%20at%20$chargecurrent"
				else 
					curl -i  -H "Content-Type: application/json" "http://$username:$password@$domoticzIP:8080/json.htm?type=command&param=udevice&idx=$textidx&nvalue=0&svalue=Charging%20at%20$chargecurrent%0A$remaining%20remaining"
				fi
	elif [ $charging = "NotCharging" ] && [ $plugged = "Pluggedin" ]
		then
			curl -i  -H "Content-Type: application/json" "http://$username:$password@$domoticzIP:8080/json.htm?type=command&param=udevice&idx=$textidx&nvalue=0&svalue=Finished%20Charging"
	fi
fi

if [ $range -gt 1 ]
	then
		curl -i  -H "Content-Type: application/json" "http://$username:$password@$domoticzIP:8080/json.htm?type=command&param=udevice&idx=$milesidx&nvalue=0&svalue=$range"
fi

if [ $batpercent -gt 1 ]
	then
		curl -i  -H "Content-Type: application/json" "http://$username:$password@$domoticzIP:8080/json.htm?type=command&param=udevice&idx=$peridx&nvalue=0&svalue=$batpercent"
fi

curl -i  -H "Content-Type: application/json" "http://$username:$password@$domoticzIP:8080/json.htm?type=command&param=udevice&idx=$battempidx&nvalue=0&svalue=$battemp"

#Time between updates
sleep $updatetime
done &
Enjoy :D

Re: Renault Zoe API

Posted: Sunday 19 April 2020 14:36
by jvrietveld
Thanks for the update on the Renault Zoe API. I have the first part working with the instructions of James Muscat.

pi@domoticz:~/pyze $ pyze status
-------------------- --------------------------
Battery level 90%
Range estimate 46.0 miles
Plug state Unplugged
Charging state Not charging or plugged in
Charge mode Always charge
AC state off
External temperature 6.0°C
Battery temperature 13°C
Total mileage 33025.3 mi
Updated at 2020-01-12 17:23:41
Location Unavailable
-------------------- --------------------------

The integration with Domiticz is another one. I have some trouble with the script.
Running the script from the console does not work and I am new to using bash scripting.

pi@domoticz:~/domoticz/scripts $ ./renaultzoe.sh
bash: ./renaultzoe.sh: /bin/bash^M: bad interpreter: No such file or directory

With a virtual switch I also have tried to execute via action. This resulted in error 32512.

Any help will be appreciated.

Kind regards,
Johan

Re: Renault Zoe API

Posted: Sunday 19 April 2020 20:08
by jvrietveld
The error in the script was a common error when editing in windows (https://raspberry-projects.com/pi/bash/bash-files). The script can be started without further errors.

Re: Renault Zoe API

Posted: Sunday 19 April 2020 20:28
by jvrietveld
The data from the Renault API contains still the same data.
Does this has to do with the "Known issues" (https://github.com/jamesremuscat/pyze/w ... enault-API) ?

pi@domoticz:~ $ pyze login
Enter your My Renault email address: [email protected]
Enter your password:
Logged in successfully.
pi@domoticz:~ $ pyze status
-------------------- --------------------------
Battery level 90%
Range estimate 46.0 miles
Plug state Unplugged
Charging state Not charging or plugged in
Charge mode Always charge
AC state off
External temperature 6.0°C
Battery temperature 14°C
Total mileage 33025.3 mi
Updated at 2020-01-12 17:23:41
Location Unavailable
-------------------- --------------------------

Regards,
Johan

Re: Renault Zoe API

Posted: Monday 20 April 2020 9:31
by jvrietveld
When I checked the MyRenault App on my phone with the same result I remembered the expired subscription of my 2016 Renault Zoe. So i need to renew this first.

Re: Renault Zoe API

Posted: Monday 20 April 2020 21:14
by timmchugh
Apologies I'm a sloppy typer, I made a spelling mistake for one of the variables ( domoticzIP spelt domtoiczIP)

I have just retested the script and i should work now

Re: Renault Zoe API

Posted: Monday 20 April 2020 21:17
by timmchugh
You may also want to use this version for KM instead of miles

Code: Select all

#!/bin/bash
while true
do
#Domoticz Variables
username="Domoticz username"
password="Domoticz password"
domoticzIP="Domoticz IP address"
peridx="Percent IDX"
textidx="Text sensor IDX"
milesidx="Miles IDX"
battempidx="Battery temperature IDX"
updatetime="60" #not sure of the update frequency on the new api

#Variables
pyze status --km > ./zoeinfo.txt
info=`cat ./zoeinfo.txt`
battemp=`cat ./zoeinfo.txt | grep "Battery temp" | sed 's/Battery temperature   //; s/.C//'`
batpercent=`cat ./zoeinfo.txt | grep "Battery level" | sed 's/Battery level         //; s/ //; s/\%//'`
charging=`cat ./zoeinfo.txt | grep "Charging state" | sed 's/Charging state        //; s/Not charging or plugged in/NotCharging/'`
plugged=`cat ./zoeinfo.txt | grep "Plug state" | sed 's/Plug state            //; s/ //'`
range=`cat ./zoeinfo.txt | grep "Range es" | sed 's/Range estimate        //; s/\..*//'`
chargecurrent=`cat ./zoeinfo.txt | grep "Charge rate" | sed 's/Charge rate           //'`
remaining=`cat ./zoeinfo.txt | grep "Time rem" | grep -o ".:.." | sed 's/:/%20hours%20/'`

#Script
if [ $plugged = "Unplugged" ]
	then
		curl -i  -H "Content-Type: application/json" "http://$username:$password@$domoticzIP:8080/json.htm?type=command&param=udevice&idx=$textidx&nvalue=0&svalue=Not%20Plugged%20In"
	elif [ $plugged = "Pluggedin" ]
		then
			if [ $charging = "Charging" ]
			then
				if [ -z "$remaining" ]
				then
					curl -i  -H "Content-Type: application/json" "http://$username:$password@$domoticzIP:8080/json.htm?type=command&param=udevice&idx=$textidx&nvalue=0&svalue=Charging%20at%20$chargecurrent"
				else 
					curl -i  -H "Content-Type: application/json" "http://$username:$password@$domoticzIP:8080/json.htm?type=command&param=udevice&idx=$textidx&nvalue=0&svalue=Charging%20at%20$chargecurrent%0A$remaining%20remaining"
				fi
	elif [ $charging = "NotCharging" ] && [ $plugged = "Pluggedin" ]
		then
			curl -i  -H "Content-Type: application/json" "http://$username:$password@$domoticzIP:8080/json.htm?type=command&param=udevice&idx=$textidx&nvalue=0&svalue=Finished%20Charging"
	fi
fi

if [ $range -gt 1 ]
	then
		curl -i  -H "Content-Type: application/json" "http://$username:$password@$domoticzIP:8080/json.htm?type=command&param=udevice&idx=$milesidx&nvalue=0&svalue=$range"
fi

if [ $batpercent -gt 1 ]
	then
		curl -i  -H "Content-Type: application/json" "http://$username:$password@$domoticzIP:8080/json.htm?type=command&param=udevice&idx=$peridx&nvalue=0&svalue=$batpercent"
fi

curl -i  -H "Content-Type: application/json" "http://$username:$password@$domoticzIP:8080/json.htm?type=command&param=udevice&idx=$battempidx&nvalue=0&svalue=$battemp"

#Time between updates
sleep $updatetime
done &

Re: Renault Zoe API

Posted: Tuesday 21 April 2020 8:17
by jvrietveld
Thanks for the update with the KM parameter on pyze and the fix for the host it was not able to find.
For the renewal of the MyRenault service I had contact with my cardealer. I have to wait a few weeks after the current covid19 crisus is getting better for us all and visit the dealer to fix it.

Re: Renault Zoe API

Posted: Thursday 30 April 2020 11:17
by jvrietveld
Apparently you can update the My Z.E. Connect 12 months in the R-Link store for free without visiting the garage so I did.

For the Status I use here a Custom Sensor that works great with numbers but not with text.
screenshot-192.168.2.6_8080-2020.04.30-11_11_27.png
screenshot-192.168.2.6_8080-2020.04.30-11_11_27.png (10.02 KiB) Viewed 4312 times
I was expecting a text like 'Unplugged'. Do I have to change the device to a Text sensor?

Regards,
Johan

Re: Renault Zoe API

Posted: Thursday 30 April 2020 16:08
by jvrietveld
Zoe-status.png
Zoe-status.png (17.45 KiB) Viewed 4304 times
This is working for me.

Re: Renault Zoe API

Posted: Wednesday 08 July 2020 13:08
by jvrietveld
The Renault API has been changed a few days ago. Therefor a required upgrade is needed to continue accessing that API. Please update to pyze 0.5.0
https://github.com/jamesremuscat/pyze/releases

Re: Renault Zoe API

Posted: Sunday 18 April 2021 10:29
by jvrietveld
I hope you changed the kamareon key for Pyze. Since 01.02.2020 the node is not working anymore due API key change. The new kamareon key is "Ae9FDWugRxZQAGm3Sxgk7uJn6Q4CGEA2" as discussed here: https://gist.github.com/mountbatt/772e4 ... 058dd1ded7
and a version update of Pyze to 0.6.0.

Re: Renault Zoe API

Posted: Sunday 20 August 2023 18:56
by mm10
It's 2023 already and found that that the Kamereon key has been updated once more
See https://github.com/hacf-fr/renault-api/pull/848/files for the value that worked for me at this instance in time.

Re: Renault Zoe API

Posted: Monday 18 September 2023 23:12
by HacK
Hi all,

I've created a python plugin that uses the hacf-fr renault-api as it's foundation.
Compared to the script described here, it is quite a step forward.

Please join me in providing feedback so we can make this work the best possible at 2023 standards!

Thanks in Advance
github/HomeACcessoryKid/Domoticz-Renault-Plugin

Re: Renault Zoe API

Posted: Friday 22 September 2023 23:24
by waltervl
While updating the Domoticz Python plugin list I came acros this plugin https://github.com/Kask29/Domoticz-Renault-Dacia-Plugin