From 52044cbc51be191b2aa72ce10ba2cd1461b703d7 Mon Sep 17 00:00:00 2001 From: justme-1968 Date: Sat, 24 Sep 2016 10:31:26 +0000 Subject: [PATCH] 31_HUEDevice.pm: added createActionReadings attribute git-svn-id: https://svn.fhem.de/fhem/trunk@12205 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/31_HUEDevice.pm | 80 +++++++++++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 8 deletions(-) diff --git a/fhem/FHEM/31_HUEDevice.pm b/fhem/FHEM/31_HUEDevice.pm index d2c5d5121..ef2f6029a 100644 --- a/fhem/FHEM/31_HUEDevice.pm +++ b/fhem/FHEM/31_HUEDevice.pm @@ -154,6 +154,7 @@ sub HUEDevice_Initialize($) $hash->{GetFn} = "HUEDevice_Get"; $hash->{AttrFn} = "HUEDevice_Attr"; $hash->{AttrList} = "IODev ". + "createActionReadings:1,0 ". "delayedUpdate:1 ". "ignoreReachable:1,0 ". "realtimePicker:1,0 ". @@ -1069,19 +1070,80 @@ HUEDevice_Parse($$) if( $hash->{helper}->{devtype} eq 'G' ) { $hash->{STATE} = 'Initialized'; - $hash->{lights} = join( ",", @{$result->{lights}} ) if( $result->{lights} ); + if( $result->{lights} ) { + $hash->{lights} = join( ",", @{$result->{lights}} ); + } else { + $hash->{lights} = ''; + } if( ref($result->{state}) eq 'HASH' ) { - my $all_on = $result->{state}{all_on}; - my $any_on = $result->{state}{any_on}; + my %readings; + + if( $result->{state} ) { + $readings{all_on} = $result->{state}{all_on}; + $readings{any_on} = $result->{state}{any_on}; + } + if( AttrVal($name, 'createActionReadings', 0) ) { + if( my $state = $result->{action} ) { + $readings{ct} = $state->{ct}; $readings{ct} .= " (".int(1000000/$readings{ct})."K)" if( $readings{ct} ); + $readings{hue} = $state->{hue}; + $readings{sat} = $state->{sat}; + $readings{bri} = $state->{bri}; $readings{bri} = $hash->{helper}{bri} if( !defined($readings{bri}) ); + $readings{xy} = $state->{'xy'}->[0] .",". $state->{'xy'}->[1] if( defined($state->{'xy'}) ); + $readings{colormode} = $state->{colormode}; + + $readings{alert} = $state->{alert}; + $readings{effect} = $state->{effect}; + + $readings{reachable} = $state->{reachable}?1:0 if( defined($state->{reachable}) ); + + my $s = ''; + my $percent = -1; + my $on = $state->{on}; $readings{on} = $hash->{helper}{onoff} if( !defined($on) ); + if( $on ) + { + $s = 'on'; + $readings{onoff} = 1; + + if( !defined($readings{bri}) || AttrVal($name, 'subType', 'dimmer') eq 'switch' ) { + $percent = 100; + + } else { + $percent = int($readings{bri} * 99 / 254 + 1); + if( $percent > 0 + && $percent < 100 ) { + $s = $dim_values{int($percent/7)}; + } + $s = 'off' if( $percent == 0 ); + + } + } + else + { + $on = 0; + $s = 'off'; + $percent = 0; + + $readings{onoff} = 0; + } + + $readings{percent} = $percent; + + $s = 'unreachable' if( defined($readings{reachable}) && !$readings{reachable} ); + #$readings{state} = $s; + + } readingsBeginUpdate($hash); - readingsBulkUpdate($hash, "all_on", $all_on) if( defined($all_on) && $all_on != $hash->{helper}{all_on} ); - readingsBulkUpdate($hash, "any_on", $any_on) if( defined($any_on) && $any_on != $hash->{helper}{any_on} ); + foreach my $key ( keys %readings ) { + if( defined($readings{$key}) ) { + readingsBulkUpdate($hash, $key, $readings{$key}, 1) if( !defined($hash->{helper}{$key}) || $hash->{helper}{$key} ne $readings{$key} ); + $hash->{helper}{$key} = $readings{$key}; + } + } readingsEndUpdate($hash,1); - $hash->{helper}{all_on} = $all_on if( defined($all_on) ); - $hash->{helper}{any_on} = $any_on if( defined($any_on) ); + } } if( defined($hash->{helper}->{update}) ) { @@ -1341,7 +1403,7 @@ HUEDevice_Attr($$$;$) =pod =item summary devices connected to a phillips hue bridge or a osram lightify gateway -=item summary_DE Geräte an einer Philips HUE Bridge oder einem Osram LIGHTIFY Gateway +=item summary_DE Geräte an einer Philips HUE Bridge oder einem Osram LIGHTIFY Gateway =begin html @@ -1480,6 +1542,8 @@ HUEDevice_Attr($$$;$)
  • color-icon
    1 -> use lamp color as icon color and 100% shape as icon shape
    2 -> use lamp color scaled to full brightness as icon color and dim state as icon shape
  • +
  • createActionReadings
    + create readings for the last action in group devices
  • ignoreReachable
    ignore the reachable state that is reported by the hue bridge. assume the device is allways reachable.
  • setList