This repository has been archived by the owner on Dec 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 33f85c0
Showing
5 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# homebridge-fake-rgb | ||
|
||
An homebridge plugin that create an Fake RGB Bulb HomeKit accessory | ||
|
||
# Installation | ||
|
||
Follow the instruction in [homebridge](https://www.npmjs.com/package/homebridge) for the homebridge server installation. The plugin is published through [NPM](https://www.npmjs.com/package/homebridge-fake-rgb) and should be installed "globally" by typing: | ||
|
||
```bash | ||
npm install -g homebridge-fake-rgb | ||
``` | ||
|
||
# Configuration | ||
|
||
Remember to configure the plugin in config.json in your home directory inside the .homebridge directory. | ||
|
||
```json | ||
"accessories": [{ | ||
"accessory": "Fake-RGB", | ||
"name": "RGB Bulb" | ||
}] | ||
``` | ||
|
||
Configuration parameters: | ||
|
||
- "accessory": "Fake-RGB", | ||
- "name": "PUT THE NAME OF YOUR TEST BULB HERE", | ||
|
||
Look for a sample config in [config.json example](https://github.com/edjopato/homebridge-fake-rgb/blob/master/config-sample.json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"bridge": { | ||
"name": "Homebridge", | ||
"username": "CC:22:3D:E3:CE:30", | ||
"port": 51826, | ||
"pin": "031-45-154" | ||
}, | ||
|
||
"description": "Bla Bla Bla", | ||
|
||
"accessories": [{ | ||
"accessory": "Fake-RGB", | ||
"name": "RGB Bulb" | ||
}], | ||
|
||
"platforms": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
var Service, Characteristic; | ||
|
||
module.exports = function( homebridge ) { | ||
Service = homebridge.hap.Service; | ||
Characteristic = homebridge.hap.Characteristic; | ||
homebridge.registerAccessory( "homebridge-fake-rgb", "Fake-RGB", RgbAccessory ); | ||
}; | ||
|
||
function RgbAccessory( log, config ) { | ||
this.log = log; | ||
this.config = config; | ||
this.name = config.name; | ||
this.power = 0; | ||
this.brightness = 100; | ||
this.saturation = 0; | ||
this.hue = 0; | ||
|
||
this.log( "Initialized '" + this.name + "'" ); | ||
} | ||
|
||
function rgbFromHsv( h, s, v ) { | ||
var h_ = h / 60; | ||
var c = v * s; | ||
var x = c * ( 1 - Math.abs( ( h_ % 2 ) - 1 ) ); | ||
|
||
var r = v - c; | ||
var g = v - c; | ||
var b = v - c; | ||
|
||
if ( h_ >= 5 ) { | ||
r += c; | ||
b += x; | ||
} else if ( h_ >= 4 ) { | ||
r += x; | ||
b += c; | ||
} else if ( h_ >= 3 ) { | ||
g += x; | ||
b += c; | ||
} else if ( h_ >= 2 ) { | ||
g += c; | ||
b += x; | ||
} else if ( h_ >= 1 ) { | ||
r += x; | ||
g += c; | ||
} else { | ||
r += c; | ||
g += x; | ||
} | ||
|
||
return { | ||
r: r, | ||
g: g, | ||
b: b | ||
}; | ||
} | ||
|
||
RgbAccessory.prototype.setColor = function() { | ||
var color = rgbFromHsv( this.hue, this.saturation / 100, this.brightness / 100 ); | ||
|
||
if ( !this.power ) { | ||
color.r = 0; | ||
color.g = 0; | ||
color.b = 0; | ||
} | ||
|
||
this.log( "set color to", Math.round( color.r * 255 ), Math.round( color.g * 255 ), Math.round( color.b * 255 ) ); | ||
}; | ||
|
||
RgbAccessory.prototype.getServices = function() { | ||
var lightbulbService = new Service.Lightbulb( this.name ); | ||
var bulb = this; | ||
|
||
lightbulbService | ||
.getCharacteristic( Characteristic.On ) | ||
.on( 'get', function( callback ) { | ||
callback( null, bulb.power ); | ||
} ) | ||
.on( 'set', function( value, callback ) { | ||
bulb.power = value; | ||
bulb.log( "power to " + value ); | ||
bulb.setColor(); | ||
callback(); | ||
} ); | ||
|
||
lightbulbService | ||
.addCharacteristic( Characteristic.Brightness ) | ||
.on( 'get', function( callback ) { | ||
callback( null, bulb.brightness ); | ||
} ) | ||
.on( 'set', function( value, callback ) { | ||
bulb.brightness = value; | ||
bulb.log( "brightness to " + value ); | ||
bulb.setColor(); | ||
callback(); | ||
} ); | ||
|
||
lightbulbService | ||
.addCharacteristic( Characteristic.Hue ) | ||
.on( 'get', function( callback ) { | ||
callback( null, bulb.hue ); | ||
} ) | ||
.on( 'set', function( value, callback ) { | ||
bulb.hue = value; | ||
bulb.log( "hue to " + value ); | ||
bulb.setColor(); | ||
callback(); | ||
} ); | ||
|
||
lightbulbService | ||
.addCharacteristic( Characteristic.Saturation ) | ||
.on( 'get', function( callback ) { | ||
callback( null, bulb.saturation ); | ||
} ) | ||
.on( 'set', function( value, callback ) { | ||
bulb.saturation = value; | ||
bulb.log( "saturation to " + value ); | ||
bulb.setColor(); | ||
callback(); | ||
} ); | ||
|
||
return [ lightbulbService ]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "homebridge-fake-rgb", | ||
"version": "0.0.1", | ||
"description": "Fake RGB Bulb plugin for homebridge: https://github.com/nfarina/homebridge", | ||
"license": "MIT", | ||
"keywords": [ | ||
"homebridge-plugin" | ||
], | ||
"engines": { | ||
"node": ">=0.12.0", | ||
"homebridge": ">=0.2.0" | ||
}, | ||
"author": { | ||
"name": "Edgar Toll" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/edjopato/homebridge-fake-rgb.git" | ||
}, | ||
"dependencies": {} | ||
} |