Rule machine and multiple actions


#1

I've been reading through the forum on and off for a month or so and it seems that either; no one is doing this, everyone knows how to do it or I can't search.

I cant figure out how to dim a light by 10% over 5 seconds then increase a light by 10% over 5 seconds then wait 10 seconds and turn the light off. I can do all these things individually but not in a way that is quick, clean and useful for my task.

I'm sure my problem is that I'm looking at this as though it were SmartThings where you would just tell webcore to do this but I got this hub to move away from SmartThings.

Thanks in advance


#2

For a task like that I'd write my own app and it's not that difficult. If you can use webcore then groovy shouldn't be a problem. Of course this assumes that your dimmer or bulb can be set at the dimming rate that you require.


#3

You could create multiple RM Actions, and then chain them together to achieve this behavior. @bravenel is the RM Author/Master/Guru. He might have something add with respect to exactly how one can achieve this using RM.


#4

Thanks for the replies. So I'm not just missing something? I can't do two of the same action or reorder how actions fire all from within one rule? Are there alternatives to RM that run locally? I've found some that looked promising but they seem to run remotely. I see people saying they have converted all there webcore pistons over but the only way this seems possible is to have a ton of rules that are simply one action each and then string them together in a cluttered mess. Is this correct? I'm really just trying to make rules where I can have an event trigger five or six actions in the order I want with the time delay between them that I want. Thanks again.


#5

Correct. I still say this is the biggest missing element in HE that will prevent it from converting many ST or other system users to this platform. RM just doesn't cut it for logic that needs sequencing. It can technically do it, but it is a big freaking mess (in my OPINION).

Don't get me wrong, I like RM and respect what Bruce has done with it - and I use it for many things. But it can't get the job done efficiently for many complex use cases.

For those types of needs, I just write purpose built user apps to do it instead...

If you could write a webcore piston, it is only slightly harder to write a groovy app once you get the syntax down.


#6

Thank you, that is what I feared. I know this is my problem, but I'm probably not alone in feeling that even though I can write an app, I don't want to. The piston approach seems more polished and less like it's my night job that I have to do after I get done with my day job. But again, that's me, I look at home automation as a hobby, not as something I have to maintain. Oh well, I guess it is back up into the cloud.


#7

There are non-cloud options for this.... just may not be the one you're using.


#8

I understand your thoughts on this. I will say, though, that I can write a purpose built app in almost the exact same time it took to write a WebCore piston.

The logic part is basically the exact same amount of work, the getting params in/out is slightly more work - but not much,


#9

@JasonJoel Would you be willing to share a few basic example/template apps? Just a few examples that show the bare minimum of what is needed for the app itself, and then some very simple tasks (turn on a light or two if motion detected). I found a thread where you were looking for examples yourself back in December, and the one posted seemed to help you. I really want to wrap my head around groovy, but I learn best from building on examples. I've tried to browse through some of the apps I've installed, but most are complex, and it's taking a while just to digest what's going on. I'd love to have some very basic examples or templates to start from so I can get my feet wet. And, of course, please just direct me to the correct place if something like this already exists. I know we have a spot for example drivers and apps (https://github.com/hubitat/HubitatPublic), but I still don't see any example apps there.


#10

I'll will tonight if someone doesn't beat me to it.

It is pretty simple if you aren't trying to make it a 'generic'/configurable app.


#11

The example would be very much appreciated, as would a pointer to a good learning website for groovy.
Thanks in advance!


#12

The best resource to get started, in my opinion, is the SmartThings developer documentation. The documentation is pretty good, and walks you through a sample app creation,

While there are a few differences here and there between ST and HE implementation of groovy, they are the same in structure and basic language. Most standard ST apps will convert to HE with just a few simple changes, in fact.


#13

I will go lok ate that, thanks.


#14

I think I started here. But there are some topics before this one (on the tree on the left of the screen) if you really want to start from square 1.

https://docs.smartthings.com/en/latest/getting-started/first-smartapp.html


#15

Here you go. I tried to put enough comments in that it would make sense. This is a completely useless app, but might be a good simple starter go-by.

definition(
	name: "Simple App Example",
	namespace: "Botched1",
	author: "Jason Bottjen",
	description: "Example App",
	iconUrl: "",
	iconX2Url: "",
	iconX3Url: "")

preferences 
{
	page(name: "pageConfig")
}

def pageConfig() 
{
	dynamicPage(name: "", title: "", install: true, uninstall: true, refreshInterval:0) 
	{
		section("Some Inputs") 
		{
			// Great reference for capabilities: https://docs.smartthings.com/en/latest/capabilities-reference.html
			input "tStat", "capability.thermostat", title: "Thermostat", description: "Thermostat", required: true, multiple: false
			input "temp1", "capability.temperatureMeasurement", title: "Temperature", description: "Temperature", required: true, multiple: false
			input "temp2", "capability.temperatureMeasurement", title: "Temperature", description: "Temperature", required: true, multiple: false
			
		}
		
		section("Some Variables") 
		{
			input(name: "minOpen", type: "number", defaultValue: "10", range: "0..100", title: "Minimum Vent Open %", description: "Min Open %", required: false)
			input(name: "moveSize", type: "number", defaultValue: "15", range: "0..100", title: "Vent Move Size %", description: "Move Size %", required: false)
			input(name: "deadBand", type: "number", defaultValue: "2", range: "0..100", title: "Vent Position Deadband %", description: "Dead Band %", required: false)
		}
		
		section("Some Outputs") 
		{
			input "dimmer1", "capability.switchLevel", title: "Dimmer 1", description: "", required: true, multiple: false
			input "dimmer2", "capability.switchLevel", title: "Dimmer 2", description: "", required: true, multiple: false
			
		}
		
		section("Debug")
		{
			input "debugMode", "bool", title: "Enable debug logging", required: true, defaultValue: false
		}
	}
}

def installed() 
{
	log.debug "installed"
    // This is run when the app is installed
	initialize()
}

def updated() 
{
	log.debug "updated"
    // This is run any time you click DONE on the app setup screen
	initialize()
}

def initialize() 
{
	unschedule()
	log.debug "initialize"

	// If you want the app to run periodically on a schedule, then schedule it like this.
	// Typically you would do this *OR* the subscriptions below, but not both. But you can do both if you have
	// a reason to...
	//
	// This will run the code in section "checkDevices" every 1 minute.
	runEvery1Minute(checkDevices)
	
	// If you would rather not run it on a set schedule, and rather when a device's variable changes, you would comment out the runEvery above
	// and setup subscriptions to the events you want to trigger action off of
	//
	// This will subscribe to dimmer1's ON/OFF status, dimmer level value, and the mode of your Hubitat hub.
	// When any of those three valuies change, the code in "dimmer1ONOFFHandler", "dimmer1LEVELHandler", or "modeHandler" would run.
	subscribe(dimmer1, "switch", dimmer1ONOFFHandler) 
	subscribe(dimmer1, "level", dimmer1LEVELHandler) 
	subscribe(location, "mode", modeHandler)
}

def uninstalled() 
{
	log.debug "uninstalled"
    // This is run when the app is uninstalled
}

def checkDevices() 
{
	// If scheduled in "initialize()" this chunk of code will run however often you scheduled it. Otherwise it will never run or do anything.
	log.info("${app.label} - Ran")
	
	// Fetch the current values of some of these devices, and stick them in a variable
	def currentTSMode = tStat.currentValue("thermostatOperatingState")
	def currentTemp1 = temp1.currentValue("temperature")
	def currentTemp2 = temp2.currentValue("temperature")
	def currentDimmer1Level = dimmer1.currentValue("level")
	def currentDimmer2Level = dimmer2.currentValue("level")
	def currentDimmer1ONOFF = dimmer1.currentValue("switch")
	def currentDimmer2ONOFF = dimmer2.currentValue("switch")

	if (debugMode==true)
	{
		log.debug "checkDevices"
		log.debug "Thermostat State is: $currentTSMode"
		log.debug "Temp1 is $currentTemp1"
		log.debug "Temp2 is $currentTemp2"
		log.debug "Dimmer1 Level is $currentDimmer1Level"
		log.debug "Dimmer2 Level is $currentDimmer2Level"
		log.debug "Dimmer1 ONOFF is $currentDimmer1ONOFF"
		log.debug "Dimmer2 ONOFF is $currentDimmer2ONOFF"
	}
	
	
	// If you wanted to set dimmer 1 to ON:
	// dimmer1.on()
	// If you wanted to set dimmer 1 to OFF:
	// dimmer1.off()
	
	// If you wanted to set the level on Dimmer 1 to 50:
	//dimmer1.setLevel(50)
}

def dimmer1ONOFFHandler(evt){
	if (debugMode==true) log.debug "Dimmer 1 ON/OFF Status changed to: $evt.value"
}

def dimmer1LEVELHandler(evt){
	if (debugMode==true) log.debug "Dimmer 1 Level % changed to: $evt.value"
}

def modeHandler(evt){
	if (debugMode==true) log.debug "Mode changed to $evt.value"
}

And here is what the log looked like with debug turned on, and I moved the dimmer1 level and turned it off and on - and then the scheduled "checkDevices" code section ran and dumped all of the variables.

app:472019-02-06 04:29:22.105 pm debug     Dimmer2 ONOFF is on
app:472019-02-06 04:29:22.103 pm debug     Dimmer1 ONOFF is on
app:472019-02-06 04:29:22.101 pm debug     Dimmer2 Level is 99
app:472019-02-06 04:29:22.099 pm debug     Dimmer1 Level is 99
app:472019-02-06 04:29:22.097 pm debug     Temp2 is 72
app:472019-02-06 04:29:22.095 pm debug     Temp1 is 74.70
app:472019-02-06 04:29:22.091 pm debug     Thermostat State is: idle
app:472019-02-06 04:29:22.089 pm debug     checkDevices
app:472019-02-06 04:29:22.045 pm info      Simple App Example - Ran
app:472019-02-06 04:29:04.464 pm debug     Dimmer 1 ON/OFF Status changed to: on
app:472019-02-06 04:28:57.901 pm debug     Dimmer 1 ON/OFF Status changed to: off
app:472019-02-06 04:28:50.576 pm debug     Dimmer 1 Level % changed to: 99
app:472019-02-06 04:28:42.118 pm debug     Dimmer 1 Level % changed to: 78
app:472019-02-06 04:28:24.725 pm debug     initialize
app:472019-02-06 04:28:24.714 pm debug     updated

#16

This is great. Thanks! I'll take a look at this and the links you provided. I actually wanted to do some thermostat related things anyway, so the example is helpful. Thanks again.