From 18c45fa09f190e3372545762d55b2e4589e70960 Mon Sep 17 00:00:00 2001 From: LeonGaultier Date: Fri, 1 Jul 2022 16:57:45 +0000 Subject: [PATCH] 74_GardenaSmartDevice: add lona readings, [fix] - setter procedure git-svn-id: https://svn.fhem.de/fhem/trunk@26186 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/73_GardenaSmartBridge.pm | 16 ++-- fhem/FHEM/74_GardenaSmartDevice.pm | 132 +++++++++++++++++++++++++---- 3 files changed, 127 insertions(+), 22 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 0bbf57921..420d0aa84 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature: 74_GardenaSmartDevice: add lona readings, [fix] - setter procedure - feature: 14_CUL_TCM97001: add KW9015 (TFA 30.3161) add Mebus HQ7312 diff --git a/fhem/FHEM/73_GardenaSmartBridge.pm b/fhem/FHEM/73_GardenaSmartBridge.pm index 19297c359..d3bec0906 100644 --- a/fhem/FHEM/73_GardenaSmartBridge.pm +++ b/fhem/FHEM/73_GardenaSmartBridge.pm @@ -414,7 +414,6 @@ sub Set { if ( lc $cmd eq 'getdevicesstate' ) { getDevices($hash); - } elsif ( lc $cmd eq 'gettoken' ) { return "please set Attribut gardenaAccountEmail first" @@ -438,6 +437,13 @@ sub Set { DeletePassword($hash); } + elsif ( lc $cmd eq 'debughelper') { + return "usage: $cmd" if ( scalar( @{$aArg} ) != 2 ); + my $new_helper = $aArg->[0]; + my $new_helper_value = $aArg->[1]; + Log3( $name, 5, "[DEBUG] - GardenaSmartBridge ($name) - override helper $new_helper with $new_helper_value"); + $hash->{helper}{$new_helper} = $new_helper_value; + } else { my $list = "getDevicesState:noArg getToken:noArg" @@ -482,8 +488,8 @@ sub Write { "GardenaSmartBridge ($name) - Send with URL: $hash->{URL}$uri, HEADER: secret!, DATA: secret!, METHOD: $method" ); -# Log3($name, 3, -# "GardenaSmartBridge ($name) - Send with URL: $hash->{URL}$uri, HEADER: $header, DATA: $payload, METHOD: $method"); + # Log3($name, 3, + # "GardenaSmartBridge ($name) - Send with URL: $hash->{URL}$uri, HEADER: $header, DATA: $payload, METHOD: $method"); return; } @@ -520,7 +526,6 @@ sub ErrorHandling { 1 ); if ( $err =~ /timed out/ ) { - Log3 $dname, 5, "GardenaSmartBridge ($dname) - RequestERROR: connect to gardena cloud is timed out. check network"; } @@ -607,6 +612,7 @@ sub ErrorHandling { if ( $data =~ /Error/ + && $data !~ /lastLonaErrorCode/ || ( defined($decode_json) && ref($decode_json) eq 'HASH' && defined( $decode_json->{errors} ) ) @@ -1577,7 +1583,7 @@ sub DeletePassword { ], "release_status": "stable", "license": "GPL_2", - "version": "v2.4.7", + "version": "v2.5.2", "author": [ "Marko Oldenburg " ], diff --git a/fhem/FHEM/74_GardenaSmartDevice.pm b/fhem/FHEM/74_GardenaSmartDevice.pm index fac69b5e3..ad9299335 100644 --- a/fhem/FHEM/74_GardenaSmartDevice.pm +++ b/fhem/FHEM/74_GardenaSmartDevice.pm @@ -195,6 +195,11 @@ sub Define { $hash->{helper}{eco_mode_id} = ''; $hash->{helper}{button_config_time_id} = ''; $hash->{helper}{winter_mode_id} = ''; + # Electroni Pressure Pump + $hash->{helper}{operating_mode_id} = ''; + $hash->{helper}{leakage_detection_id} = ''; + $hash->{helper}{turn_on_pressure_id} = ''; + $hash->{helper}{_id} = ''; @@ -294,7 +299,7 @@ sub Set { || AttrVal( $name, 'model', 'unknown' ) eq 'watering_computer' ); $abilities = 'power' if ( AttrVal( $name, 'model', 'unknown' ) eq 'power' ); - $abilities = 'manual_watering' + $abilities = 'watering' if ( AttrVal( $name, 'model', 'unknown' ) eq 'electronic_pressure_pump' ); ### mower @@ -355,12 +360,12 @@ sub Set { #$abilities['service_id'] = $hash->{helper}{SCHEDULESID} if ( $mainboard_version > 10.30 ); } ### electronic_pressure_pump - elsif ( lc $cmd eq 'pumptimer' ) { - $payload = - '"name":"pump_manual_watering_timer","parameters":{"duration":' - . $aArg->[0] . '}'; - } - ### watering_computer + # elsif ( lc $cmd eq 'pumptimer' ) { + # $payload = + # '"name":"pump_manual_watering_timer","parameters":{"duration":' + # . $aArg->[0] . '}'; + # } + ### watering_computer & electronic pump elsif ( lc $cmd eq 'manualoverride' ) { $payload = '"properties":{"name":"watering_timer_1' @@ -477,7 +482,41 @@ sub Set { . '","device":"' . $hash->{DEVICEID} . '"}'; } - ### Sensors + ### Watering_pressure_pump + elsif ( lc $cmd eq 'operating_mode') { + my $op_mode = $aArg->[0]; + $payload = '"settings":{"name":"operating_mode",' + .'"value":"'.$op_mode.'",' + .'"device":"' + . $hash->{DEVICEID}.'"}'; + $abilities = 'watering_pressure_pump_settings'; + $service_id = $hash->{helper}->{ 'operating_mode_id' }; + } + elsif ( lc $cmd eq 'leakage_detection') { + my $leakdetection_mode = $aArg->[0]; + $payload = '"settings":{"name":"leakage_detection",' + .'"value":"'.$leakdetection_mode.'",' + .'"device":"' + . $hash->{DEVICEID}.'"}'; + $abilities = 'watering_pressure_pump_settings'; + $service_id = $hash->{helper}->{ 'leakage_detection_id' }; + } + elsif ( lc $cmd eq 'turn_on_pressure') { + my $turnonpressure = $aArg->[0]; + $payload = '"settings":{"name":"turn_on_pressure",' + .'"value":"'.$turnonpressure.'",' + .'"device":"' + . $hash->{DEVICEID}.'"}'; + $abilities = 'watering_pressure_pump_settings'; + $service_id = $hash->{helper}->{ 'turn_on_pressure_id' }; + } + elsif ( lc $cmd eq 'resetvalveerrors') { + $payload = '"name":"reset_valve_errors",' + .' "parameters": {}'; + $abilities = 'error'; + } + + ### Sensors elsif ( lc $cmd eq 'refresh' ) { my $sensname = $aArg->[0]; @@ -529,6 +568,9 @@ sub Set { 'closeAllValves:noArg stopScheduleValve:selectnumbers,1,1,6,0,lin resumeScheduleValve:selectnumbers,1,1,6,0,lin manualDurationValve1:slider,1,1,90 manualDurationValve2:slider,1,1,90 manualDurationValve3:slider,1,1,90 manualDurationValve4:slider,1,1,90 manualDurationValve5:slider,1,1,90 manualDurationValve6:slider,1,1,90 cancelOverrideValve1:noArg cancelOverrideValve2:noArg cancelOverrideValve3:noArg cancelOverrideValve4:noArg cancelOverrideValve5:noArg cancelOverrideValve6:noArg' if ( AttrVal( $name, 'model', 'unknown' ) eq 'ic24' ); + $list .= 'manualOverride:slider,1,1,90 cancelOverride:noArg operating_mode:automatic,scheduled leakage_detection:watering,washing_machine,domestic_water_supply,off turn_on_pressure:slider,2,0.2,3.0,1 resetValveErrors:noArg' + if ( AttrVal( $name, 'model', 'unknown' ) eq 'electronic_pressure_pump' ); + $list .= 'refresh:temperature,humidity' if ( AttrVal( $name, 'model', 'unknown' ) =~ /sensor.?/ ); @@ -734,13 +776,25 @@ sub WriteReadings { if ( ref( $propertie->{value} ) eq "HASH" ) { while ( my ( $r, $v ) = each %{ $propertie->{value} } ) { - readingsBulkUpdate( - $hash, - $decode_json->{abilities}[$abilities]{name} . '-' + if ( ref( $v ) ne "HASH" ) { + readingsBulkUpdate( + $hash, + $decode_json->{abilities}[$abilities]{name} . '-' + . $propertie->{name} . '_' + . $r, + RigReadingsValue( $hash, $v ) + ); + } else { + while ( my ( $i_r, $i_v ) = each %{ $v } ) { + readingsBulkUpdate( + $hash, + $decode_json->{abilities}[$abilities]{name} . '-' . $propertie->{name} . '_' - . $r, - RigReadingsValue( $hash, $v ) - ); + . $r . '_' . $i_r, + RigReadingsValue( $hash, $i_v ) + ); + } + } } } } @@ -761,7 +815,10 @@ sub WriteReadings { && ( $decode_json->{settings}[$settings]{name} =~ /schedules_paused_until_?\d?$/ || $decode_json->{settings}[$settings]{name} eq 'eco_mode' - || $decode_json->{settings}[$settings]{name} eq 'winter_mode' ) + || $decode_json->{settings}[$settings]{name} eq 'winter_mode' + || $decode_json->{settings}[$settings]{name} eq 'operating_mode' + || $decode_json->{settings}[$settings]{name} eq 'leakage_detection' + || $decode_json->{settings}[$settings]{name} eq 'turn_on_pressure' ) ) { if ( $hash->{helper} @@ -778,6 +835,14 @@ sub WriteReadings { $decode_json->{settings}[$settings]{value} ); } + # save electronid pressure pump settings as readings + if ( $decode_json->{settings}[$settings]{name} eq 'operating_mode' + || $decode_json->{settings}[$settings]{name} eq 'leakage_detection' + || $decode_json->{settings}[$settings]{name} eq 'turn_on_pressure' ) { + readingsBulkUpdateIfChanged( $hash, $decode_json->{settings}[$settings]{name}, + $decode_json->{settings}[$settings]{value} ); + + } # save winter mode as reading if ( $decode_json->{settings}[$settings]{name} eq 'winter_mode' ) { @@ -867,7 +932,6 @@ sub setState { # 4. Ventil manuell geoeffnet, Zeitpläne deaktiviert. # App zeigt: "Wird bewässert xx Minuten verbleibend" if ( AttrVal( $name, 'model', 'unknown' ) eq 'watering_computer' ){ - my $state_string = ReadingsVal( $name, 'watering-watering_timer_1_duration', 0 ) =~ m{\A[1-9]([0-9]+)?\z}xms # offen @@ -941,6 +1005,39 @@ sub setState { ReadingsVal( $name, 'power-power_timer', 'no info from power-timer' ) ) if ( AttrVal( $name, 'model', 'unknown' ) eq 'power' ); + #electronic water pump + if ( AttrVal( $name, 'model', 'unknown' ) eq 'electronic_pressure_pump' ) { # | ok | pump_not_filled (Pumpe nicht gefüllt) + my $state_string = ReadingsVal( $name, 'watering-watering_timer_1_duration', 0 ) =~ + m{\A[1-9]([0-9]+)?\z}xms + # offen + ? + ( ReadingsVal($name, 'scheduling-schedules_paused_until', '' ) eq '' ) + # leer ( zeitplan aktiv ... ) + ? sprintf( (RigReadingsValue($hash, 'will be irrigated %.f minutes remaining.').' '.RigReadingsValue($hash, 'next watering: %s')), (ReadingsVal( $name, 'watering-watering_timer_1_duration', 0 )/60), RigReadingsValue($hash, ReadingsVal($name, 'scheduling-scheduled_watering_next_start', '')) ) + # zeitplan pausiert + : + ( ReadingsVal($name, 'scheduling-schedules_paused_until', '') eq '2038-01-18T00:00:00.000Z') + # pause bis dauerhaft + ? sprintf( (RigReadingsValue($hash, 'will be irrigated %.f minutes remaining.').' '.RigReadingsValue($hash , 'schedule permanently paused')), (ReadingsVal( $name, 'watering-watering_timer_1_duration', 0 )/60) ) + # naechter termin + : sprintf( RigReadingsValue($hash , 'paused until %s'), RigReadingsValue($hash, ReadingsVal($name, 'scheduling-schedules_paused_until', '')) ) + # zu + : + ( ReadingsVal($name, 'scheduling-schedules_paused_until', '' ) eq '' ) + # zeitplan aktiv + ? sprintf( (RigReadingsValue($hash, 'closed') .'. '.RigReadingsValue($hash, 'next watering: %s')), RigReadingsValue($hash, ReadingsVal($name, 'scheduling-scheduled_watering_next_start', '') ) ) + # zeitplan pausiert + : RigReadingsValue($hash, 'closed') + ; + # state offline | override + $state_string = 'offline' if ($online_state eq 'offline'); + # check valv error, override state + my $error_type = ReadingsVal( $name, 'error-valve_error_1_type', 'ok' ); + $state_string = ( $error_type ne 'ok' ) ? $error_type : $state_string; + + readingsBulkUpdate( + $hash, 'state', RigReadingsValue( $hash, $state_string ) ); + } return; } @@ -1054,6 +1151,7 @@ sub ReadingLangGerman { 'paused until %s' => 'pausiert bis %s', 'will be irrigated %.f minutes remaining.'=> 'Wird bewässert. %.f Minuten verbleibend.', 'next watering: %s' => 'Nächste Bewässerung: %s', + 'pump_not_filled' => 'Pumpe nicht gefüllt', ); if ( @@ -1535,7 +1633,7 @@ sub SetPredefinedStartPoints { ], "release_status": "stable", "license": "GPL_2", - "version": "v2.4.3", + "version": "v2.5.2", "author": [ "Marko Oldenburg " ],