Making my own Bathroom smart light with PLEG

Hello
I have tried to search the forum for something similar, but have not been able to find something that does what I need.

I am trying to make my own smart switch, that I can configure the way I want.
This is what I want the plugin to do:
1 Turn on the light when motion is detected.
2 Turn off the light after a specified time
3 Make the light come on at a different level at night time that during the day / evening
4 Have a manual override feature that “forces” the light to be on for a specified time

When it comes to number 4 I hope to make the light come on normally if the manual switch is activated.
This can be because the sensor by accident does not detect the movement. If this happens and manual switch is activated I want the light to be turned off like with normal movement. In a similar tread I have read about a triple click to activate “manual override”…?

When it comes to number 1 and 2. I think I can manage to make these myself.
I am struggling a bit with number 3. As a opposite to similar threads I want the light level to be controlled according to time, and not according to sunset/ sunrise.

Maybe it also would be nice to have a logic that does not sends a ON command when the light already is on.

So I know this is similar to other cases, but hope someone take their time to help a newbie :slight_smile:

You should be able to do this with the existing smart switch plug in. Evoke different setting by schedule in scenes. This plugin pauses for manual override, then resumes after a preselected time.

Thank you for your answer.
But I know about the smart switch plugin, and is currently using it.
The reason I want PLEG to do it is that I want to control how it is working.
And there is something with the manual override that I dont like with the smart switch plugin.
I want to control how the light behaves after the switch has been used manually…

By folowing this thread I see I can setup part of what I want.
http://forum.micasaverde.com/index.php/topic,14709.0.html

But how can I specify that I want night to be after 01:00. As mentioned earlier this is when I want night level to be activated when motion is detected.

When do you want Day to begin?

Day should begin at 06:00

I gather you want to use absolute time not a variable time, which the Day/Night Plugin calculates.

Try using (0100:00:00;NOW;0600:00:00) in place of Night in the conditions.

eg.
[left]Name[/left] [center]Conditions[/center]
TurnOnLight1 (NOT LightIsOn1) AND (Motion1 AND (0100:00:00;NOW;0600:00:00))

edit: RTS would most probably suggest using TurnOnLight1 in place of Now as it uses a timestamp (If I recall correctly which is a failsafe in case Vera resets).

(0100:00:00;NOW;0600:00:00)

The syntax for time is wrong. When used as sequence time they are absolute: HH:MM:SS for the current day. There are not 100 or 600 hours in a day.

When used as a relative time with > and < operators they are also HH:MM:SS So 100:00:00 would be 100 hours.

I found out that by making a virtual switch that indicates day level and night level I had a easy way to get this to work…

Thanks for your help

Since I dont have to much memory on my vera I have decided to give this project another go.
The project goal is to replace the “Smart Switch” plugin. I think I can save some memory by removing this plugin and add some new lines to the pleg plugin.

My requirements for the logic is the same as when I posted this some time ago.
1 Turn on the light when motion is detected. Check
2 Turn off the light after a specified time. Check
3 Make the light come on at a different level at night time that during the day / evening. Check
4 Have a manual override feature that “forces” the light to be on for a specified time

I have based my logic on the example in the pdf manual.
And I think I have solved 1-3. I also think that I might have a solution for 4.

My setup is as follows:

Triggers
Name Description
Motion Sensor Bad is tripped
LightOn Spotter Bad 3 etg is turned on

Schedules
Name Type Time Days Random On Delay Off After Type Off Time Off Days Random Off Delay
NightLevel Weekly 23:30:00 1,2,3,4,5,6,7 None Weekly 05:45:00 1,2,3,4,5,6,7 None

Conditions
Name Expression
TurnOnDay !LightOn and Motion and (!LightOn; Motion) and !NightLevel
TurnOffDay LightOn and !Motion and (!Motion; NOW > 20:00)
TurnOnNight !LightOn and Motion and (!LightOn; Motion) and NightLevel
TurnOffNight LightOn and !Motion and (!Motion; NOW > 5:00) and NightLevel

I use a fibaro dimmer to control the lights. These have instant status update, so the status is immediately updated in the vera.
Earlier this has given me some problems when it comes to manual override. And I have not been able to turn the light off.
But with this logic I was able to turn the light off. But it turned on when the motion re-triggered.
Is it possible to limit the The TurnOn condtitions? Something like what has been done before with the auto detection:

Motion;LightOn<10

Could it work if I add this to the TurnOn conditions?

As a alternative I can have a scene that turn on the light disarm the pleg wait NN minutes and turns light off and arms the pleg.
But this would be a backup solution if it is not possible to solve the logic above.

Hope there are some bathroom experts out there that have an opinion on this!

regards

Is it possible to limit the The TurnOn condtitions? Something like what has been done before with the auto detection:

Motion;LightOn<10

Could it work if I add this to the TurnOn conditions?


You can certainly constrain the motion-triggered turn-on. You just need to decide what the constraint should be. For example:

TurnOnDay !LightOn and Motion and (!LightOn; Motion > 2:00) and !NightLevel

Will only turn on if the motion trigger occurred more than two minutes after the light was turned off.

Another (similar) way you can limit the condition from firing over and over would be by putting another condition to prevent it from occurring if if happened ‘recently’

TurnOnDay !LightOn and Motion and (!LightOn; Motion) and !NightLevel and (TurnOnDay;Now>3600)

Will now TurnOnDay if it has been at least 3600seconds since it triggered last.

I see
So by implementing this logic:
TurnOnDay !LightOn and Motion and (!LightOn; Motion > 2:00) and !NightLevel
I can prevent the light to turn On.

But what I want the most the opposite.
I want to be able to prevent the light from turning off. My normal auto off timer would be 15 minutes, and by flipping the switch off and on I would get 1 hour until it turns off. Is this possible?

Maybe something like this?:
TurnOffDay LightOn and !Motion and (!Motion; NOW > 20:00) and (Motion;LightOn < 10)
By adding the last part I am hoping that the light only turns off if LightOn happens less than 10 seconds after Motion.

a quick cycling of the lights On-Off-On

DoSomething = LightOn and (!LightOn; LightOn < 10)

translated into: DoSomething if (the light is now on) and (the light was turned on less than 10seconds from the last time it was turned off)

I can try to utilize that.

But will this logic hold water?
TurnOnDay !LightOn and Motion and (!LightOn; Motion > 2:00) and !NightLevel
TurnOffDay LightOn and !Motion and (!Motion; NOW > 20:00) and (Motion;LightOn < 10)

I am thinking especially on the last “sentence”. Can this logic ever be true?
I only want to turn off the light if it was turned on less than 10 seconds after motion.

[quote=“haavard, post:15, topic:175928”]I can try to utilize that.

But will this logic hold water?
TurnOnDay !LightOn and Motion and (!LightOn; Motion > 2:00) and !NightLevel
TurnOffDay LightOn and !Motion and (!Motion; NOW > 20:00) and (Motion;LightOn < 10)

I am thinking especially on the last “sentence”. Can this logic ever be true?
I only want to turn off the light if it was turned on less than 10 seconds after motion.[/quote]

the first will trigger when condition TurnOnDay is met, which is motion triggered. So the boldface part is confusing.

I agree that it was a bit confusing :slight_smile:

With the following logic:
Motion;LightOn < 10
I intend to detect that the light was turned on automatically (It could probably be set lower than 10).

And I only want to turn it off if this has been true.
In other words only auto off if auto on.

Vera cannot distinguish if a light was manually triggered at the switch versus being caused by PLEG or by a scene. So, you may be chasing a solution that is difficult.

Thinking about your problem, if you turn on the light manually, before the sensor detected motion and turned it on for you. (LightOn;Motion) TurnOffDay won’t switch.

the best thing for you to do (and this is the fun part) is experiment with your solutions.

Also, when you get the chance, read PLEG Basics.

Thank you for your replies :slight_smile:

If you look the PLEG Basics examples you can see that the logic I use is almost direct copy from the first example. I have also said this in my post :slight_smile:
So yes the PLEG Basics is a great place to start.

RexBeckett has just posted a new motion example that contains all that I requested. I just have to tune it to fit my needs.

regrads