Renault Zoe API

All kinds of 'OS' scripts

Moderator: leecollings

Post Reply
timmchugh
Posts: 5
Joined: Sunday 02 December 2018 21:26
Target OS: Linux
Domoticz version: 2020.1
Contact:

Renault Zoe API

Post 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
Last edited by timmchugh on Monday 20 April 2020 21:12, edited 1 time in total.
jvrietveld
Posts: 15
Joined: Wednesday 25 December 2019 16:23
Target OS: Raspberry Pi / ODroid
Domoticz version: V2020.2
Location: Limburg
Contact:

Re: Renault Zoe API

Post 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
jvrietveld
Posts: 15
Joined: Wednesday 25 December 2019 16:23
Target OS: Raspberry Pi / ODroid
Domoticz version: V2020.2
Location: Limburg
Contact:

Re: Renault Zoe API

Post 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.
jvrietveld
Posts: 15
Joined: Wednesday 25 December 2019 16:23
Target OS: Raspberry Pi / ODroid
Domoticz version: V2020.2
Location: Limburg
Contact:

Re: Renault Zoe API

Post 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
jvrietveld
Posts: 15
Joined: Wednesday 25 December 2019 16:23
Target OS: Raspberry Pi / ODroid
Domoticz version: V2020.2
Location: Limburg
Contact:

Re: Renault Zoe API

Post 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.
Attachments
MyRenault.App.png
MyRenault.App.png (115.54 KiB) Viewed 4410 times
timmchugh
Posts: 5
Joined: Sunday 02 December 2018 21:26
Target OS: Linux
Domoticz version: 2020.1
Contact:

Re: Renault Zoe API

Post 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
timmchugh
Posts: 5
Joined: Sunday 02 December 2018 21:26
Target OS: Linux
Domoticz version: 2020.1
Contact:

Re: Renault Zoe API

Post 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 &
jvrietveld
Posts: 15
Joined: Wednesday 25 December 2019 16:23
Target OS: Raspberry Pi / ODroid
Domoticz version: V2020.2
Location: Limburg
Contact:

Re: Renault Zoe API

Post 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.
jvrietveld
Posts: 15
Joined: Wednesday 25 December 2019 16:23
Target OS: Raspberry Pi / ODroid
Domoticz version: V2020.2
Location: Limburg
Contact:

Re: Renault Zoe API

Post 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 4314 times
I was expecting a text like 'Unplugged'. Do I have to change the device to a Text sensor?

Regards,
Johan
jvrietveld
Posts: 15
Joined: Wednesday 25 December 2019 16:23
Target OS: Raspberry Pi / ODroid
Domoticz version: V2020.2
Location: Limburg
Contact:

Re: Renault Zoe API

Post by jvrietveld »

Zoe-status.png
Zoe-status.png (17.45 KiB) Viewed 4306 times
This is working for me.
jvrietveld
Posts: 15
Joined: Wednesday 25 December 2019 16:23
Target OS: Raspberry Pi / ODroid
Domoticz version: V2020.2
Location: Limburg
Contact:

Re: Renault Zoe API

Post 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
jvrietveld
Posts: 15
Joined: Wednesday 25 December 2019 16:23
Target OS: Raspberry Pi / ODroid
Domoticz version: V2020.2
Location: Limburg
Contact:

Re: Renault Zoe API

Post 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.
mm10
Posts: 5
Joined: Monday 06 April 2015 18:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Renault Zoe API

Post 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.
User avatar
HacK
Posts: 7
Joined: Monday 18 September 2023 22:52
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Contact:

Re: Renault Zoe API

Post 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
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Renault Zoe API

Post by waltervl »

While updating the Domoticz Python plugin list I came acros this plugin https://github.com/Kask29/Domoticz-Renault-Dacia-Plugin
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests