How do you have a device send to another device?


#1

Hey all,

I am working on @bptworld’s Magic Cube driver/app and @ogiewon’s Logitech Harmony device driver. What I am stuck on is how to send a device command from one developer app/driver to another. Is there a way to do this?

Example:
Magic Cube rotates left then a Volume Up is sent to the Logitech Harmony Parent driver.


#2

You have to use an App, that waits on Events from one device (Magic Cube), and then calls Commands in another device (Harmony Hub).

The simplest way to achieve this is via Rule Machine, unless you want to write your own App.


#3

You could send a location event that the other app is subscribed to, like:

sendLocationEvent(name: "testevent", value: "on")

and

subscribe(location, "testevent", handler)

#4

That is what I assumed he was doing, I might be wrong though....


#5

@ogiewon, @dan.t

I am probably going to modify @bptworld MagicCube app as he is already subscribing to events from the driver.

So how would you send to the Logitech Parent Driver if an event is found?


#6

You have to add an "input" to his app to allow you to select the Harmony Hub device. Then, in his app, where the Magic Cube events are being handled, use the Harmony Hub device from the 'input' above to call the commands of the device.

This is the basis of how all Apps work. First section allows users to select devices that will be used by the App, based on their Capabilities. Next, the App subscribes to events from devices. Finally, when an event occurs, the action is usually to call a command of another device.


#7

Alright @ogiewon I spent some time this morning working on the Magic Cub to Harmony integration. I had to add a capability "Switch" to the Parent Device to have the Harmony Parent show up in a list. I have the cube responding and hitting the harmonyHandler() I created in the Magic Cube app. I am attempting to make the following call to the Harmony Parent device driver but it isn't doing anything.

.volumeup

Actual code is setVolup.volumeup

What am I missing? Or do I need to have a way for the parent driver to accept a call from a driver?


#8

You shouldn't need to add a capability. You could use one of the existing capabilities (including actuator and switch level) to find and select the harmony parent.

The command should be
deviceInputName.volumeUp()

Of course you would need to change the deviceInputName with the name you gave the input. A code snippet would make helping a lot easier. Specifically the preference section where you declared the input for the harmony parent...and the complete method where you are executing the volume up command.


#9

In addition to @stephack's great advice, it should be noted that Groovy is CaSe SeNsItIvE. Thus, "device.volumeup()" is not the same as "device.volumeUp()". @stephack's code is correct, I just wanted to point out the fact that the language is case sensitive in case this was the root cause of your issue.


#10

As Daniel says you shouldn’t do this, use another existing capability to select the device.

The reason is that you are advertising that the device supports switch capabilities which it would seem it doesn’t. Thus other apps will then allow selection of it as a switch, for example Rule Machine, and may send commands to the device which will throw errors. Declaring that you have switch capabilies requires you to implement some basic on off commands / attributes.


#11

Geez...what am I...Invisible? :ghost:


#12

What? Who just said that??? :upside_down_face:


#13

@kevin
Great observation. Unfortunately the Parent device only has the capability of Initialize and Refresh. So something has to be added for an app to be able to select it. Recommendations on a different capability? I am game to use that instead. :slight_smile:

@ogiewon, @stephack, @kevin
Turned out to be as suspected a capitalization issue. smh I really need to code in VS like I normally do verses in the HE editor. The HE editor is nice for quick and dirty but when trying to keep everything in sync with capitalization you can easily miss something like I just did.


#14

I brought up the latest code from @ogiewon's github and it has the following:

metadata {
    definition (name: "Logitech Harmony Hub Parent", namespace: "ogiewon", author: "Dan Ogorchock", importUrl: "https://raw.githubusercontent.com/ogiewon/Hubitat/master/Drivers/logitech-harmony-hub-parent.src/logitech-harmony-hub-parent.groovy") {
        capability "Initialize"
        capability "Refresh"
        capability "Switch Level"
        capability "Audio Volume"
        capability "Actuator" 

Here's the parent driver I'm looking at:


#15

OK I am out of date on that then.

So how would you use capability "Audio Volume"?

input(name: "somename", type: "capability.Audio Volume", title: "some title")

Can you have a space?


#16

Take a look here

https://docs.hubitat.com/index.php?title=Driver_Capability_List#AudioVolume

It spells out the way the capabilities, definitions and attributes are defined, it is capability.audioVolume in your case


#18

@aaron,

I just got to ask. Is your whole goal to get your feet wet with groovy (apart from controlling your Harmony with the Magic Cube)? You know you would be done right now if you would use RM and some virtual push buttons, right?

Just making sure.....


#19

I am pretty good with Groovy when confined in my own little world of app/driver. When venturing outside into other's works I am hesitant. RM won't do what I want for the use case of Magic Cube. This is more of a toy that I am putting WAY too much time into. :slight_smile:

I really appreciate the guidance from ya'll.


#20

Challenge accepted!!!

Device1: Virtual Switch that disables after 500ms
MagicCube App -> turn left on face 0 -> turn on Device1
RM: Trigger: Device1 on
Actions: Custom Action on Harmony Device calling volumeUp()

What can't RM do???? :slight_smile:

BTW, I have that same little toy sitting right in front of me


#21

Yeah that isn't what I want to do. RM can't see the event so you need to use a virtual switch. Not the most eloquent but I see it is possible. :slight_smile: