Betatest - Renault ZE Services Binding

Because you are asking for more work :smiley: I would like to give you some more information about the possibilites of my current used php script:

  1. I know that some people, who donā€™t have a smart charger, are using the built in car scheduler to turn off the charging at for example 80%. When the internal scheduler is switched off the car stops charging.
    Maybe you can get the idea from the code snippet:
//Evaluate parameters "cmon" respectively "cmoff" for setting the chargemode
if ($cmd_cmon === TRUE || $cmd_cmoff === TRUE) {
  $postData = array(
    'Content-type: application/vnd.api+json',
    'apikey: '.$kamereon_api,
    'x-gigya-id_token: '.$session[1]
  );
  if ($cmd_cmon === TRUE) $jsonData = '{"data":{"type":"ChargeMode","attributes":{"action":"schedule_mode"}}}';
  else $jsonData = '{"data":{"type":"ChargeMode","attributes":{"action":"always_charging"}}}';
  $ch = curl_init('https://api-wired-prod-1-euw1.wrd-aws.com/commerce/v1/accounts/'.$session[2].'/kamereon/kca/car-adapter/v1/cars/'.$vin.'/actions/charge-mode?country='.$country);
  curl_setopt($ch, CURLOPT_POST, TRUE);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $postData);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
  $response = curl_exec($ch);
  if ($response === FALSE) die(curl_error($ch));
}
  1. At least for PH2 it is possible to read the battery capacity (not sure if that is the correct part of the code, sorry):

   echo '</TD></TR>'."\n".'<TR><TD>'.$lng['Battery level'].':</TD><TD>'.$session[12].' %</TD></TR>'."\n";
	if ($mail_bl === 'Y' || $cmon_bl === 'Y' || !empty($exec_bl)) echo '<TR><TD>'.$lng['Action at battery level'].':</TD><TD><INPUT TYPE="number" NAME="bl" VALUE="'.$session[21].'" MIN="1" MAX="99"><INPUT TYPE="submit" VALUE="%"></TD></TR>'."\n";
    if ($zoeph == 2) {
      echo '<TR><TD>'.$lng['Battery capacity'].':</TD><TD>'.$session[13].' kWh</TD></TR>'."\n";
    }
  1. It is possible to read the remaining time of a charging session:

$sendmessage = $lng['Specified battery level reached.']."\n".$lng['Battery level'].': '.$session[12].' %'."\n".$lng['Remaining charging time'].': '.$s.' '.$lng['minutes']."\n".$lng['Range'].': '.$session[14].' km'."\n".$lng['Status update'].': '.$session[8].' '.$session[9];

  1. It is possible to read the date and time of the last status update and position update (I could only find something about the position update):
//Request GPS position (only Ph2)
  if ($zoeph == 2) {
    $postData = array(
      'apikey: '.$kamereon_api,
      'x-gigya-id_token: '.$session[1]
    );
    $ch = curl_init('https://api-wired-prod-1-euw1.wrd-aws.com/commerce/v1/accounts/'.$session[2].'/kamereon/kca/car-adapter/v1/cars/'.$vin.'/location?country='.$country);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $postData);
    $response = curl_exec($ch);
    if ($response === FALSE) die(curl_error($ch));
    $responseData = json_decode($response, TRUE);
    $s = date_create_from_format(DATE_ISO8601, $responseData['data']['attributes']['lastUpdateTime'], timezone_open('UTC'));
	if (empty($s)) $update_sucess = FALSE;
	else {
      $s = date_timezone_set($s, timezone_open('Europe/Berlin'));
	  $session[17] = $responseData['data']['attributes']['gpsLatitude'];
	  $session[18] = $responseData['data']['attributes']['gpsLongitude'];
      $session[19] = date_format($s, 'd.m.Y');
	  $session[20] = date_format($s, 'H:i');
	}
  }

Please dump those ideas if you are not interested or donā€™t have the time to work on it :smiley:
Retrieving data from a website through http is a possibility, but a native openHAB binding is far better, of course.

1 Like

Thanks for the great feedback. While I am adding attributes this is easy to add more. However it is hard to guess what works and what is useful. So any feedback for users and rule developers is very useful.

I use my charger to control the charging rather than the car. This is because I am interested in using my excess solar power and charging when electricity is cheap on an hourly rateā€¦ All I need is the batterylevel but the other stuff is very nice to have and the pre-condition heating has won me some husband points with my wife so that is totally awesome.

I have added the battery capacity to the binding but it does not work on my car.

This is something that is dynamic with my auto-charging with solar. I will add it.

Is this useful?

This is great because I guess you can auto charge without a smart chargerā€¦

So I will do a writeable chargeMode channel.

With the timestamp I know if my wife is heading home and prepare the meal/tea/coffee right on schedule (no joke) :smiley:

Yes, I know that some people are using it that way.

Wow you must have lots of husband points. You are right that is useful I will add it!

I have been playing with wife tracking but so far it has lost me husband pointsā€¦ The Renault-API does not like delivering lots of requests so I update status every 10 mins. This is not accurate enough to auto open a gave or start a coffee machineā€¦ So I am plying with own tracks but this is also not very reliable. I guess with the last position update timestamp you can guess where she has got toā€¦

I lost some during long years and have to get them back slowly :smiley:

Here are my findings from testing:

Battery Capacity does not populate, but it is not useful anyway from my point of view. Battery Energy Available is the better choice.
Battery Temperature is always fixed to 20 degrees, this was also the finding from the guy who wrote the php scripts.
External Temperature does not work on PH2.

So I think this was a successful test! Thank you very much.

I think I put you on a wrong track, it is the end of charging time, not the remaining time, sorry.

Edit: I was not yet able to turn the HVAC on through the switch. Will test later again.

All good, works :+1:

@sihui Thanks for the awesome testing, advice and information.

My battery is also always 20 C.
I also have 0 Battery capacity.

I am not sure if I should leave these in and maybe they work at some point on some carsā€¦ However there might be bug reports that these do not work. Not sure if this is going to be a problemā€¦

remaining time seams to be an integerā€¦ I will add it and through testing I will try to find out what the units are.

Thanks again,

Doug

If I were you I would remove them. As we already know from the php script users the found out the same thing: does not work.

1 Like

New version for testing: https://drive.google.com/file/d/1-2ffCydevwFEGHbekTzv-WRXNFMC2dDw/view?usp=sharing

BatteryTemperature and capacity have been removed. (@sihui )
External temperature stays as an ā€œAdvanced Channelā€ so it is hidden a bit. (@Wolfgang1966 )

Set Charging mode to String: ā€œschedule_modeā€ or ā€œalways_chargingā€ implemented but not tested yet.

I think this is now feature complete so I will do some testing and tiding up and then submit a pull request.

1 Like

Do you never sleep? :smiley:

Yes, I think so, too :+1:

Testing of the new version will be tomorrow or the day after tomorrow.

I started testing, looks good so far. But I could not yet test the new charging mode and remaining time as the car was fully charged yesterday.

Unfortunately one important channel (for me) is missing, the status update time (in addtion to the location update time).
That timestamp is updated when for example a door is opened, the remote is used or if HVAC was activated. If the car is not in sight one can see if HVAC was successfully activated (without opening the Renault App which I donā€™t use at all).

But I donā€™t want to force you on anything :grinning:

For the not yet tested channels regarding charging I will come back to you ā€¦

If your wife is in danger of missing her coffee or has to get in a cold car then we got to get this fixed ASAP. Those hard won husband points are easily lost againā€¦

Where would this status come from? The locationupdate time comes from the location service. The status update would come from where:

  • battery service
  • hvac service
  • openHAB last poll timestamp.
  • ???
  • how do you set this value in your scrips?

The HVACstatus ON switch turns on the HVAC in the car and then asks the car for the status of the HVAC updating the HVACstatus channel. So if openHAB say the HVACstatus == ON then (I think) the car says it is ON (???) but maybe we need to test this moreā€¦ For example if the car is warm inside I can not turn on the HVACā€¦ it turns off againā€¦ (This is what I think is happening but I got to do more testing).

Thanks for your help.

It looks like it is coming from the battery status update, but I am not sure.
I tried to find the answer in different forums, but can not confirm my findings to 100%.

Maybe when the doors are opened or the remote is used the car always sends a battery status update to the servers and therefore has a current timestamp.

But if this is to vague or needs to much time for testing forget the request :grinning:

1 Like

@sihui Lets put the statusupdate in a later pull request if we have a clear understanding of its source and use.

Looks like the pre conditioning HVAC: ON switch only works if the targettemperature is 19 or 20. (Zoe 2021) Is this true for other cars? Maybe this should be a configuration parameter or hard coded to 20ā€¦?

That is perfectly fine. I will ask the guy who wrote the scripts where he gets it from and report the results to you.

What I know from reading the German ZOE forum, it is a fixed value with 21 degrees and only used for cars with manual ac.

I got an answer, but not very detailed:

The status update is provided through the Renault api, only Renault knows which events are updating that status.

So I went through all the pyze source code and looked for timestamps except the location update timestamp which you already have. I found only one further source:

status.py

hvac = wrap_unavailable(v, 'hvac_status')
    if hvac.get('_unavailable', False):
        hvac_start = hvac['nextHvacStartDate']
        external_temp = hvac['externalTemperature']
    elif 'nextHvacStartDate' in hvac:
        hvac_start = dateutil.parser.parse(
            hvac['nextHvacStartDate']
        ).astimezone(
            dateutil.tz.tzlocal()
        ).strftime(
            '%Y-%m-%d %H:%M:%S'
        )
        external_temp = "{}Ā°C".format(hvac['externalTemperature'])
    else:
        hvac_start = None
        external_temp = "{}Ā°C".format(hvac['externalTemperature'])

    try:
        update_time = dateutil.parser.parse(
            status['timestamp']
        ).astimezone(
            dateutil.tz.tzlocal()
        ).strftime(
            '%Y-%m-%d %H:%M:%S'
        )
    except ValueError:
        update_time = status['timestamp']

So it looks like the status update is tied to the hvac event. This could make sense as I am seeing an update there when preconditioning has successfully started.

But I am not sure if this is of any help. If not: donā€™t worry, we know have a wonderful openHAB binding which is a huge benefit, many thanks again for all of your hard work.

While reading through many posts in the other forum again I came across an explanantion regarding the charging schedule:

If a ZOE is charged through a charger and the car scheduler, which should only have a fake schedule of for example a minute or so, is activated, the car stops charging. This is used by many people to stop the charging before it reaches 100%, as this is sometimes not healthy for the car battery.
I could not yet test this, but will try by the end of the week.

While looking through pyze it is hardcoded to 21. In your current binding I was able to switch hvac on while I had it set to 21 (car is from October 2020).

hvactargettemperature has 3 options.

  1. hvactargettemperature to advanced channels because it might work in the future on some cars. However there will be confusion and frustration among users who think the binding does not work when it is the renault-api that is strange.

  2. Remove hvactargettemperature and hard code 20 to be done with it. It is just to pre-warm the car and so who needs this dynamic. Working is better than clever and complex.

  3. Make hvactargettemperature a config option min value 19 max 21. However setting min and max values and hoping all cars have the same strange behaviour.

Having written the options I think option 2 is my decision unless someone has a good argument for another option?

statusupdate timestamp

I guess there will also be a cockpit and battery update timestamp. I can see the point of the locationupdatetimestamp but not keen to add the others because it is more confusing than useful. I invite arguments otherwise?

In the readme and addon page it would be great to include a charge controller rule with the 80% full battery etcā€¦ using the technique @sihui describes. I will do this and test it (although i use my smart charger for this stuff.)

Does someone have a nice sitemap I can include in the read me examples. That way it is easy to add a page to the UI. I have no idea about sitemaps I use habpanel and UI 3 pages. I can add one of them but I invite help and input.

I would like to second that.

Yes, would have been my decision, too.

Sure, you will get one by the end of the week if someone is not faster :slight_smile:

1 Like

Thanks @sihui I will do this.

The charge mode works as I expected. I can send the mode value and I see this change in the MyRenault App. I will test a limit rule and document this smart charging idea.

1 Like