From d14b8f1c8ce560fb58d2ab99933f99555b558a1b Mon Sep 17 00:00:00 2001 From: plin <> Date: Wed, 4 Jan 2023 14:14:49 +0000 Subject: [PATCH] 96_RenaultZE:Support for RenaultZE cars git-svn-id: https://svn.fhem.de/fhem/trunk@26960 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/contrib/96_RenaultZE.pm | 90 ++++++++++++++++++++++++++++++++---- 1 file changed, 80 insertions(+), 10 deletions(-) diff --git a/fhem/contrib/96_RenaultZE.pm b/fhem/contrib/96_RenaultZE.pm index 6bad623dd..2caf16c46 100644 --- a/fhem/contrib/96_RenaultZE.pm +++ b/fhem/contrib/96_RenaultZE.pm @@ -1,6 +1,6 @@ ############################################################################### # -# $Id: 96_RenaultZE.pm 2022-11-16 plin $ +# $Id: 96_RenaultZE.pm 2023-01-04 plin $ # 96_RenaultZE.pm # # Forum : https://forum.fhem.de/index.php/topic,116273.0.html @@ -37,6 +37,10 @@ ############################################################################################################################ # Version History +# v 1.04 typo denbled corrected +# v 1.03 hvac settings output corrected +# v 1.02 some minor corrections +# v 1.01 added hvac-settings # v 1.00 added module to the contrib directory # v 0.32 added attribute disabled # v 0.31 changed API keys due to change by Renault @@ -91,7 +95,7 @@ use Time::Piece; #use JSON qw(decode_json); use JSON; -my $RenaultZE_version ="V1.00 / 16.11.2022"; +my $RenaultZE_version ="V1.04 / 04.01.2023"; my %RenaultZE_sets = ( "AC:on,cancel" => "", @@ -105,6 +109,7 @@ my %RenaultZE_gets = ( "charges" => "", "charging-settings:noArg" => "", "hvac-history" => "", + "hvac-settings:noArg" => "", "notification-settings:noArg" => "", "update:noArg" => "", "vehicles:noArg" => "", @@ -253,6 +258,12 @@ sub RenaultZE_Get($@) { } } + elsif ($opt eq "hvac-settings") + { + readingsSingleUpdate($hash,"ze_Step","getHvacSettings",1); + RenaultZE_Main1($hash, @param); + } + elsif ($opt eq "charging-settings") { readingsSingleUpdate($hash,"ze_Step","getChargingSettings",1); @@ -395,7 +406,7 @@ sub RenaultZE_Main1($@) { Log3 $name, 5, "RenaultZE_Main1 - gettimeofday=".gettimeofday(); if ( $ze_Gigya_JWT_Token eq "" || $gigya_time < gettimeofday() - 70000 ) { - $res = RenaultZE_getCreds_Step1($hash); + my $res = RenaultZE_getCreds_Step1($hash); Log3 $name, 5, "RenaultZE_Main1 - RC=".$res; } else @@ -462,7 +473,7 @@ sub RenaultZE_Main3($) { if ($key eq "GET_update") { - #my $res = RenaultZE_getData_Step1($hash); + #my $res = RenaultZE_getData_Step1($hash); my $res = RenaultZE_gData_Step1($hash,'battery-status'); Log3 $name, 5, "RenaultZE_gData_Step1 - battery-status - RC=".$res; $res = RenaultZE_gData_Step1($hash,'cockpit'); @@ -505,6 +516,12 @@ sub RenaultZE_Main3($) { Log3 $name, 5, "RenaultZE_gData_Step1 - hvac-history - RC=".$res; } + if ($key eq "GET_hvac-settings") + { + my $res = RenaultZE_gData_Step1($hash,'hvac-settings'); + Log3 $name, 5, "RenaultZE_gData_Step1 - hvac-settings - RC=".$res; + } + if ($key eq "GET_notification-settings") { my $res = RenaultZE_gData_Step1($hash,'notification-settings'); @@ -581,7 +598,7 @@ sub RenaultZE_Attr(@) { } elsif (($attrName eq "disabled") ) { - readingsSingleUpdate($hash,"state","denbled",1); + readingsSingleUpdate($hash,"state","enabled",1); readingsSingleUpdate($hash,"ze_Step","RenaultZE ($name) is enabled",1); $_[3] = $attrVal; $hash->{".reset"} = 1 if defined($hash->{LPID}); @@ -933,6 +950,8 @@ sub RenaultZE_gData_Step2($) my $lastErr = $hash->{READINGS}{ze_lastErr}{VAL}; return undef if ($lastErr ne ""); + my $lastUrl = $hash->{READINGS}{ze_lastUrl}{VAL}; + Log3 $name, 3, "RenaultZE_gData_Step2 - DataError ".$data if ($data =~ /\/); return undef if ($data =~ /\/); @@ -962,8 +981,19 @@ sub RenaultZE_gData_Step2($) return 0; } + ### cockpit ### if($data =~ /totalMileage/) { readingsSingleUpdate($hash,"totalMileageKm",$decode_json->{data}->{attributes}->{totalMileage},1); + readingsBulkUpdate($hash,"fuelAutonomy",$decode_json->{data}->{attributes}->{fuelAutonomy}) if (my $decode_json->{data}->{attributes}->{fuelAutonomy} gt 0); + readingsBulkUpdate($hash,"fuelQuantity",$decode_json->{data}->{attributes}->{fuelQuantity}) if (my $decode_json->{data}->{attributes}->{fuelQuantity} gt 0); + return 0; + } + + ### hvac-status ### + if($data =~ /hvacStatus/) { + readingsSingleUpdate($hash,"hvacStatus",$decode_json->{data}->{attributes}->{hvacStatus},1); + readingsBulkUpdate($hash,"socThreshold",$decode_json->{data}->{attributes}->{socThreshold}) if (my $decode_json->{data}->{attributes}->{socThreshold} gt 0); + readingsBulkUpdate($hash,"xternalTemperature",$decode_json->{data}->{attributes}->{xternalTemperature}) if (my $decode_json->{data}->{attributes}->{xternalTemperature} gt 0); return 0; } @@ -1116,12 +1146,14 @@ sub RenaultZE_gData_Step2($) } ### charging-settings?country=DE - if($data =~ /mode.*schedules/) { + if(($data =~ /mode.*schedules/) && ($lastUrl =~ /charg/)){ my $mtab = $decode_json->{data}->{attributes}->{schedules}; + my $sss = @$mtab; #print scalar @$mtab."\n"; my $output = "Charging Settings

Mode=".$decode_json->{data}->{attributes}->{mode}."
"; my @wdays = ("monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "saturday" ); - foreach my $item( @$mtab ) { + if ( $sss > 0 ) { + foreach my $item( @$mtab ) { $output = $output."Schedules, activated =".$item->{activated}.""; $output = $output.""; $output = $output.""; @@ -1136,12 +1168,47 @@ sub RenaultZE_gData_Step2($) $output = $output.""; } last; + } + $output = $output."
Day of Week
"; } - $output = $output.""; + $output = $output.""; readingsSingleUpdate($hash,"chargingSettings",$output,1); return 0; } + ### hvac-settings?country=DE + if(($data =~ /mode.*schedules/) && ($lastUrl =~ /hvac/)){ + my $mtab = $decode_json->{data}->{attributes}->{schedules}; + my $sss = @$mtab; + #print scalar @$mtab."\n"; + my $output = "HVAC Settings

Mode=".$decode_json->{data}->{attributes}->{mode}."
"; + my @wdays = ("monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "saturday" ); + if ( $sss > 0 ) { + $output = $output."

Schedules"; + foreach my $item( @$mtab ) { + if ($item->{activated} == 1 ) { + $output = $output."

activated =".$item->{activated}.""; + $output = $output.", Target Temperature =".$item->{targetTemperature}."
"; + $output = $output.""; + $output = $output.""; + $output = $output.""; + $output = $output.""; + foreach my $wd( @wdays ) { + $output = $output.""; + $output = $output.""; + $output = $output.""; + $output = $output.""; + } + $output = $output."
Day of WeekreadyAtTime
".$wd."".$item->{$wd}->{readyAtTime}."
"; + } + } + } + $output = $output.""; + readingsSingleUpdate($hash,"hvacSettings",$output,1); + return 0; + } + + ### notification-settings?country=DE if($data =~ /settings.*messageKey/) { my $mtab = $decode_json->{data}->{attributes}->{settings}; @@ -1660,12 +1727,15 @@ sub RenaultZE_EpochFromDateTime($) { type=day&start=YYYYMMDD&end=YYYYMMDD (default: 1.1.2000 till today)
type=month&start=YYYYMM&end=YYYYMM +

  • hvac-settings
    + shows the ac settingS
    +
  • notification-settings
    only for Phase1 models
    lists the settings for cnotifications
  • update
    - force update of the current readings
  • + force update of the current readings (battery-status, cockpit, location, hvac-status, charge-mode)
  • vehicles
    get a list of your vehicles with details, set the readings for the images
    if the attribute ze_showimage is set you get readings with the cars images
  • @@ -1673,10 +1743,10 @@ sub RenaultZE_EpochFromDateTime($) { Option to test new API functions which might be implemented one day ...
    sub parameters are
    hvac-sessions?start=20201101&end=20210108&country=DE
    - charges?start=20201101&end=20210108&country=DE
    charge-history?type=day&start=20201101&end=20210108&country=DE
    charge-history?type=month&start=202011&end=202101&country=DE
    lock-status?country=DE
    + res-state?country=DE
    As result you will either get a msgbox when the function is implemented by Renault, otherwise the ze-Readings will tell you more