2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

30_HUEBridge.pm: added schedules (by PPP01)

git-svn-id: https://svn.fhem.de/fhem/trunk@19048 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
justme-1968 2019-03-27 15:39:25 +00:00
parent fb74cee065
commit 93dffac53b
2 changed files with 64 additions and 2 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # 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. # 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 - change: 74_GardenaSmartDevice: change on-for-timer time format
- feature: 74_GardenaSmartDevice: add support for power plug and META - feature: 74_GardenaSmartDevice: add support for power plug and META
- feature: 73_GardenaSmartBridge: add support for power plug and META - feature: 73_GardenaSmartBridge: add support for power plug and META

View File

@ -34,6 +34,8 @@ sub HUEBridge_Initialize($)
$hash->{AttrFn} = "HUEBridge_Attr"; $hash->{AttrFn} = "HUEBridge_Attr";
$hash->{UndefFn} = "HUEBridge_Undefine"; $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->{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 sub
@ -695,6 +697,33 @@ HUEBridge_Set($@)
return undef; return undef;
} elsif($cmd eq 'updateschedule') {
return "usage: updateschedule <id> <attributes json>" 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 <id>" 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') { } elsif($cmd eq 'deleterule') {
return "usage: deleterule <id>" if( @args != 1 ); return "usage: deleterule <id>" if( @args != 1 );
return "$arg is not a hue rule number" if( $arg !~ m/^\d+$/ ); return "$arg is not a hue rule number" if( $arg !~ m/^\d+$/ );
@ -835,7 +864,7 @@ HUEBridge_Set($@)
return undef; return undef;
} else { } 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' ); $list .= " swupdate:noArg" if( defined($hash->{updatestate}) && $hash->{updatestate} =~ '^2' );
return "Unknown argument $cmd, choose one of $list"; return "Unknown argument $cmd, choose one of $list";
} }
@ -926,6 +955,30 @@ HUEBridge_Get($@)
$ret = sprintf( "%2s %-20s\n", "ID", "NAME" ) .$ret if( $ret ); $ret = sprintf( "%2s %-20s\n", "ID", "NAME" ) .$ret if( $ret );
} }
return $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') { } elsif($cmd eq 'sensors') {
my $result = HUEBridge_Call($hash, undef, 'sensors', undef); my $result = HUEBridge_Call($hash, undef, 'sensors', undef);
@ -978,7 +1031,7 @@ HUEBridge_Get($@)
return $ret; return $ret;
} else { } 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) ) { if( $hash->{helper}{apiversion} && $hash->{helper}{apiversion} >= (1<<16) + (26<<8) ) {
$list .= " startup:noArg"; $list .= " startup:noArg";
} }
@ -1874,6 +1927,8 @@ HUEBridge_Attr($$$)
list the groups known to the bridge.</li> list the groups known to the bridge.</li>
<li>scenes [detail]<br> <li>scenes [detail]<br>
list the scenes known to the bridge.</li> list the scenes known to the bridge.</li>
<li>schedules [detail]<br>
list the schedules known to the bridge.</li>
<li>startup<br> <li>startup<br>
show startup behavior of all known lights</li> show startup behavior of all known lights</li>
<li>rule &lt;id&gt; <br> <li>rule &lt;id&gt; <br>
@ -1909,6 +1964,12 @@ HUEBridge_Attr($$$)
Modifys the given scene in the bridge.</li> Modifys the given scene in the bridge.</li>
<li>scene &lt;id&gt;<br> <li>scene &lt;id&gt;<br>
Recalls the scene with the given id.</li> Recalls the scene with the given id.</li>
<li>updateschedule &lt;id&gt; &lt;attributes json&gt;<br>
updates the given schedule in the bridge with &lt;attributes json&gt; </li>
<li>enableschedule &lt;id&gt;<br>
enables the given shedule</li>
<li>disableschedule &lt;id&gt;<br>
disables the given shedule</li>
<li>createrule &lt;name&gt; &lt;conditions&amp;actions json&gt;<br> <li>createrule &lt;name&gt; &lt;conditions&amp;actions json&gt;<br>
Creates a new rule in the bridge.</li> Creates a new rule in the bridge.</li>
<li>deleterule &lt;id&gt;<br> <li>deleterule &lt;id&gt;<br>