diff --git a/fhem/CHANGED b/fhem/CHANGED index 5341facae..b918c1eec 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: 30_HUEBridge: added schedules (by PPP01) - change: 74_GardenaSmartDevice: change on-for-timer time format - feature: 74_GardenaSmartDevice: add support for power plug and META - feature: 73_GardenaSmartBridge: add support for power plug and META diff --git a/fhem/FHEM/30_HUEBridge.pm b/fhem/FHEM/30_HUEBridge.pm index eb6257606..3e7482417 100644 --- a/fhem/FHEM/30_HUEBridge.pm +++ b/fhem/FHEM/30_HUEBridge.pm @@ -34,6 +34,8 @@ sub HUEBridge_Initialize($) $hash->{AttrFn} = "HUEBridge_Attr"; $hash->{UndefFn} = "HUEBridge_Undefine"; $hash->{AttrList} = "key disable:1 disabledForIntervals createGroupReadings:1,0 httpUtils:1,0 noshutdown:1,0 pollDevices:1,2,0 queryAfterSet:1,0 $readingFnAttributes"; + + #$hash->{isDiscoverable} = { ssdp => {'hue-bridgeid' => '/.*/'}, upnp => {} }; } sub @@ -695,6 +697,33 @@ HUEBridge_Set($@) return undef; + } elsif($cmd eq 'updateschedule') { + return "usage: updateschedule " if( @args != 2 ); + return "$arg is not a hue schedule number" if( $arg !~ m/^\d+$/ ); + + my $json = $args[@args-1]; + my $obj = eval { decode_json($json) }; + if( $@ ) { + Log3 $name, 2, "$name: json error: $@ in $json"; + return undef; + } + + my $result; + $result = HUEBridge_Call($hash, undef, "schedules/$arg", $obj, 'PUT'); + return "Error: " . $result->{error}{description} if( $result->{error} ); + return "Schedule id $arg updated" if( $result->{success} ); + return undef; + + } elsif($cmd eq 'enableschedule' || $cmd eq 'disableschedule') { + return "usage: $cmd " if( @args != 1 ); + return "$arg is not a hue schedule number" if( $arg !~ m/^\d+$/ ); + + my $newStatus = 'enabled'; + $newStatus = 'disabled' if($cmd eq 'disableschedule'); + + $args[1] = sprintf( '{"status":"%s"}', $newStatus ); + return HUEBridge_Set($hash, $name,'updateschedule',@args) + } elsif($cmd eq 'deleterule') { return "usage: deleterule " if( @args != 1 ); return "$arg is not a hue rule number" if( $arg !~ m/^\d+$/ ); @@ -835,7 +864,7 @@ HUEBridge_Set($@) return undef; } else { - my $list = "active inactive delete creategroup deletegroup savescene deletescene modifyscene scene createrule updaterule deleterule createsensor deletesensor configsensor setsensor updatesensor deletewhitelist touchlink:noArg checkforupdate:noArg autodetect:noArg autocreate:noArg statusRequest:noArg"; + my $list = "active inactive delete creategroup deletegroup savescene deletescene modifyscene scene createrule updaterule updateschedule enableschedule disableschedule deleterule createsensor deletesensor configsensor setsensor updatesensor deletewhitelist touchlink:noArg checkforupdate:noArg autodetect:noArg autocreate:noArg statusRequest:noArg"; $list .= " swupdate:noArg" if( defined($hash->{updatestate}) && $hash->{updatestate} =~ '^2' ); return "Unknown argument $cmd, choose one of $list"; } @@ -926,6 +955,30 @@ HUEBridge_Get($@) $ret = sprintf( "%2s %-20s\n", "ID", "NAME" ) .$ret if( $ret ); } return $ret; + } elsif($cmd eq 'schedules') { + my $result = HUEBridge_Call($hash, undef, 'schedules', undef); + return $result->{error}{description} if( $result->{error} ); + + # 064:MO + # 032:DI + # 016:MI + # 008:DO + # 004:FR + # 002:SA + # 001:SO + my $ret = ""; + foreach my $key ( sort {$a<=>$b} keys %{$result} ) { + $ret .= sprintf( "%2i: %-20s %-12s", $key, $result->{$key}{name},$result->{$key}{status} ); + $ret .= sprintf( "%s", $result->{$key}{localtime} ) if( $arg && $arg eq 'detail' ); + + $ret .= "\n"; + } + if( $arg && $arg eq 'detail' ) { + $ret = sprintf( "%2s %-20s %-11s %s\n", "ID", "NAME", "STATUS", "TIME" ) .$ret if( $ret ); + } else { + $ret = sprintf( "%2s %-20s %-12s\n", "ID", "NAME", "STATUS" ) .$ret if( $ret ); + } + return $ret; } elsif($cmd eq 'sensors') { my $result = HUEBridge_Call($hash, undef, 'sensors', undef); @@ -978,7 +1031,7 @@ HUEBridge_Get($@) return $ret; } else { - my $list = "lights:noArg groups:noArg scenes:noArg rule rules:noArg sensors:noArg whitelist:noArg"; + my $list = "lights:noArg groups:noArg scenes:noArg rule rules:noArg sensors:noArg schedules:noArg whitelist:noArg"; if( $hash->{helper}{apiversion} && $hash->{helper}{apiversion} >= (1<<16) + (26<<8) ) { $list .= " startup:noArg"; } @@ -1874,6 +1927,8 @@ HUEBridge_Attr($$$) list the groups known to the bridge.
  • scenes [detail]
    list the scenes known to the bridge.
  • +
  • schedules [detail]
    + list the schedules known to the bridge.
  • startup
    show startup behavior of all known lights
  • rule <id>
    @@ -1909,6 +1964,12 @@ HUEBridge_Attr($$$) Modifys the given scene in the bridge.
  • scene <id>
    Recalls the scene with the given id.
  • +
  • updateschedule <id> <attributes json>
    + updates the given schedule in the bridge with <attributes json>
  • +
  • enableschedule <id>
    + enables the given shedule
  • +
  • disableschedule <id>
    + disables the given shedule
  • createrule <name> <conditions&actions json>
    Creates a new rule in the bridge.
  • deleterule <id>