Need Help Validating Idea

I'm attempting to develop my first app and device driver (bc I think that's the right approach) and I'd like your validation that I'm on the right track.

Goal: (1) Have the Living Room lights dim to 5% (if already on) WHEN a specified Roku TV device logs an event called "media-state" with a value of "play". (2) Have the Living Room lights dim to 50% (if already on) WHEN a specified Roku TV device logs an event called "media-state" with a value of NOT "play".

Device: I've modified an existing device driver from here which will already create a Roku TV device type. The modification I made to this device works successfully, meaning when the Roku is playing, an event called "media-state" is logged with a value of "play". Additional values are logged too, but play is the one of interest.

Rule Machine: I understand how to create rules, and I intend to use RM. There is no attribute registered for the Roku TV device based on the event. So, I expect to use a virtual switch.

App (proposed - looking for validation): Create an app where the user selects the TV device (capability.tv) and the Virtual Switch (not sure what capability, capability.switch?). Then, subscribe to events from TV, and when media-state = play, set switch on(). Conversely, when media-state != play, set switch off().

Am I on the right track? I'm at the point where I am writing an app, using some example app (from here), but I'm stuck with a couple of basic items:

  1. How to subscribe to events from input name = rokuTv with a name of media-state?
  2. How to call on()/off() from the input name = rokuVirtSw?

maybe look at this as it pretty much does what you are trying to do.

1 Like

Changing attribute values is how events are generated, so I'm not sure what you mean here. Perhaps you missed the functionality in Rule Machine to trigger on a custom attribute? If something else isn't working, there may be a problem with the driver.

You could certainly use a custom app instead of RM, but if you were already planning on using RM, I don't see why you'd need to.

1 Like

I have thoroughly explored custom attributes in RM for my Roku TV device. I verified in another forum post that custom attributes != device events. If I can achieve it with RM alone, awesome! But I have not been able to determine how.

Can you link to that discussion? This is not true--and if it were, a custom app would not work either (if there's no event, there's nothing it could subscribe to). Attribute values are the mechanism by which events are created in Hubitat. This can be easily tested. Here is a minimal driver I just wrote that has only one custom attribute that can be set via one custom command:

metadata {
	definition (name: "Test Driver with Custom Attribute", namespace: "Test", author: "Test") {
		capability "Actuator"
        attribute "myCustomAttribute", "STRING"
        command "setCustomAttribute", ["STRING"]
	}   
}

void setCustomAttribute(value) {
    sendEvent(name: "myCustomAttribute", value: "$value")
}

def installed() {
}

def updated() {
}

You can verify on the device "Event" history that an event is generated each time the attribute is set to a (new) value via the custom command, as you might do from the device page for testing:

Screenshot: "Test Device with Custom Attribute" device page

Use it to trigger a rule, and you'll see that it works as expected:

Screenshot: Rule triggering with custom attribute

...as you can verify with the fact that this "Log" action runs when triggered, which I did here by setting the attribute value to value2:

Screenshot: Logs for rule showing "Log" action running when expected

So ... if this doesn't work for you, there's a problem somewhere. :slight_smile: I'd be happy to take a look at the driver or rule if you think it could be one of those.

3 Likes

I'll find the article after posting this reply...

What you posted makes sense, but I don't have the option in the list of attributes within RM like you do.

Device: (pay attention to "media-state" on the right side)

Events: (see again, "media-state")

List of custom attributes to choose from in Rule Machine: (hint - there is no "media-state")

GOT IT!

What I was missing was the attribute definition in the device driver. Now it appears in my list of custom attributes in RM.

Btw, here's the post I was referring to: RM and responding to custom device attributes as a trigger (but I see now where the flaw is)

That post is from March 2019, when Rule 3.0 was the newest version of that app. I'm pretty sure that "Triggered Rule" in 3.0 did indeed support custom attributes, but version 4.0, released a few months after that, introduced a bunch of major changes (including no more separate "types" of rules). But it's true regardless that it can't trigger off an attribute the device doesn't claim to report--so, I'm glad you got it figured out in the driver! :smiley:

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.