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 SettingsMode=".$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}."
Day of Week | "; @@ -1136,12 +1168,47 @@ sub RenaultZE_gData_Step2($) $output = $output."
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}."