Motion, Switch, Mode, and Dimmers

I want to do a mix of two or three things:

  1. When I first walk into the kitchen in the morning, (a) turn off the air filter and (b) turn on the kitchen lights;
  2. continue to turn the kitchen lights on and off through the day based on motion;
  3. adjust dimmer levels based on mode,
  4. set different dimmer levels for different lights (sink lights need to be brighter than the cooking lights);
  5. if the dimmer level is set manually, stop adjusting until the lights are turned off manually.

Motion Lighting will do 1(b), 2, 3, and 5 but won't let me set a different level for different lights (or 1(a) turn off the air filter). Rule Machine easily handles 1-4 but I can't figure out how to do #5.

I've seen a number of suggestions that I should use a virtual switch but I can't find an example of how to do so (and haven't been able to figure it out on my own). Could someone post example code showing how to create the Rule Machine equivalent of Motion Lighting's "Enable override with dimmer level change?"

My suggestion is to continue to use Motion Lighting. Just have a couple instances of it instead of one. The first instance would be cooking lights, and the other for sink lights.

You could use motion lighting or simple automation app for the air filter.

No reason to have to spin up a rule just to do what the other apps can more easily handle. I can't think of a reason that you cannot use the same motion sensor for multiple Motion Lighting child apps.

1 Like

Thanks for the suggestion, and of course that's an entirely reasonable approach. However, my real goal is to build up my arsenal of tools for the platform. This seems like something that will come up again (it certainly has come up repeatedly in the past), and it seems like an important technique for using RM.

The answer is usually to "use a virtual switch." But I don't know how to do that... So I'd really like an answer to the question I asked - how do I use a virtual switch to interact with a rule?

I cannot see how that would help here.

You would just write the rule (paraphrasing here) using the options you want.

  • IF time between 8AM and 9PM AND motion active, turn on light A 75%, light B 50%.
    or
  • IF motion active, and mode is Day, turn on light A 75%, light B 50%.

But really, this isn't the best application for Rule Machine.

I'm trying to solve the problem of "if the dimmer level is set manually, pause the rule until the lights are turned off manually."

Rule Machine has some pretty good primitives for the part you're pointing to. Here's the rule for that part:

I would take a look at the Motion Lighting App Documentation, specifically step 6 of the motion lighting setup.

As for you requirements:

1A - Should be able to control the air filter by the option that says "Turn on a switches per mode". I am not sure how you normally control the air filter, but if its not available there, I would make a virtual switch in your devices, name it something like Air Filter Virtual Off Switch, then in RM, have a rule that is triggered when that newly created switch's state changes, then for the actions, if the virtual switch is on, turn the air filter off, since you want it to turn off, if the switch is off, turn the filter on, or you can do nothing depending on what you want.

Note: If all you want to do is turn the air filter off, then you could have the trigger be the virtual switch turning on, and the only action is turning the filter off to simplify things a bit.

Then back in the motion lighting app, I would use the turn on switches per mode option to trigger that virtual switch, which then would trigger the RM to turn the air filter off.

1B - Normal operation of motion lighting

2 - Normal operation of motion lighting

3 - "Set these dimmers per mode" option

4 - OK, this is an interesting one, and one that I actually use and can provide an example for that I know works. There are some community apps, such as Lights on Motion Plus which you can take a look at, but you can do it with the built in motion lighting app as well with the use of scenes. For instance, if as you say you want your sink lights to be brighter, I would make a scene in the Groups and Scenes app that would have the desired settings for your lights. Then in the motion lighting app, use the "Select Scenes per mode" option to reference that scene. An example of this is my Master Bedroom Lighting app, which has 100% at 5000K during the day, 100% at 3500K in the evening and for the night, one of my lamps is 1% 2200K and the other two are off. This night mode is similar to what I believe you are after.

MB Motion Lighting

MB Night Mode

5 - Normal Override options in Motion Lighting app

If you have any questions feel free to ask.

Thanks! That's quite helpful, and does solve the problem at hand. I should have considered scenes; they seem largely designed for what I'm trying to do. Good technique.

Again, though, my purpose here isn't solely to solve this particular problem, it's to understand the tools at my disposal. Let me ask a much narrower question.

Is the basic idea behind virtual switches that they will always be backed by some hand-tuned automation that will interpret them? Said another way, is it fair to say that the fundamental purpose of virtual switches is to generate events, and the processing of those events is entirely handled by an installed application (ie. simple automation rules, motion/mode lighting, rule machine)?

Yes and no, virtual switches, or any virtual device for that matter is just another way to store or send data between devices that would otherwise not communicate. I took a screenshot of the virtual switches that I use, and most of those, are explicity for interfacing with alexa, specifically voice commands.

My Virtual Switches

  • Those reboot and shutdown switches are used as a quick and easy way to shutdown or reboot the hub whether that be with alexa or with another app.
  • The internet status switch holds the data of whether the internet is up or down according to the Web Pinger app. I then use that data with some other rules to attempt to bring the internet back online.
  • The echo button, alexa goodnight, and reading mode are all to allow voice commands or physical echo devices to interface with my hub.
  • The motion detection switch is a way to disable motion detection all together, again through alexa.

This is just how I use virtual switches though, I have seen other uses for virtual dimmers say as holding data such as counts in the brightness level, which is a sort of different approach to global variables.

Ah. Could you describe how you use the "motion detection switch" to disable motion detection? I think that's what I've been blundering around trying to asking this whole time. :slight_smile:

BTW why do you use virtual switches for e.g. "Alexa Goodnight?" For stuff like that I just set up a scene ("good night") and published that directly to the HE Alexa app.

So when this switch is turned on, all motion detection is disabled. I expose this switch to Alexa so that I can just say "turn off motion detection" and then the lights are in manual only mode for whatever reason I want.

It is because my goodnight routine is somewhat complex as you can see in the screenshot below. That way I can have more granular control over what exactly "Goodnight Mode" means.

1 Like

This isn't motion trigger but is a way to disable rules with a virtual switch. Heater override is a virtual switch.

Pretty straightforward in hindsight. Thanks!