I wrote a custom app that plays a track/TTS on smart speakers periodically throughout the day (the period is NOT the same from day to day; that would have been easy ). I want to be able to give my users the option to trigger RM rules whenever this happens (e.g. they may want to turn up/down the volume, turn on/off lights, etc.). How can I do this? Although this is my specific use case, I am happy to listen to generalized solutions as well.
Prior research:
I thought that the way to do this would be to publish to Hubitat's event stream via sendEvent from my custom app and then have RM trigger from it. However, I could not find a trigger that let me pick this. Looking at other threads like "Enable app events" for Motion Lighting? and sendEvent from an app? makes it sound like sendEvent from custom apps is merely for diagnostic purposes. Am I misunderstanding? I am thinking that the only/supported way to do this is to create a virtual device that the custom app performs state changes on, but I was hoping to have a solution that is self-contained in the app. Any help would be appreciated.
You can have RM rules triggered by HTTP requests. Since it sounds like you are writing the custom app and already have the functionality to do other things at the desired time, you could use this: Rule Machine - Hubitat Documentation
You could also switch to musicplayer instead of speechsynthesis. It has setlevel in addition to playtext (equivalent to speak). There are other commands on that one that you probably don't need, but you could just stub them out.
Thank you @bravenel. I had to edit the first example in that thread because it gave an enum variable which doesn't match the sendAction signature:
groovy.lang.MissingMethodException: No signature of method: static hubitat.helper.RMUtils.sendAction() is applicable for argument types: (java.lang.String, java.lang.String, java.lang.String) values: [1633, runRuleAct, Adhan Player]
Possible solutions: sendAction(java.util.List, java.lang.String, java.lang.String) on line 89 (advancedSettingsPage)
Modifying the example to something like this worked for me:
def rules = RMUtils.getRuleList()
// can also use "multiple: true" to convert to a List
input "theseRules", "enum", title: "Select which rules to stop", options: rules
RMUtils.sendAction([theseRules], "stopRuleAct", app.label)