Skip to content

Commit

Permalink
Merge pull request #203 from datech/release/v0.1.12
Browse files Browse the repository at this point in the history
release/v0.1.12
  • Loading branch information
datech authored Jan 23, 2025
2 parents a730d63 + a8b3ba9 commit bcbbf00
Show file tree
Hide file tree
Showing 12 changed files with 3,119 additions and 730 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/node_modules
*/README*.md
data/
dist/
node_modules/
*/README*.md
60 changes: 35 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,65 @@
# node-red-contrib-amazon-echo

Alexa controlled Node-Red nodes supporting latest Amazon Echo devices
Alexa controlled Node-Red nodes supporting the latest Amazon Echo devices

**NO Alexa Skills required.**

**NO cloud dependencies.**

## Installation

Install from your Node-RED Manage Palette

or

Install using npm

$ npm install node-red-contrib-amazon-echo
```sh
$ npm install node-red-contrib-amazon-echo
```

## How to use
* Add **Amazon Echo Hub** node your flow
* Add multiple **Amazon Echo Device** nodes linked to **Amazon Echo Hub node**
Note: Use unique names for device nodes. Alexa will use the node name to manage your smart device
* Ask **"Alexa, discover devices"** or start the discover procedure from the Alexa mobile app

![Usage screenshot](https://raw.githubusercontent.com/datech/node-red-contrib-amazon-echo/master/docs/images/how-to-use.png "Screenshot")
- Add **Amazon Echo Hub** node to your flow.
- Add multiple **Amazon Echo Device** nodes linked to the **Amazon Echo Hub node**.
- **Note:** Use unique names for device nodes. Alexa will use the node name to manage your smart device.
- Ask **"Alexa, discover devices"** or start the discovery procedure from the Alexa mobile app.

## Features
* Turning on/off
* Dimming
* Setting the light color

- Turning on/off
- Dimming
- Setting the light color

## Supported devices
* Amazon Echo 2nd generation
* Amazon Echo Plus 2nd generation
* Amazon Echo Dot 1st, 2nd and 3rd generations

- All Echo devices

## Example Alexa commands
* Alexa, turn on/off {device}
* Alexa, switch on/off {device}
* Alexa, set {device} to 50%
* Alexa, turn my {device} light green
* Alexa, set the {device} light to orange
* Alexa, make the {device} warmer
* Alexa, brighten {device} to 60 percent
* Alexa, dim the {device} lights

- "Alexa, turn on/off {device}"
- "Alexa, switch on/off {device}"
- "Alexa, set {device} to 50%"
- "Alexa, turn my {device} light green"
- "Alexa, set the {device} light to orange"
- "Alexa, make the {device} warmer"
- "Alexa, brighten {device} to 60 percent"
- "Alexa, dim the {device} lights"

## Requirements
Amazon Echo Hub node is starting a service listening on port 80 which requires Node-Red process to be started with root user.

**No additional settings are needed if Node-Red is started as Home Assistant add-on**
The Amazon Echo Hub node starts a service listening on port 80, which requires the Node-RED process to be started with root privileges or requires firewall rules to redirect the traffic.

## Troubleshooting
Detailed troubleshooting instructions can be found on the [Wiki](https://github.com/datech/node-red-contrib-amazon-echo/wiki)

Detailed troubleshooting instructions can be found on the [Wiki](https://github.com/datech/node-red-contrib-amazon-echo/wiki).

## Bugs and feature requests
Please create an issue in [GitHub](https://github.com/datech/node-red-contrib-amazon-echo/issues)

Please create an issue on [GitHub](https://github.com/datech/node-red-contrib-amazon-echo/issues).

## More device types

**node-red-contrib-amazon-echo** supports only basic device types like lights, switches, and dimmable bulbs. If you need a broader range of smart home devices, including thermostats, TVs, speakers, locks, blinds, garage doors, fans, and scenes, you might try **[DuloNode](https://www.dulonode.com)**.

**DuloNode** extends functionality beyond what node-red-contrib-amazon-echo offers by supporting more device categories and additional features like temperature control, TV channel changes, adjusting speaker volume, locking doors, raising blinds, and more advanced automation. It provides a comprehensive smart home integration experience for users looking for extended capabilities.
56 changes: 56 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
version: '3'

services:
nodered:
image: "nodered/node-red:latest"
profiles: [node-red]
environment: {
# DEBUG: "node-ssdp:*"
}
ports:
- "1880:1880"
volumes:
- type: bind
source: data
target: /data
- type: bind
source: .
target: /node-red-contrib-amazon-echo
restart: unless-stopped
depends_on:
nodered-init:
condition: service_completed_successfully

nodered-init:
image: "nodered/node-red:latest"
profiles: [node-red]
volumes:
- type: bind
source: data
target: /data
- type: bind
source: .
target: /node-red-contrib-amazon-echo
entrypoint:
- "/bin/sh"
- "-c"
- |
cd /node-red-contrib-amazon-echo &&
mkdir -p dist &&
npm pack --pack-destination dist
npm install ./dist/node-red-contrib-amazon-echo-*.tgz --prefix /data
restart: "no"

test:
image: "nodered/node-red:latest"
profiles: [test]
volumes:
- type: bind
source: .
target: /node-red-contrib-amazon-echo
working_dir: /node-red-contrib-amazon-echo
entrypoint:
- "/bin/sh"
- "-c"
- |
npm install && npm test
6 changes: 3 additions & 3 deletions nodes/amazon-echo-device.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
module.exports = function(RED) {
'use strict';

require('./lib/helpers.js')();
const helpers = require('./lib/helpers.js')();

function AmazonEchoDeviceNode(config) {
RED.nodes.createNode(this, config);
var deviceNode = this;

deviceNode.on('input', function(msg) {

var nodeDeviceId = formatUUID(config.id);
var nodeDeviceId = helpers.formatUUID(config.id);

if (nodeDeviceId == msg.deviceid) {
msg.topic = config.topic;
msg.topic = config.topic || msg.topic;
deviceNode.send(msg);
}

Expand Down
25 changes: 14 additions & 11 deletions nodes/amazon-echo-hub.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = function(RED) {
'use strict';

require('./lib/helpers.js')();
const helpers = require('./lib/helpers.js')();

const HueColor = require('hue-colors').default;

Expand Down Expand Up @@ -84,7 +84,7 @@ module.exports = function(RED) {

if (config.processinput > 0 && nodeDeviceId !== null) {

var deviceid = formatUUID(nodeDeviceId);
var deviceid = helpers.formatUUID(nodeDeviceId);

var meta = {
insert: {
Expand All @@ -99,7 +99,7 @@ module.exports = function(RED) {
// 'Process and output' OR
// 'Process and output on state change' option is selected
if (config.processinput == 2 || (config.processinput == 3 && Object.keys(deviceAttributes.meta.changes).length > 0)) {
payloadHandler(hubNode, deviceid);
payloadHandler(hubNode, deviceid, msg.topic);
}

}
Expand Down Expand Up @@ -158,7 +158,7 @@ module.exports = function(RED) {
var data = {
address: req.hostname,
port: req.connection.localPort,
huehubid: getHueHubId(config)
huehubid: helpers.getHueHubId(config)
};

var output = Mustache.render(template, data);
Expand Down Expand Up @@ -190,7 +190,7 @@ module.exports = function(RED) {
username: req.params.username,
date: new Date().toISOString().split('.').shift(),
uniqueid: function() {
return hueUniqueId(this.id);
return helpers.hueUniqueId(this.id);
}
}

Expand All @@ -210,7 +210,7 @@ module.exports = function(RED) {
lights: getDevicesAttributes(hubNode.context()),
date: new Date().toISOString().split('.').shift(),
uniqueid: function() {
return hueUniqueId(this.id);
return helpers.hueUniqueId(this.id);
}
}

Expand Down Expand Up @@ -282,7 +282,7 @@ module.exports = function(RED) {
port: port,
path: '/description.xml'
},
udn: 'uuid:' + getHueHubId(config)
udn: 'uuid:' + helpers.getHueHubId(config)
})

server.addUSN('upnp:rootdevice');
Expand All @@ -292,7 +292,7 @@ module.exports = function(RED) {
}

//
// Helpers
// helperss
//
function getOrDefault(key, defaultValue, context) {

Expand Down Expand Up @@ -323,7 +323,7 @@ module.exports = function(RED) {
RED.nodes.eachNode(function(node) {
if (node.type == 'amazon-echo-device') {
devices.push({
id: formatUUID(node.id),
id: helpers.formatUUID(node.id),
name: node.name
});
}
Expand Down Expand Up @@ -441,11 +441,14 @@ module.exports = function(RED) {
//
// Handlers
//
function payloadHandler(hubNode, deviceId) {
function payloadHandler(hubNode, deviceId, topic = null) {

var msg = getDeviceAttributes(deviceId, hubNode.context());
msg.deviceid = deviceId;
msg.topic = '';

if (topic !== null) {
msg.topic = topic;
}

hubNode.send(msg);
}
Expand Down
34 changes: 28 additions & 6 deletions nodes/lib/helpers.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
module.exports = function(){

this.formatUUID = function(id) {
module.exports = function() {
const os = require('os');

function formatUUID(id) {
if (id === null || id === undefined)
return '';
return ('' + id).replace('.', '').trim();
}

this.hueUniqueId = function(id) {
function hueUniqueId(id) {
return (id + '0000').replace(/(.{2})/g, "$1:").substring(0, 23) + '-00';
}

this.getHueHubId = function(config) {

function getHueHubId(config) {
var uuid = '00112233-4455-6677-8899-';
uuid += formatUUID(config.id);
return uuid;
}

function getNetworkInterfaces() {
const networkInterfaces = os.networkInterfaces();
let interfaces = {
"all": "0.0.0.0"
};

// Find IPv4 addresses
Object.keys(networkInterfaces).filter(name => name !== 'lo').forEach(interfaceName => {
const details = networkInterfaces[interfaceName].find(detail => detail.family === 'IPv4' && !detail.internal);
if (details) {
interfaces[interfaceName] = details.address;
}
});

return interfaces;
}

return {
formatUUID,
hueUniqueId,
getHueHubId,
getNetworkInterfaces
};
};
Loading

0 comments on commit bcbbf00

Please sign in to comment.