WebSockets-based LIFX Controller software.
For an example use case, look at ./app.js
.
npm i @smart-home-services/lifx-controller
yarn @smart-home-services/lifx-controller
To configure the Webpack listener, you have 3 options available to modify in your ./localConfig.js
:
module.exports = {
// ... other config options ...
hostname: 'raspberry-pi.local',
port: 36001,
}
Go to LIFX's cloud settings page and create a new token for your app. This will go in your ./localConfig.js
as:
module.exports = {
// ... other config options ...
lifxApiToken: 'YOUR_LIFX_API_TOKEN',
}
In ./projectConfig.js
or ./localConfig.js
, add a property lifxLanClient
as an object and its options as properties on that object.
module.exports = {
lifxLanClient: {
debug: true,
messageHandlerTimeout: 2000,
resendMaxTimes: 3,
},
}
To test toggling a group, load up a browser, and go to about:blank
.
Then paste this into the devtools console:
webSocket = new WebSocket('ws://localhost:3000', 'v1')
webSocket.onmessage = console.log
webSocket.onerror = console.error
webSocket.onclose = console.info
webSocket.onopen = () => {
console.log('READY')
webSocket
.send(
JSON
.stringify({
sceneName: 'My Scene Name',
type: 'REQUEST::TOGGLE_SCENE',
})
)
}
You can have the WebSocket client reconnect when the app is reloaded by pasting this code instead:
restartWebSocket = () => {
webSocket = new WebSocket('ws://localhost:3000', 'v1')
webSocket.onmessage = console.log
webSocket.onerror = console.error
webSocket.onclose = () => setTimeout(restartWebSocket, 5000)
webSocket.onopen = () => {
console.log('READY')
webSocket
.send(
JSON
.stringify({
sceneName: 'My Scene Name',
type: 'REQUEST::TOGGLE_SCENE',
})
)
}
}
restartWebSocket()
Under Construction
Under Construction