Scenes, Transitions and Rule Machine

Hey,

So had my Hubitat over a year, and as much as i love it, it can be damn infuriating at times!! :slight_smile:

So right now, I've got a load of bulbs (Ikea), some sockets (Ikea/Lidl), and also a bunch of Zemismart Scene selctors. Now including the virtual devices, there nearly 80 devices.

One of the things that i've always done is a "Bed time Routine" setting lights and turning them off, in a pattern as i head off to bed. This was all done using a rulemachine rule when it entered nightmode. However, as i've been adding things, i've got fed up with the rule mchine UI. Honestly its aweful! (Please tell me what i am missing!?) If i could have a coded way of doing things that would be great, but there are SO many windows of Triggers, and restrictions, and Actions, and they all look the same... and drop downs with 80 devices in...

So the point! :slight_smile:

Can someone tell me a clear manageable way to do this... Rule machine i find hard work. I can't get scene transitions to work (Tried one with a single dimmer to go from on-100% to off 0% and it just waits the 30 seconds i said and turns off...) Rule machine delayed commands have just stopped working. Nothing in the error logs to give any indication...

Sorry Rant over, Seriously considering having another go at getting Home assistant working

Thanks in Advance! :slight_smile:

Rule Machine's UI can be a bit awkward and takes some getting used to (and getting used to not only the UI but also how triggers interact with things like delayed actions and waits), but what you want should definitely be possible. Since you also seem to be having problems with the rule itself, might I suggest posting a screenshot of how you have it set up (both triggers and actions), and maybe someone can see if there are any problems there? Also, it's not clear to me if the "scene transition" you're talking about is part of your rule or something you did via Groups and Scenes, so that would be good information to share as well, along with what kind of device that one is.

I'm not sure if your "missing" anything in RM per se, but there are a couple things that may be good to know if you don't already. First, while Rule Machine is tempting because it's powerful, it's not necessary for a lot of things and wouldn't be my first go-to for most tasks. Hubitat has lots of built-in apps designed for specific purposes. In your case, there is a built-in app that used to be called Simple Lighting but is now called Simple Automation Rules that might do what you want (I'm not sure what all you're doing, so this is just something I'm suggesting as a starting point if you haven't already considered it). As its old name suggests, it's an easy way to control switches, dimmers, and bulbs (even if they aren't really "lights," part of the reason the name was changed, besides the fact that other types of devices were added too). Pretty much any purpose-built app is going to be easier and less awkward to set up than Rule Machine, though sometimes at the expense of how powerful they are(n't).

Second, if you know Groovy (or think you can learn; if you know Java, you have a good start--but either way you do have to learn how Hubitat's sandbox works), you can write custom apps instead of using Rule Machine or built-in apps. Rule Machine exists so you don't have to, but again, a purpose-built app is usually easier--except the caveat in this particular case that you have to write it. Since you sound familiar with Home Assistant, this is sort of like the AppDaemon route there, except the functionality is built in and it's Groovy instead of Python. But I haven't used Home Assistant as my primary "hub" in a while, so my metaphor might be a bit off nowadays. :slight_smile:

Hey,

Thanks for replying! I'd lost my head a little yesterday! What am i trying to do!? I think the key thing is really understand and have something reliable... I've added quite a few devices recently, and the rule machine i had for the bedtime routine was not proving reliable. Random lights would not turn off in the "First phase" (Turning off all the interesting lights, and leaving just a few main ceiling lights on to navigate the house...) As this was frustrating me, i was trying to work out if i should be using scenes more, etc.. and then lead to to wonder if there "Was a better way". The custom App appeals to me, but i';ve actually never used Home Assistant, and my coding is more competent Hacking rather than writing from scratch stuff... I'll search about to see if i can find any custom apps to build from...

Screenshot of my Rule

There used to be much more to this, and the delayed actions were fine for a good 6-12 months, but now that night one simply doesn't do anything...

The scene transition was originally for this purpose, but i then tried to get this to work with a test one, with 1 dimmer in. I was triggering this from the device screen, using push and on, not sure how thats all supposed to work to be honest...

Simple Automation - Yep, on that... I've moved some of the functionality over to that already... There is no delay capability on that or the "Fade" from Rule machine either... This is where i was hoping i could get the "Scene Transitions" working, and then they'd be "Triggerable" from Simple Automation... It's not how i had it with the delays, but a "Long Fade" was something i could cope with... But i couldn't work out the transitions...

To be honest, if i could work out the transitions, then that would be me pretty much sorted, but they were not working...

Thanks again,

Hmm, I don't see any problems with the rule. Are the transitions that aren't working the ones built into the rule (the "fade over time"-type things) or a "Scene Transition" you created in Groups and Scenes? The only things I can think of are whether your dimmers/bulbs don't like "fade to 0" (usually a "Set Level" to 0, the ultimate destination, will cause the bulb to turn off, but note that the "level" attribute will generally report the last level at which it was on, not 0 when it's off, but I don't see how that could matter here). You might try a fade to 1, then a plain "Off" after the desired delay to see if that does anything different.

Otherwise since it sounds like you added a bunch of devices, you'll often see people recommend letting things "settle" before doing too much with automation. This is usually only an issue if you add a large number of devices at a time (I think I've seen 20+ Z-Wave devices mentioned before and the recommended wait time was 3 days), but with just a few devices you're unlikely to run into this. So, probably not the problem either...

Both! :slight_smile: OK, looking at your suggestion for the fade to 1 then off... that seemed to work in a test rule, I'll try implementing that properly later and do some more testing. I also observed a "Fade to 0" doesn't seem to result in any level changes at all, meaning this may be most of the issue here.

I also took your custom app suggestion, and did some digging about, finding a basic app that i could build ontop of... I've hacked it about a bit, just to try and get it working. but i am getting a problem there too with the "runin" function. This seemed like exactly the groovy i would need to get things working. However, thats not really behaving as i would expect either, as the runin is run twice, but it doesnt wait the right amount of time, and then also only triggers once, not twice...

dev:22020-12-14 08:31:49.031 infobedroom Light was turned off
app:5162020-12-14 08:30:41.750 infoSimple Fave Rule Machine
dev:182020-12-14 08:19:29.776 infoBen p20pro has arrived
dev:162020-12-14 08:14:19.184 infoDiningRoomLight was turned on
app:5152020-12-14 08:14:19.095 debugToggling
dev:3102020-12-14 08:14:10.134 infoHall light is 100% [physical]
dev:3102020-12-14 08:14:09.151 infoHall light was turned on [digital]
app:5152020-12-14 08:14:09.108 debugRunin Sent
app:5152020-12-14 08:14:09.051 debugIs ON
app:5152020-12-14 08:14:09.048 debugRun
dev:5522020-12-14 08:14:09.023 infoScen-Test was turned on


definition(
    name: "Simple App Example",
    namespace: "anonymous",
    author: "anonymous",
    description: "Toggle output switch when motion and logic switch is on.",
    category: "Convenience",
    iconUrl: "",
    iconX2Url: "",
    iconX3Url: "")

preferences
{
    section
    {
        input name: "trigger", type: "capability.switch", title: "Trigger Switch", multiple: false, required: true
        input name: "outputSwitch", type: "capability.switch", title: "Output Switch", multiple: false, required: true
        input name: "dimmers", type: "capability.switchLevel", title: "Dimmers", multiple: true, required: false
        input name: "testDimmers", type: "capability.switchLevel", title: "TestDimmers", multiple: true, required: false
    }
}

void installed()
{
    updated()
}

void updated()
{
    unsubscribe()
    subscribe(trigger, "switch", eventHandler)
}

void uninstalled()
{
    // unsubscribe to all events
    unsubscribe()
}

void eventHandler(evt)
{
    //Toggle()
    //runIn(5,Toggle)
    log.debug "Run"
    if(evt.value == "on")
        log.debug "Is ON"
        runIn(5,Toggle)
        runIn(10,Toggle)
        log.debug "Runin Sent"

}

def Toggle(){
     log.debug "Toggling"
     if(outputSwitch.currentValue("switch") == "on"){
        outputSwitch.off()} 
     else{
        outputSwitch.on()    
    }
}

This does make me wonder if there is anything wrong more fundamentally as the groovy does't seem to be working. Though i am totally aware this may just be my god awful initial attempt at hubitat groovy!! :smiley:

I'm not 100% sure what the problem is that you're describing, but could it be the fact that your second runIn() overwrites the one scheduled by the first, resulting in only one scheduled job? This is the default behavior if the handler method matches something already scheduled. See: Common Methods Object - Hubitat Documentation. The option you are looking for to not do this is documented as overwrite: false. There you will also see that the technically correct call is runIn(5,"Toggle") rather than runIn(5,Toggle) (with a string for the handler name), but Hubitat/Groovy does seem good about finding it regardless. (Groovy convention is also to start method names with lowercase like toggle, but there is no technical requirement there...or at least not something you can't overcome if you run into Groovy's magic trying to do a bit too much guesswork for you.)

Hey @bertabcd1234,

Thanks for getting back to me! I was trying to look though the documentation, but my "Testing" had concluded that this was the issue.

Thanks for the coding standard guide! :slight_smile: Just learning, so always appreciate a few pointers i the right direction! I'll carry on hacking this to see if i can get what i want.

thanks all for the help! :smiley: