Skip to content

Commit

Permalink
Shelly Transformer: Tunable White
Browse files Browse the repository at this point in the history
  • Loading branch information
christianTF committed Apr 26, 2021
1 parent 9cc3984 commit edf573c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions data/transform/shipped/udpin/shelly/shelly_rgb&w.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,40 @@

$data = array (
'effect' => 0,
'gain' => 100,
'turn' => 'on',
'mode' => 'color'
);

switch ($command) {
// Color mode
case 'white':
$white = round( $value_pct / 100 * 255 );
$data['mode'] = "color";
$data['gain'] = 100;
$data['white'] = $white;
break;

case 'rgb':
$rgb_pct = str_pad( $value_pct, 9, '0', STR_PAD_LEFT );
$red = round( substr( $rgb_pct, -3, 3) / 100 * 255 );
$green = round( substr( $rgb_pct, -6, 3) / 100 * 255 );
$blue = round( substr( $rgb_pct, -9, 3) / 100 * 255 );
$data['mode'] = "color";
$data['gain'] = 100;
$data['red'] = $red;
$data['green'] = $green;
$data['blue'] = $blue;
break;

case 'tunablew':
$tunable = str_pad( $value_pct, 9, '0', STR_PAD_LEFT );
$bright = substr( $tunable, -7, 3);
$temp = substr( $tunable, -4, 4);
// Normalize Lumitech 2700...6500 to Shelly 3000...6500
$temp = round( 3000 + ( $temp-2700 ) * (6500-3000) / (6500-2700) );
$data['mode'] = "white";
$data['temp'] = $temp;
$data['brightness'] = intval($bright);
break;
default:
error_log('Transformer shelly_rgb&w: Wrong parameters (white or rgb missing)');
}
Expand Down

0 comments on commit edf573c

Please sign in to comment.