Skip to content

Commit

Permalink
Merge pull request #9 from philip1986/master
Browse files Browse the repository at this point in the history
Update to latest master version
  • Loading branch information
Xento committed Dec 24, 2015
2 parents bc2b022 + cc13952 commit a7fa78a
Show file tree
Hide file tree
Showing 28 changed files with 1,204 additions and 2,421 deletions.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: node_js

before_install:
- export NODE_ENV=travis-test
- sudo apt-get update
# - sudo apt-get install libusb-1.0-0-dev
- sudo apt-get install libudev-dev

node_js:
- 0.10
88 changes: 63 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,36 @@ Currently supported:
- [IWY Light Master] (http://iwy-light.de/gb/iwy-starter-sets/iwy-color-single-set-9w.html)
- [WIFI370] (http://www.wifiledcontroller.com/#!wifi-370-controller/c1s9b)
- [Milight] (http://www.milight.com)
- [MilightRF24] (https://github.com/henryk/openmili)
- [Blinkstick] (https://www.blinkstick.com)
- [Hyperion] (https://github.com/tvdzwan/hyperion/wiki)

## Installation

To install the plugin on a Debian or Raspbian system libudev-dev must be installed.

sudo apt-get install libudev-dev

## Configuration

### For IwyMasten and Wifi370
### For IwyMaster

```
{
"id": "some_id",
"name": "some_name",
"class": "IwyMaster",
"addr": "xxx.xxx.xxx.xxx"
}
```

### For Wifi370

```
{
"id": "some_id",
"name": "some_name",
"class": "IwyMaster | Wifi370",
"class": "Wifi370",
"addr": "xxx.xxx.xxx.xxx"
}
```
Expand All @@ -34,36 +54,54 @@ Currently supported:

### For MilightRF24

Pluginconfig:
```
{
"plugin": "led-light",
"MilightRF24Port": "/dev/ttyUSB1"
}
```

Devices:
```
"zones": [
{
"addr": "5927",
"zone": 0,
"send": true,
"receive": true
},
{
"addr": "485D",
"zone": 0,
"send": true,
"receive": true
}
]
"id": 'some_id'
"name": 'some_name'
"class": 'MilightRF24'
"port": '/dev/ttyUSB1'
"zones": [
{
"addr": "5927",
"zone": 0,
"send": true,
"receive": true
},
{
"addr": "485D",
"zone": 0,
"send": true,
"receive": true
}
]
}
```
You will get your addr when you just add the parameter MilightRF24Port to your config and switch to the debug output in pimatic and change some settings with your remote.

You need for example an arduino nano and connect it to an nrf24 using the standard SPI wiring.
Get the sketch from here https://github.com/henryk/openmili and change the CE and CSN pin to your wiring.

### For Blinkstick

```
{
"id": "some_id",
"name": "some_name",
"class": "Blinkstick",
"serial": "xxx" // Only required if more than one Blinkstick is connected to the host.
}
```

### For Hyperion

```
{
"id": "some_id",
"name": "some_name",
"class": "Wifi370",
"addr": "xxx.xxx.xxx.xxx"
}
```

## Features

Expand All @@ -73,5 +111,5 @@ Get the sketch from here https://github.com/henryk/openmili and change the CE an
- by color picker (in UI)
- by name (in rules e.g. red)
- by hex (in rules e.g. #00FF00)
- by teampature variable from weather plugin (in rules e.g. $weather.temperature)
- by temperature variable from weather plugin (in rules e.g. $weather.temperature)

61 changes: 59 additions & 2 deletions device-config-schema.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# #led-light-plugin configuration options
module.exports = {
title: "Led light device config schemas"
LedLight: {
title: "LedLight"
IwyMaster: {
title: "IwyMaster LedLight"
type: "object"
properties:
addr:
Expand All @@ -20,12 +20,69 @@ module.exports = {
description: "Zone [0 - 4], 0 = switches all zones"
type: "number"
},
MilightRF24: {
title: "Milight"
type: "object"
properties:
zones:
description: "The switch protocols to use."
type: "array"
default: []
format: "table"
items:
type: "object"
properties:
addr:
description: "Address of light device"
type: "string"
port:
description: "USB port where the gateway is attached"
type: "string"
zone:
description: "Zone [0 - 4], 0 = switches all zones"
type: "number"
send:
description: "Send commands using this address and zone"
type: "boolean"
default: true
receive:
description: "Respond on received commands using this address and zone"
type: "boolean"
default: true
},
Wifi370: {
title: "LedLight"
type: "object"
properties:
addr:
description: "IP-Address of light device"
type: "string"
},
Blinkstick: {
title: "BlinkStick"
type: "object"
properties:
serial:
description: "serial of Blinkstick"
type: "string"
default: ""
},
DummyLedLight: {
title: "DummyLedLight"
type: "object"
properties: {}
},
HyperionLedLight: {
title: "Hyperion",
type: "object"
properties:
addr:
description: "IP-Address of hyperion device"
type: "string"
default: "localhost"
port:
description: "Port of hyperion device"
type: "string",
default: "19444"
}
}
12 changes: 9 additions & 3 deletions devices/base.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ module.exports = (env) ->
params:
brightnessValue:
type: t.number
changeDimlevelTo:
description: "Sets the level of the dimmer"
params:
dimlevel:
type: t.number

constructor: (initState) ->
unless @device
Expand All @@ -67,7 +72,7 @@ module.exports = (env) ->
@name = @config.name
@id = @config.id

@power = initState?.power or false
@power = initState?.power or 'off'
@color = initState?.color or ''
@brightness = initState?.brightness or 100
@mode = initState?.mode or false
Expand Down Expand Up @@ -118,10 +123,11 @@ module.exports = (env) ->
turnOff: -> throw new Error "Function 'turnOff' is not implemented!"
setColor: -> throw new Error "Function 'setColor' is not implemented!"
setWhite: -> throw new Error "Function 'setWhite' is not implemented!"
setBrightness: -> throw new Error "Function 'setBrightness' is not implemented!"
setBrightness: (brightnessValue) -> throw new Error "Function 'setBrightness' is not implemented!"
changeDimlevelTo: (dimLevel) -> @setBrightness(dimLevel)

toggle: ->
if @power is 'on' then @turnOn() else @turnOff()
if @power is 'off' then @turnOn() else @turnOff()
Promise.resolve()

return BaseLedLight
73 changes: 73 additions & 0 deletions devices/blinkstick.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
module.exports = (env) ->
Promise = env.require 'bluebird'
_ = require 'lodash'
Color = require 'color'
BaseLedLight = require('./base')(env)


class Blinkstick extends BaseLedLight

constructor: (@config, lastState) ->
nodeBlinkstick = require 'blinkstick'
if @config.serial
@device = new nodeBlinkstick.findBySerial(@config.serial)
else
@device = new nodeBlinkstick.findFirst()

initState = _.clone lastState
for key, value of lastState
initState[key] = value.value
super(initState)
if @power then @turnOn() else @turnOff()

_updateState: (attr) ->
state = _.assign @getState(), attr
super null, state

setMaxValue = (color, brightness) ->
return (color / 255) * (brightness * 2.5)

turnOn: ->
@_updateState power: true
if @mode
color = Color(@color).rgb()
else
color =
r: 255
g: 255
b: 255

@device.setColor(setMaxValue(color.r, @brightness), setMaxValue(color.g, @brightness), setMaxValue(color.b, @brightness))
Promise.resolve()

turnOff: ->
@_updateState power: false
@device.turnOff()
Promise.resolve()

setColor: (newColor) ->
color = Color(newColor).rgb()
@_updateState
mode: @COLOR_MODE
color: color
@device.setColor(setMaxValue(color.r, @brightness), setMaxValue(color.g, @brightness), setMaxValue(color.b, @brightness)) if @power
Promise.resolve()

setWhite: () ->
@_updateState mode: @WHITE_MODE
@device.setColor(setMaxValue(255, @brightness), setMaxValue(255, @brightness), setMaxValue(255, @brightness)) if @power
Promise.resolve()

setBrightness: (newBrightness) ->
@_updateState brightness: newBrightness
if @mode
color = Color(@color).rgb()
else
color =
r: 255
g: 255
b: 255
@device.setColor(setMaxValue(color.r, newBrightness), setMaxValue(color.g, newBrightness), setMaxValue(color.b, newBrightness)) if @power
Promise.resolve()

return Blinkstick
49 changes: 49 additions & 0 deletions devices/dummy.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module.exports = (env) ->
Promise = env.require 'bluebird'
_ = require 'lodash'
Color = require 'color'
BaseLedLight = require('./base')(env)

class DummyLedLight extends BaseLedLight

constructor: (@config, lastState) ->
@device = @
@name = config.name
@id = config.id
@_dimlevel = lastState?.dimlevel?.value or 0

initState = _.clone lastState
for key, value of lastState
initState[key] = value.value
super(initState)
if @power then @turnOn() else @turnOff()

_updateState: (attr) ->
state = _.assign @getState(), attr
super null, state

turnOn: ->
@_updateState power: true
Promise.resolve()

turnOff: ->
@_updateState power: false
Promise.resolve()

setColor: (newColor) ->
color = Color(newColor).rgb()
@_updateState
mode: @COLOR_MODE
color: color
Promise.resolve()

setWhite: ->
@_updateState mode: @WHITE_MODE
Promise.resolve()

setBrightness: (newBrightness) ->
@_updateState brightness: newBrightness
Promise.resolve()

return DummyLedLight

Loading

0 comments on commit a7fa78a

Please sign in to comment.