Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for device commands, adds (H device command) node #7

Merged
merged 1 commit into from
May 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ You can install the extension simply in Node-RED in your browser, by default und

## Usage / Available nodes

Three nodes are available in Node-RED: **H command**, **H activity** and **H observe**, located in the group **harmony**.
Four nodes are available in Node-RED: **H command**, **H activity**, **H device command** and **H observe**, located in the group **harmony**.

### H command

Expand All @@ -55,22 +55,36 @@ The command configured in the node will be triggered by any input injected into

A node to activate an **Activity** on a Harmony Hub through Node-RED

A Harmony **Hub** needs to be selected from the list or created by clicking on the edit button. The Harmony Hub
A Harmony **Hub** needs to be selected from the list or created by clicking on the edit button. The Harmony Hub
**IP** address can be autodetected by clicking on the search button in the configuration node.

An **Activity** that is set up on the Harmony Hub needs to be provided, it's identified by its *ID*. Clicking on the
search button loads the available activities from the provided **Hub**, which can then be selected from a dropdown list. Switching
An **Activity** that is set up on the Harmony Hub needs to be provided, it's identified by its *ID*. Clicking on the
search button loads the available activities from the provided **Hub**, which can then be selected from a dropdown list. Switching
back to the input field will show the *ID* in the field. The **Label** field below will show the **Activity** label.

To switch off, select *PowerOff* from the **Activity** dropdown list, or enter *"-1"* into the field.

The command configured in the node will be triggered by any input injected into the node, the output slot will return *msg.payload = true* if the command was sent successfully.

### H device command

A node to send a **Device Command** to a Harmony Hub through Node-RED.

A Harmony **Hub** needs to be selected from the list or created by clicking on the edit button. The Harmony Hub **IP** address can be autodetected by clicking on the search button in the configuration node.

A **Device** that is set up on the Harmony Hub needs to be provided, it's identified by its *ID*. Clicking on the search button loads the available devices from the provided **Hub**, which can then be selected from a dropdown list. Switching back to the imput field will show the *ID* in the field. The **Label** field below will show the **Device** label.

A **Command** from the selected **Device** needs to be provided, it's a stanza *query*. Clicking on the search button loads the available commands from the provided **Device**, that can then be selected from a list. Switching back to the input field will show the *query* string in the field.

The **Repeat** field allows for the command to be repeated. The default is *1*, meaning the command is send once. For example entering *10* will send the command exactly 10 times. This can be helpful when using commands for volume or channels.

The command configured in the node will be triggered by any input injected into the node, the output slot will return *msg.payload = true* if the command was sent successfully

### H observe

A node to observe an **Activity** being triggered on a Harmony Hub through Node-RED

A Harmony **Hub** needs to be selected from the list or created by clicking on the edit button. The Harmony Hub
A Harmony **Hub** needs to be selected from the list or created by clicking on the edit button. The Harmony Hub
**IP** address can be autodetected by clicking on the search button in the configuration node.

When an **Activity** is switched on the Harmony Hub, the node sends an object with a payload to the output:
Expand Down
65 changes: 65 additions & 0 deletions harmony/harmony-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,69 @@ module.exports = function (RED) {
})
}
})

RED.httpAdmin.get('/harmony/devices', function (req, res, next) {
if (!req.query.ip) {
res.status(400).send('Missing argument IP')
} else {
harmonyClient(req.query.ip)
.then(function (harmony) {
harmony.getAvailableCommands()
.then(function (commands) {
var devices = commands.device
.filter(function (device) {
return device.controlGroup.length > 0
})
.map(function (device) {
return {id: device.id, label: device.label}
})
harmony.end()
res.status(200).send(JSON.stringify(devices))
}).fail(function (err) {
harmony.end()
res.status(500).send('Request failed.')
if (err) throw err
})
}).fail(function (err) {
res.status(500).send('Request failed.')
if (err) throw err
})
}
})

RED.httpAdmin.get('/harmony/device-commands', function (req, res, next) {
if (!req.query.ip || !req.query.deviceId) {
res.status(400).send('Missing argument.')
} else {
harmonyClient(req.query.ip)
.then(function (harmony) {
harmony.getAvailableCommands()
.then(function (commands) {
var device = commands.device.filter(function(device) {
return device.id === req.query.deviceId
}).pop()
var deviceCommands = device.controlGroup
.map(function (group) {
return group.function
})
.reduce(function (prev, curr) {
return prev.concat(curr)
})
.map(function (fn) {
return {action: fn.action, label: fn.label}
})
harmony.end()
res.status(200).send(JSON.stringify(deviceCommands))
}).fail(function (err) {
harmony.end()
res.status(500).send('Request failed.')
if (err) throw err
})

}).fail(function (err) {
res.status(500).send('Request failed.')
if (err) throw err
})
}
})
}
Loading