dev #74

Merged
sebastianschwarz merged 126 commits from dev into testing 2022-09-06 11:31:54 +00:00
3 changed files with 129 additions and 85 deletions
Showing only changes of commit 8ce72c5ddc - Show all commits

View File

@ -1 +1 @@
[fix] - change condition has_schedule [fix] - condition has_schedule

View File

@ -189,23 +189,23 @@ sub Define {
my $deviceId = $aArg->[2]; my $deviceId = $aArg->[2];
my $category = $aArg->[3]; my $category = $aArg->[3];
$hash->{DEVICEID} = $deviceId; $hash->{DEVICEID} = $deviceId;
$hash->{VERSION} = version->parse($VERSION)->normal; $hash->{VERSION} = version->parse($VERSION)->normal;
$hash->{helper}{STARTINGPOINTID} = ''; $hash->{helper}{STARTINGPOINTID} = '';
$hash->{helper}{schedules_paused_until_id} = ''; $hash->{helper}{schedules_paused_until_id} = '';
$hash->{helper}{eco_mode_id} = ''; $hash->{helper}{eco_mode_id} = '';
$hash->{helper}{button_config_time_id} = ''; $hash->{helper}{button_config_time_id} = '';
$hash->{helper}{winter_mode_id} = ''; $hash->{helper}{winter_mode_id} = '';
$hash->{helper}{_id} = ''; $hash->{helper}{_id} = '';
# IrrigationControl valve control max 6 # IrrigationControl valve control max 6
$hash->{helper}{schedules_paused_until_1_id} = ''; $hash->{helper}{schedules_paused_until_1_id} = '';
$hash->{helper}{schedules_paused_until_2_id} = ''; $hash->{helper}{schedules_paused_until_2_id} = '';
$hash->{helper}{schedules_paused_until_3_id} = ''; $hash->{helper}{schedules_paused_until_3_id} = '';
$hash->{helper}{schedules_paused_until_4_id} = ''; $hash->{helper}{schedules_paused_until_4_id} = '';
$hash->{helper}{schedules_paused_until_5_id} = ''; $hash->{helper}{schedules_paused_until_5_id} = '';
$hash->{helper}{schedules_paused_until_6_id} = ''; $hash->{helper}{schedules_paused_until_6_id} = '';
CommandAttr( undef, CommandAttr( undef,
"$name IODev $modules{GardenaSmartBridge}{defptr}{BRIDGE}->{NAME}" ) "$name IODev $modules{GardenaSmartBridge}{defptr}{BRIDGE}->{NAME}" )
@ -609,6 +609,7 @@ sub WriteReadings {
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $abilities = scalar( @{ $decode_json->{abilities} } ); my $abilities = scalar( @{ $decode_json->{abilities} } );
my $settings = scalar( @{ $decode_json->{settings} } ); my $settings = scalar( @{ $decode_json->{settings} } );
my $scheduled_events = scalar( @{ $decode_json->{scheduled_events} } );
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
@ -628,6 +629,7 @@ sub WriteReadings {
'watering' ) 'watering' )
) )
{ {
if ( $propertie->{name} eq 'button_config_time' ) { if ( $propertie->{name} eq 'button_config_time' ) {
if ( $hash->{helper}{ $propertie->{name} . '_id' } ne if ( $hash->{helper}{ $propertie->{name} . '_id' } ne
$decode_json->{abilities}[$abilities]{id} ) $decode_json->{abilities}[$abilities]{id} )
@ -764,6 +766,35 @@ sub WriteReadings {
$abilities--; $abilities--;
} while ( $abilities >= 0 ); } while ( $abilities >= 0 );
if (
exists( $decode_json->{scheduled_events} )
&& scalar ($decode_json->{scheduled_events} > 0
&& ref ($decode_json->{scheduled_events}) eq 'ARRAY' )
) {
readingsBulkUpdateIfChanged( $hash, 'scheduling-schedules_events_count',
scalar ($decode_json->{scheduled_events} ) );
my $valve_id = 1; # ic24 [1..6] | wc, pump [1]
for my $event_schedules ( @{ $decode_json->{scheduled_events} } ) {
$valve_id = $event_schedules->{valve_id} if ( exists($event_schedules->{valve_id} ) ); #ic24
while ( my ( $r, $v ) = each %{ $event_schedules } ) {
readingsBulkUpdateIfChanged( $hash, 'scheduling-schedules_event_valve_'
. $valve_id
. '_'
. $v,
$r) if (ref($v) ne 'HASH' );
readingsBulkUpdateIfChanged( $hash, 'scheduling-schedules_event_valve_'
. $valve_id
. '_'
. $v->{type},
join(',', @ { $v->{weekdays}}) ) if (ref($v) qe 'HASH' );
};
};
}; # fi scheduled_events
my $winter_mode; my $winter_mode;
do { do {
@ -882,55 +913,67 @@ sub setState {
: 'offline' ) : 'offline' )
if ( AttrVal( $name, 'model', 'unknown' ) eq 'mower' ); if ( AttrVal( $name, 'model', 'unknown' ) eq 'mower' );
# ic24 # ic24 / wc / electronic pump
if ( AttrVal( $name, 'model', 'unknown' ) eq 'ic24' ){
my @ic24opened_ventils; if ( AttrVal( $name, 'model', 'unknown' ) eq 'ic24'
my $state_string = ''; my $nearst_irrigation = '2038-01-18 00:00'; || AttrVal( $name, 'model', 'unknown' ) eq 'watering_computer'
my $has_scheduling = 0; my $longest_duration = 0; || AttrVal( $name, 'model', 'unknown' ) eq 'electronic_water_pump' ){
my @valves_connected = split(',', ReadingsVal( $name, 'ic24-valves_connected', '')); my @opened_valves;
for (@valves_connected){ my $state_string = ''; my $nearst_irrigation = '';
my $has_schedule = 0; my $longest_duration = 0;
my @valves_connected = AttrVal( $name, 'model', 'unknown' ) eq 'ic24' ? split(',', ReadingsVal( $name, 'ic24-valves_connected', '')) : '1';
for (@valves_connected){ # valves 1 or 1..6
## add to opened ventils, if watering active ## add to opened ventils, if watering active
push @ic24opened_ventils, $_ if ( ( ( ReadingsVal( $name, "watering-watering_timer_".$_."_duration", 0 ) =~ m{\A[1-9]([0-9]+)?\z}xms ) ? $_ : 0 ) > 0 ); push @opened_valves, $_ if ( ( ( ReadingsVal( $name, "watering-watering_timer_".$_."_duration", 0 ) =~ m{\A[1-9]([0-9]+)?\z}xms ) ? $_ : 0 ) > 0 );
## find nearst timestamp ## find longest irrigation duration
#$has_scheduling = 1 if ( ReadingsVal($name, 'scheduling-schedules_paused_until_'.$_ , '') ne '2038-01-18T00:00:00.000Z' && ReadingsVal($name, 'scheduling-schedules_paused_until_'.$_ , '') eq '' );
## wenn nicht dauerhaft pausiert , dann zeitplan vorhanden.
$has_scheduling = 1 if ( ReadingsVal($name, 'scheduling-schedules_paused_until_'.$_ , '') ne '2038-01-18T00:00:00.000Z' ); #&& ReadingsVal($name, 'scheduling-schedules_paused_until_'.$_ , '') eq '' );
#$has_scheduling = 1 if ( ReadingsVal($name, 'scheduling-schedules_paused_until_'.$_ , 'n/a') eq '' );
$longest_duration = ReadingsVal( $name, "watering-watering_timer_".$_."_irrigation_left", 0 ) if ( $longest_duration = ReadingsVal( $name, "watering-watering_timer_".$_."_irrigation_left", 0 ) if (
( ReadingsVal( $name, "watering-watering_timer_".$_."_duration", 0 ) =~ m{\A[1-9]([0-9]+)?\z}xms ( ReadingsVal( $name, "watering-watering_timer_".$_."_duration", 0 ) =~ m{\A[1-9]([0-9]+)?\z}xms
&& ReadingsVal( $name, "watering-watering_timer_".$_."_duration", 0 ) > 0 && ReadingsVal( $name, "watering-watering_timer_".$_."_duration", 0 ) > 0
&& ReadingsVal( $name, "watering-watering_timer_".$_."_duration", 0 ) > $longest_duration ) ); && ReadingsVal( $name, "watering-watering_timer_".$_."_duration", 0 ) > $longest_duration ) );
# if ( ReadingsVal($name, 'scheduling-scheduled_watering_next_start_'.$_, '') ne '' ## wenn nicht dauerhaft pausiert , dann zeitplan vorhanden oder datum der pause enthalten in T Zulu
# --- wenn next_start_x ne 'na' && paused_until_x eq '' -> start_x $has_scheduling = 1 if ( ReadingsVal($name, 'scheduling-schedules_paused_until_'.$_ , '') ne '2038-01-18T00:00:00.000Z' )
if ( ReadingsVal($name, 'scheduling-schedules_paused_until_'.$_ , '') ne '2038-01-18T00:00:00.000Z' ) {
# $nearst_irrigation = ReadingsVal($name, 'scheduling-scheduled_watering_next_start', '');
# $nearst_irrigation = RigReadingsValue($hash, ReadingsVal($name, 'scheduling-schedules_paused_until_'.$_, ''))
# if (
# Time::Piece->strptime( RigReadingsValue($hash, ReadingsVal($name, 'scheduling-schedules_paused_until_'.$_, '')), "%Y-%m-%d %H:%M") < Time::Piece->strptime( $nearst_irrigation, "%Y-%m-%d %H:%M")
# && $has_scheduling && Time::Piece->strptime( RigReadingsValue($hash, ReadingsVal($name, 'scheduling-schedules_paused_until_'.$_, '')), "%Y-%m-%d %H:%M") > Time::Piece->new
# )
if ( ReadingsVal($name, 'scheduling-scheduled_watering_next_start', '') eq '' ) { # non next start, schedules paused permanently or next schedule > 1 year; get nearst paused_until
$nearst_irrigation = RigReadingsValue($hash, ReadingsVal($name, 'scheduling-schedules_paused_until_'.$_, ''))
if ( Time::Piece->strptime( RigReadingsValue($hash, ReadingsVal($name, 'scheduling-schedules_paused_until_'.$_, '')), "%Y-%m-%d %H:%M")
< Time::Piece->strptime( $nearst_irrigation, "%Y-%m-%d %H:%M")
&& $has_scheduling
&& Time::Piece->strptime( RigReadingsValue($hash, ReadingsVal($name, 'scheduling-schedules_paused_until_'.$_, '')), "%Y-%m-%d %H:%M")
> Time::Piece->new
)
} else {
$nearst_irrigation = ReadingsVal($name, 'scheduling-scheduled_watering_next_start', '');
}
} # fi
#$nearst_irrigation = ReadingsVal($name, 'scheduling-scheduled_watering_next_start', ''); ######
# if ( ReadingsVal($name, 'scheduling-scheduled_watering_next_start_'.$_, 'n/a') ne 'n/a' ); ######
###### $has_scheduling = 1 if ( ReadingsVal($name, 'scheduling-schedules_paused_until_'.$_ , '') ne '2038-01-18T00:00:00.000Z' ); #&& ReadingsVal($name, 'scheduling-schedules_paused_until_'.$_ , '') eq '' );
} ###### #$has_scheduling = 1 if ( ReadingsVal($name, 'scheduling-schedules_paused_until_'.$_ , 'n/a') eq '' );
######
###### # if ( ReadingsVal($name, 'scheduling-scheduled_watering_next_start_'.$_, '') ne ''
###### # --- wenn next_start_x ne 'na' && paused_until_x eq '' -> start_x
###### ## scheduling-schedules_paused_until_* = leer oder n/a -> keine zeitpläne
######
###### if ( ReadingsVal($name, 'scheduling-schedules_paused_until_'.$_ , '') ne '2038-01-18T00:00:00.000Z' ) {
###### # $nearst_irrigation = ReadingsVal($name, 'scheduling-scheduled_watering_next_start', '');
###### Log3 $name, 3, "[DEBUG] - ";
######
###### # $nearst_irrigation = RigReadingsValue($hash, ReadingsVal($name, 'scheduling-schedules_paused_until_'.$_, ''))
###### # if (
###### # Time::Piece->strptime( RigReadingsValue($hash, ReadingsVal($name, 'scheduling-schedules_paused_until_'.$_, '')), "%Y-%m-%d %H:%M") < Time::Piece->strptime( $nearst_irrigation, "%Y-%m-%d %H:%M")
###### # && $has_scheduling && Time::Piece->strptime( RigReadingsValue($hash, ReadingsVal($name, 'scheduling-schedules_paused_until_'.$_, '')), "%Y-%m-%d %H:%M") > Time::Piece->new
###### # )
###### if ( ReadingsVal($name, 'scheduling-scheduled_watering_next_start', '') eq '' ) { # non next start, schedules paused permanently or next schedule > 1 year; get nearst paused_until
###### $nearst_irrigation = RigReadingsValue($hash, ReadingsVal($name, 'scheduling-schedules_paused_until_'.$_, ''))
###### if ( Time::Piece->strptime( RigReadingsValue($hash, ReadingsVal($name, 'scheduling-schedules_paused_until_'.$_, '')), "%Y-%m-%d %H:%M")
###### < Time::Piece->strptime( $nearst_irrigation, "%Y-%m-%d %H:%M")
###### && $has_scheduling
###### && Time::Piece->strptime( RigReadingsValue($hash, ReadingsVal($name, 'scheduling-schedules_paused_until_'.$_, '')), "%Y-%m-%d %H:%M")
###### > Time::Piece->new
###### )
###### } else {
###### $nearst_irrigation = ReadingsVal($name, 'scheduling-scheduled_watering_next_start', '');
###### }
###### } # fi
######
###### #$nearst_irrigation = ReadingsVal($name, 'scheduling-scheduled_watering_next_start', '');
###### # if ( ReadingsVal($name, 'scheduling-scheduled_watering_next_start_'.$_, 'n/a') ne 'n/a' );
######
} # for
# override state 4 extendedstates # override state 4 extendedstates
if ( AttrVal( $name, "extendedState", 0 ) == 1) { if ( AttrVal( $name, "extendedState", 0 ) == 1) {
if (scalar(@ic24opened_ventils) > 0){ if (scalar(@opened_valves) > 0){
## valve 1 will be ir.. 23 minutes remaining ## valve 1 will be ir.. 23 minutes remaining
for (@valves_connected){ for (@valves_connected){
$state_string .= sprintf(RigReadingsValue($hash,'valve').' '.$_.' '.(RigReadingsValue($hash, 'will be irrigated %.f minutes remaining.') .'</br>'), (ReadingsVal( $name, 'watering-watering_timer_'.$_.'_duration', 0 )/60)); $state_string .= sprintf(RigReadingsValue($hash,'valve').' '.$_.' '.(RigReadingsValue($hash, 'will be irrigated %.f minutes remaining.') .'</br>'), (ReadingsVal( $name, 'watering-watering_timer_'.$_.'_duration', 0 )/60));
@ -947,8 +990,8 @@ sub setState {
' ) ' )
if ( AttrVal( $name, 'stateFormat', 'none' ) eq 'none' ); if ( AttrVal( $name, 'stateFormat', 'none' ) eq 'none' );
} else { } else {
Log3 $name, 3, "[DEBUG] - Offene Ventile :".scalar(@ic24opened_ventils)." laengste bewaesserung: $longest_duration . hat Zeitplan: $has_scheduling Naechster Zeitplan: $nearst_irrigation"; Log3 $name, 3, "[DEBUG] - Offene Ventile :".scalar(@opened_valves)." laengste bewaesserung: $longest_duration . hat Zeitplan: $has_scheduling Naechster Zeitplan: $nearst_irrigation";
$state_string = scalar(@ic24opened_ventils) > 0 $state_string = scalar(@opened_valves) > 0
# offen # offen
? sprintf( (RigReadingsValue($hash, 'will be irrigated %.f minutes remaining.')), $longest_duration/60) ? sprintf( (RigReadingsValue($hash, 'will be irrigated %.f minutes remaining.')), $longest_duration/60)
# zu # zu
@ -1029,36 +1072,37 @@ sub setState {
# Wird bewässert xx Minuten verbleibend" und "Nächste Bewässerung heute um xx:yy Uhr" # Wird bewässert xx Minuten verbleibend" und "Nächste Bewässerung heute um xx:yy Uhr"
# 4. Ventil manuell geoeffnet, Zeitpläne deaktiviert. # 4. Ventil manuell geoeffnet, Zeitpläne deaktiviert.
# App zeigt: "Wird bewässert xx Minuten verbleibend" # App zeigt: "Wird bewässert xx Minuten verbleibend"
if ( AttrVal( $name, 'model', 'unknown' ) eq 'watering_computer' ){ ### CHANGE to one
# if ( AttrVal( $name, 'model', 'unknown' ) eq 'watering_computer' ){
my $state_string = ReadingsVal( $name, 'watering-watering_timer_1_duration', 0 ) =~ # my $state_string = ReadingsVal( $name, 'watering-watering_timer_1_duration', 0 ) =~
m{\A[1-9]([0-9]+)?\z}xms # m{\A[1-9]([0-9]+)?\z}xms
# offen # # offen
? # ?
( ReadingsVal($name, 'scheduling-schedules_paused_until', '' ) eq '' ) # ( ReadingsVal($name, 'scheduling-schedules_paused_until', '' ) eq '' )
# leer ( zeitplan aktiv ... ) # # leer ( zeitplan aktiv ... )
? sprintf( (RigReadingsValue($hash, 'will be irrigated %.f minutes remaining.').' '.RigReadingsValue($hash, 'next watering: %s')), (ReadingsVal( $name, 'watering-watering_timer_1_irrigation_left', 0 )/60), RigReadingsValue($hash, ReadingsVal($name, 'scheduling-scheduled_watering_next_start', '')) ) # ? sprintf( (RigReadingsValue($hash, 'will be irrigated %.f minutes remaining.').' '.RigReadingsValue($hash, 'next watering: %s')), (ReadingsVal( $name, 'watering-watering_timer_1_irrigation_left', 0 )/60), RigReadingsValue($hash, ReadingsVal($name, 'scheduling-scheduled_watering_next_start', '')) )
# zeitplan pausiert # # zeitplan pausiert
: # :
( ReadingsVal($name, 'scheduling-schedules_paused_until', '') eq '2038-01-18T00:00:00.000Z') # ( ReadingsVal($name, 'scheduling-schedules_paused_until', '') eq '2038-01-18T00:00:00.000Z')
# pause bis dauerhaft # # pause bis dauerhaft
? sprintf( (RigReadingsValue($hash, 'will be irrigated %.f minutes remaining.').' '.RigReadingsValue($hash , 'schedule permanently paused')), (ReadingsVal( $name, 'watering-watering_timer_1_irrigation_left', 0 )/60) ) # ? sprintf( (RigReadingsValue($hash, 'will be irrigated %.f minutes remaining.').' '.RigReadingsValue($hash , 'schedule permanently paused')), (ReadingsVal( $name, 'watering-watering_timer_1_irrigation_left', 0 )/60) )
# naechter termin # # naechter termin
: sprintf( RigReadingsValue($hash , 'paused until %s'), RigReadingsValue($hash, ReadingsVal($name, 'scheduling-schedules_paused_until', '')) ) # : sprintf( RigReadingsValue($hash , 'paused until %s'), RigReadingsValue($hash, ReadingsVal($name, 'scheduling-schedules_paused_until', '')) )
# zu # # zu
: # :
( ReadingsVal($name, 'scheduling-schedules_paused_until', '' ) eq '' ) # ( ReadingsVal($name, 'scheduling-schedules_paused_until', '' ) eq '' )
# zeitplan aktiv # # zeitplan aktiv
? sprintf( (RigReadingsValue($hash, 'closed') .'. '.RigReadingsValue($hash, 'next watering: %s')), RigReadingsValue($hash, ReadingsVal($name, 'scheduling-scheduled_watering_next_start', '') ) ) # ? sprintf( (RigReadingsValue($hash, 'closed') .'. '.RigReadingsValue($hash, 'next watering: %s')), RigReadingsValue($hash, ReadingsVal($name, 'scheduling-scheduled_watering_next_start', '') ) )
# zeitplan pausiert # # zeitplan pausiert
: RigReadingsValue($hash, 'closed') # : RigReadingsValue($hash, 'closed')
; # ;
# state offline | override # # state offline | override
$state_string = 'offline' if ($online_state eq 'offline'); # $state_string = 'offline' if ($online_state eq 'offline');
readingsBulkUpdate( # readingsBulkUpdate(
$hash, 'state', RigReadingsValue( $hash, $state_string ) ); # $hash, 'state', RigReadingsValue( $hash, $state_string ) );
} # }
if ( AttrVal( $name, 'model', 'unknown' ) =~ /sensor.?/ ) { if ( AttrVal( $name, 'model', 'unknown' ) =~ /sensor.?/ ) {
my $state_string = my $state_string =

View File

@ -1,2 +1,2 @@
UPD 2022-07-01_16:13:02 49241 FHEM/73_GardenaSmartBridge.pm UPD 2022-07-01_16:13:02 49241 FHEM/73_GardenaSmartBridge.pm
UPD 2022-07-07_20:04:59 71767 FHEM/74_GardenaSmartDevice.pm UPD 2022-07-08_12:29:06 73951 FHEM/74_GardenaSmartDevice.pm