From c7d511fb6a832d70d031d1410989a36cb09c51dd Mon Sep 17 00:00:00 2001 From: justme1968 Date: Sat, 16 Mar 2013 21:46:32 +0000 Subject: [PATCH] added effect and transitiontime command allow multiple commands in one set git-svn-id: https://fhem.svn.sourceforge.net/svnroot/fhem/trunk/fhem@2934 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- FHEM/31_HUEDevice.pm | 255 +++++++++---------------------------------- 1 file changed, 50 insertions(+), 205 deletions(-) diff --git a/FHEM/31_HUEDevice.pm b/FHEM/31_HUEDevice.pm index 3b5fab224..f7a458e37 100644 --- a/FHEM/31_HUEDevice.pm +++ b/FHEM/31_HUEDevice.pm @@ -207,6 +207,10 @@ HUEDevice_SetParam($$@) $obj->{'hue'} = int($h*256); $obj->{'sat'} = 0+$s; $obj->{'bru'} = 0+$v; + } elsif( $cmd eq "effect" ) { + $obj->{'effect'} = $value; + } elsif( $cmd eq "transitiontime" ) { + $obj->{'transitiontime'} = 0+$value; } else { return 0; } @@ -219,211 +223,45 @@ HUEDevice_Set($@) { my ($hash, $name, @aa) = @_; - #my %obj; + my %obj; if( (my $joined = join(" ", @aa)) =~ /:/ ) { my @cmds = split(":", $joined); for( my $i = 0; $i <= $#cmds; ++$i ) { - HUEDevice_Set( $hash, $name, split(" ", $cmds[$i]) ); - #HUEDevice_SetParam($name, \%obj, split(" ", $cmds[$i]) ); + HUEDevice_SetParam($name, \%obj, split(" ", $cmds[$i]) ); } - return; - } - - my ($cmd, $value, $value2, @a) = @aa; - - if( $cmd eq "statusRequest" ) { - RemoveInternalTimer($hash); - HUEDevice_GetUpdate($hash); - return undef; - } - - #HUEDevice_SetParam($name, \%obj, $cmd, $value, $value2); - - if( $cmd eq "color" ) { - $value = int(1000000/$value); - $cmd = 'ct'; - } elsif( $cmd eq "toggle" ) { - $cmd = ReadingsVal($name,"state","on") eq "off" ? "on" :"off"; - } elsif( $cmd =~ m/^dim(\d+)/ ) { - $value = $1 unless defined($value); - if( $value < 0 ) { $value = 0; } - if( $value > 100 ) { $value = 100; } - $cmd = 'pct'; - } elsif( !defined($value) && $cmd =~ m/^(\d+)/) { - $value = $1; - $value = 254 if( $value > 254 ); - $cmd = 'bri'; - } - - if($cmd eq 'on') { - - my $obj = { - 'on' => JSON::true, - }; - $obj->{bri} = 254 if( ReadingsVal($name,"bri","0") eq 0 ); - if( defined($value) ) { - $obj->{transitiontime} = $value / 10; - } - - my $result = HUEDevice_ReadFromServer($hash,$hash->{fhem}{id}."/state",$obj); - if( $result->{'error'} ) { - $hash->{STATE} = $result->{'error'}->{'description'}; - return undef; - } - } elsif($cmd eq 'off') { - - my $obj = { - 'on' => JSON::false, - }; - if( defined($value) ) { - $obj->{transitiontime} = $value / 10; - } - - my $result = HUEDevice_ReadFromServer($hash,$hash->{fhem}{id}."/state",$obj); - if( $result->{'error'} ) { - $hash->{STATE} = $result->{'error'}->{'description'}; - return undef; - } - } elsif($cmd eq "pct") { - my $obj = { - 'bri' => int(2.54 * $value), - 'on' => JSON::true, - }; - if( defined($value2) ) { - $obj->{transitiontime} = $value2 / 10; - } - - my $result = HUEDevice_ReadFromServer($hash,$hash->{fhem}{id}."/state",$obj); - if( $result->{'error'} ) { - $hash->{STATE} = $result->{'error'}->{'description'}; - return undef; - } - } elsif($cmd eq "bri") { - my $obj = { - 'bri' => 0+$value, - 'on' => JSON::true, - }; - - my $result = HUEDevice_ReadFromServer($hash,$hash->{fhem}{id}."/state",$obj); - if( $result->{'error'} ) { - $hash->{STATE} = $result->{'error'}->{'description'}; - return undef; - } - } elsif($cmd eq "ct") { - my $obj = { - 'ct' => 0+$value, - 'on' => JSON::true, - }; - - my $result = HUEDevice_ReadFromServer($hash,$hash->{fhem}{id}."/state",$obj); - if( $result->{'error'} ) { - $hash->{STATE} = $result->{'error'}->{'description'}; - return undef; - } - } elsif($cmd eq "hue") { - my $obj = { - 'hue' => 0+$value, - 'on' => JSON::true, - }; - - my $result = HUEDevice_ReadFromServer($hash,$hash->{fhem}{id}."/state",$obj); - if( $result->{'error'} ) { - $hash->{STATE} = $result->{'error'}->{'description'}; - return undef; - } - } elsif($cmd eq "sat") { - my $obj = { - 'sat' => 0+$value, - 'on' => JSON::true, - }; - - my $result = HUEDevice_ReadFromServer($hash,$hash->{fhem}{id}."/state",$obj); - if( $result->{'error'} ) { - $hash->{STATE} = $result->{'error'}->{'description'}; - return undef; - } - } elsif($cmd eq "xy" && $value =~ m/^(.+),(.+)/) { - my ($x,$y) = ($1, $2); - - my $obj = { - 'xy' => [0+$x, 0+$y], - 'on' => JSON::true, - }; - - my $result = HUEDevice_ReadFromServer($hash,$hash->{fhem}{id}."/state",$obj); - if( $result->{'error'} ) { - $hash->{STATE} = $result->{'error'}->{'description'}; - return undef; - } - } elsif( $cmd eq "rgb" && $value =~ m/^(..)(..)(..)/) { - # calculation from http://www.everyhue.com/vanilla/discussion/94/rgb-to-xy-or-hue-sat-values/p1 - my( $r, $g, $b ) = (hex($1)/255.0, hex($2)/255.0, hex($3)/255.0); -#Log 3, "rgb: ". $r . " " . $g ." ". $b; - - my $X = 1.076450 * $r - 0.237662 * $g + 0.161212 * $b; - my $Y = 0.410964 * $r + 0.554342 * $g + 0.034694 * $b; - my $Z = -0.010954 * $r - 0.013389 * $g + 1.024343 * $b; -#Log 3, "XYZ: ". $X . " " . $Y ." ". $Y; - - if( $X != 0 - || $Y != 0 - || $Z != 0 ) { - my $x = $X / ($X + $Y + $Z); - my $y = $Y / ($X + $Y + $Z); -#Log 3, "xyY:". $x . " " . $y ." ". $Y; - - #$x = 0 if( $x < 0 ); - #$x = 1 if( $x > 1 ); - #$y = 0 if( $y < 0 ); - #$y = 1 if( $y > 1 ); - $Y = 1 if( $Y > 1 ); - - my $bri = max($r,max($g,$b)); - #my $bri = $Y; - my $obj = { - 'xy' => [0+$x, 0+$y], - 'bri' => int(254*$bri), - 'on' => JSON::true, - }; - - my $result = HUEDevice_ReadFromServer($hash,$hash->{fhem}{id}."/state",$obj); - if( $result->{'error'} ) { - $hash->{STATE} = $result->{'error'}->{'description'}; - return undef; - } - } - } elsif( $cmd eq "hsv" && $value =~ m/^(..)(..)(..)/) { - my( $h, $s, $v ) = (hex($1), hex($2), hex($3)); - - $s = 254 if( $s > 254 ); - $v = 254 if( $v > 254 ); - - my $obj = { - 'hue' => int($h*256), - 'sat' => 0+$s, - 'bri' => 0+$v, - 'on' => JSON::true, - }; - - my $result = HUEDevice_ReadFromServer($hash,$hash->{fhem}{id}."/state",$obj); - if( $result->{'error'} ) { - $hash->{STATE} = $result->{'error'}->{'description'}; - return undef; - } } else { - my $list = "off on toggle statusRequest"; - $list .= " pct:slider,0,1,100 bri:slider,0,1,254" if( AttrVal($hash->{NAME}, "subType", "colordimmer") =~ m/dimmer/ ); - #$list .= " dim06% dim12% dim18% dim25% dim31% dim37% dim43% dim50% dim56% dim62% dim68% dim75% dim81% dim87% dim93% dim100%" if( AttrVal($hash->{NAME}, "subType", "colordimmer") =~ m/dimmer/ ); - $list .= " rgb:colorpicker,RGB color:slider,2000,1,6500 ct:slider,154,1,500 hue:slider,0,1,65535 sat:slider,0,1,254 xy" if( AttrVal($hash->{NAME}, "subType", "colordimmer") =~ m/color/ ); - return SetExtensions($hash, $list, $name, $cmd, $value, @a); + my ($cmd, $value, $value2, @a) = @aa; + + if( $cmd eq "statusRequest" ) { + RemoveInternalTimer($hash); + HUEDevice_GetUpdate($hash); + return undef; + } + + HUEDevice_SetParam($name, \%obj, $cmd, $value, $value2); } - $hash->{LOCAL} = 1; - HUEDevice_GetUpdate($hash); - delete $hash->{LOCAL}; - return undef; + if( scalar keys %obj ) { + my $result = HUEDevice_ReadFromServer($hash,$hash->{fhem}{id}."/state",\%obj); + if( $result->{'error'} ) { + $hash->{STATE} = $result->{'error'}->{'description'}; + return undef; + } + + $hash->{LOCAL} = 1; + HUEDevice_GetUpdate($hash); + delete $hash->{LOCAL}; + + return undef; + } + + my $list = "off on toggle statusRequest"; + $list .= " pct:slider,0,1,100 bri:slider,0,1,254" if( AttrVal($hash->{NAME}, "subType", "colordimmer") =~ m/dimmer/ ); + #$list .= " dim06% dim12% dim18% dim25% dim31% dim37% dim43% dim50% dim56% dim62% dim68% dim75% dim81% dim87% dim93% dim100%" if( AttrVal($hash->{NAME}, "subType", "colordimmer") =~ m/dimmer/ ); + $list .= " rgb:colorpicker,RGB color:slider,2000,1,6500 ct:slider,154,1,500 hue:slider,0,1,65535 sat:slider,0,1,254 xy effect:none,colorloop" if( AttrVal($hash->{NAME}, "subType", "colordimmer") =~ m/color/ ); + return SetExtensions($hash, $list, $name, @aa); } sub @@ -452,7 +290,6 @@ HUEDevice_Get($@) $r = 0 if( $r < 0 ); $r = 255 if( $r > 255 ); - $g; if( $temp <= 66 ) { $g = 99.4708025861 * log($temp) - 161.1195681661; } else { @@ -721,11 +558,8 @@ HUEDevice_GetUpdate($)
  • statusRequest
    Request device status update.
  • pct <value> [<ramp-time>]
    - dim to <value>
  • - Notes: -
    + dim to <value>
    + Note: the FS20 compatible dimXX% commands are also accepted.
  • color <value>
    set colortemperature to <value> kelvin.
  • bri <value>
    @@ -736,9 +570,20 @@ HUEDevice_GetUpdate($) set hue to <value>; range is 0-65535.
  • sat <value>
    set saturation to <value>; range is 0-254.
  • -
  • x <x>,<y>
    - set the xy color coordinates to <x>,<y>;
  • +
  • xy <x>,<y>
    + set the xy color coordinates to <x>,<y>
  • +
  • effect [none|colorloop]
  • +
  • transitiontime <time>
    + set the transitiontime to <time> 1/10s
  • rgb <rrggbb>
  • +
    + Note: +
    @@ -755,7 +600,7 @@ HUEDevice_GetUpdate($)
  • subType
    dimmer or switch, default is dimmer.
  • devStateIcon
    - will be initialized to {CommandGet("","<name> devStateIcon")} as default to show device color in room overview.
  • + will be initialized to {CommandGet("","<name> devStateIcon")} to show device color as default in room overview.