Switch *changes*

Why isn't if switch changes an option for a conditional action?

Maybe someone can give me a better idea how to tackle this...

I'm trying to figure out ways to run my whole house fan for various set amounts of time. I created vitrual switches for Fan60, Fan120, Fan180 etc. But I want to add some intelegence to the rule so if one of the other FanXX's gets turned on it cancels the current delayed off.

I just struggle with Rule machine so much.. :frowning:

I presume because that's normally a trigger where you would have conditions in the actions to figure out which way it went (on/off) to do something else. If the trigger is "switch changed" then, inherently, there's no need for a condition since it's already been met.

If you have the rule framed out, you can post a screenshot. Even if you don't, if you can in plain language explain exactly what you want to happen, we can probably get you headed in the right direction.

5 Likes

It helps me to think of conditions as a state, and triggers as an action.

Changes is an action, so it can't be a condition. On and Off are states, where as Turns on and Turns off are actions. Hopefully framing it that way helps?

3 Likes

Conditions in Rule Machine are states, which for a switch would be on or off, so "changed" is both not available (because it's not a state) and wouldn't help you (because it sounds like you want to wait for one of these events, not test a state at a specific point in time). Rule Machine has a "Wait for events" action that would help you do the latter, and you can choose "*changed*" as the event (meaning any event) there.

How you would use this depends on how your existing rule(s) are written, so sharing more information about that might help if you aren't sure where this fits in. And there could be other options that would work for you as well--this is just the one that sounds most directly like what you asked about, without knowing more about your existing setup.

1 Like

Here's what I've got so far. Using all virtual switches and contacts so I can test all this behavior out. I also can't figure out why my elses are nesting the way they are.

In the final product, Testfan60 will be a virtual switch, testswitch will be the actual relay to turns the fan on.

I was looking to add another else block if someone turns on another virtual switch (say testfan120) to cancel this one hour timer and start a two hour timer.

I feel like I'm doing a bad job at explaining this :slight_smile:

All said and done basically I want 3 or 4 virtual switches that will turn the fan on for 1,2,3,or 4 hours. But if a user turns off the virtual switch, a window closes, etc the fan shuts off.

For one, you probably would want to grab this app:

And use it for the "time switches". If a switch is turned on in the group, all the others will be turned off. Then, you'll probably want to have a rule per "time switch".

Lastly, I think you'll want to kick to "wait" instead of delay.

So, if any switch is turned on, we'll set the 'timeoutNumber' (call this whatever you'd like) to the time, in minutes, we want the fan to run for based on which switch it was.

We check to make sure at least one contact sensor is open. If it is, then turn the fan on. The wait will turn the fan off if all the contact sensors are closed OR if all the switches are turned off (this would be for a manual override). If either happens, then the fan will be turned off. If neither happens, the wait will timeout after however many minutes the variable is set to.

If another switch is turned on, then the wait is auto cancelled and the next wait time will be set to the variable. So, if you turn on fanOn60, but after 20 minutes you turn on fanOn120, then the rule will start over and turn the fan off after another 120 minutes have passed.

2 Likes

That looks awesome! I'm trying to duplicate it now :slight_smile:

Should I add at the end after the timeout to turn the virtual switches as well? Because what else will turn them off once the time runs out?

I added some notifications too. And changed the time to 1m, 2m, 3m just to test

See how this looks...

Nothing, but that should be immaterial since this whole thing is driven by the 'on' event. The only pertinence of having the switch turn off would be to override the rule. It wouldn't hurt though.

I think you missed a screenshot.

Sorry ninja edit. I was caught up trying to fix the conditional if because I accidently put ALL instead of ANY and forgot the screenshot.. It's above in my edit.

1 Like

The only thing that stands out is your wait timeout is 1 second and not 1 minute. What type of variable did you set 'timeoutnumber' to?

Yeah, it definetly is going be seconds in my setup. It's just a number variable.

This seems to work just like I want it do. Since I'm sending a message/notification with how long the fan is turned on for, I'm trying to figure out how to say it in minutes. Doesn't seem like we can do math in the message to send.

I wonder if timeout and the variable will take it in the format of 1:00:00. Guess I could try it and see..

The variable translated to minutes...not seconds in my testing. Why I was asking what variable type you selected as that could be changing the way it's being pulled into the wait timeout period.

I keep replying at the same time as you or something. LOL

Yeah, definitely second here for some reason. With a number variable it won't take the colon. Wonder if I used text, and told it 1:00:00, that would work for the wait timeout.

One other thing you can add to your current setup if you'd like. You can add the contact sensors to the trigger. That way, say you turn on fan60, but the contacts are closed; the fan will kick on once a contact is opened. Without it, you'll need to turn the switch off and back on to get it going after opening the window.

Timeout definetly seems to behaving like HH:MM:SS for me.

Here's my finished rule. I ended up using another variable to convert seconds to minutes for my notification action.

I'm turning off the virtual switches after it errors out for a window not being open, or when the whole rule finishes. (Just because I'll put these virtual switches on a dashboard instead of the actual fan relay.)

Thank you so much for your help! I'm sure I'll tweak it more later and end up with more questions :slight_smile:

1 Like

Yep...I was double wrong about the time formatting so I obviously need to stop responding :smiley:

1 Like

No biggie. :slight_smile:

So I was playing around with this a little more. I think I will still need the One at a time device for my virtual switches. Unless you can think of a better way.

I noticed if the 60 minute switch is on, and you turn the 120 switch on the rule is setting the time for 60 again. Presumably because that is what matched first.

Would changing the ELSE-IF's, to just seperate IF blocks fix that, or am I better off you think using One at a time. Then a user has to turn off 60, before they turn on 120.?

Definitely better off using one at a time. My whole solution was based on the assumption of using that app. Otherwise, yes, you'd have to turn off the switch before turning on another.

Okay, I think everything is working how I want. I plan on using button manager or a dashboard to turn on the virtual time switches.

I was going to disable local control of the relay button for the fan, but I didn't want to have a situation were we couldn't manually turn it off it the hub were offline.

I added it as a switch, and another else-if to check if that's how it was turned on and turn on fan60 if so. That way we still have the safetys of having a window open.

For testing I'm using _testswitch so I can test without annoying the wife.