intelligent day trigger

My shade open at sunrise - which is perfectly good in winter time but in summer this will be very early and I’ll wake up from the noise.

What I want to do is something like this:

  1. Day trigger
  2. If sensor 4 is armed - open right now
  3. else: check if sensors have been triggered(in the time frame 06:00 to now) - already woke up
  4. OR wait until sensor 1, sensor 2 or sensor 3 is tripped – which means just woke up
  5. OR time X has reached – which means sleeping longer or away
    5b. If time X has reached I want to add a random number of minutes (1 to 20) before opening shades.

(1 and 2 is easy)

How can I do this efficiently with Lua?

Thanks for any help.

How can I do this efficiently with Lua?
This [u]really[/u] is a job for PLEG. It is now available for UI6 so why not use it?

You could do this in scene Lua but I wouldn’t call it efficient. You will likely need to set-up a polling loop using either a schedule or luup.call_delay(…) to wait for your conditions. It would be difficult to make it immune to Vera restarts.

Yes, I installed PLEG and core and I’ll give it a try.
Even though as of right now I have no idea where to begin. :wink:

Thanks for pointing me to PLEG again.

Edit:

It is really powerful, but right now I don’t get it to work. How can I get all triggers and conditions together?

Have you read PLEG Basics?

Not yet, thanks.

[quote=“dawiinci, post:1, topic:179696”]My shade open at sunrise - which is perfectly good in winter time but in summer this will be very early and I’ll wake up from the noise.

What I want to do is something like this:

  1. Day trigger
  2. If sensor 4 is armed - open right now
  3. else: check if sensors have been triggered(in the time frame 06:00 to now) - already woke up
  4. OR wait until sensor 1, sensor 2 or sensor 3 is tripped – which means just woke up
  5. OR time X has reached – which means sleeping longer or away
    5b. If time X has reached I want to add a random number of minutes (1 to 20) before opening shades.

(1 and 2 is easy)

How can I do this efficiently with Lua?

Thanks for any help.[/quote]

I like solving complex problems, but wouldn’t you want to just open the blinds just after the time you wanna wake up?

Then, cancel the scene if your sensor detected no motion in the 30mins prior to your wake up time. (you are sleeping in)

No, if I get up before sunrise I want it to stay closed. Sensor 4 is the alarm system - which means no one at home - or a tripped but not armed sensor someone is in the house.

Also if I can achieve this, I think I can do a lot more with PLEG.

Ok I have done some scenes with PLEG. Pretty nice and it was a helpful PLEG Basics!

Some questions:

I have a condition for opening shades if no ones at home (armed) or some triggers have been tripped 2 hours before (not armed).
Now I want a second condition which only fires if the first one didn’t.

I think if I just use the state of the first condition in my second condition it either is always true after the first run or it is only true if conditions are true (is it always checking?).

How can I set a variable (true-false) which expires 5 minutes before sunrise? I would use this to “remember” if shades have already opened today and avoid to send out the opening signal if motion is detected inside.

Basically it should only run every the morning until the action is activated once.

it would be helpful if you post the STATUS report from PLEG so we can see what you have.

[quote=“dawiinci, post:8, topic:179696”]Ok I have done some scenes with PLEG. Pretty nice and it was a helpful PLEG Basics!

Some questions:

I have a condition for opening shades if no ones at home (armed) or some triggers have been tripped 2 hours before (not armed).
Now I want a second condition which only fires if the first one didn’t.

I think if I just use the state of the first condition in my second condition it either is always true after the first run or it is only true if conditions are true (is it always checking?).

How can I set a variable (true-false) which expires 5 minutes before sunrise? I would use this to “remember” if shades have already opened today and avoid to send out the opening signal if motion is detected inside.

Basically it should only run every the morning until the action is activated once.[/quote]

you should be able to accomplish what you want.

I have to translate the names a bit for better understanding:

--open_immediately sunrise_shades AND (alarm_armed_away OR (last_motion_kitchen, last_entry_door_open, last_motion_livingroom, Now < 02:00:00)) (all last tripped)

–open a bit later in summer
NOT open_immediately AND weekdays

–open_later
NOT open_immediately AND weekend

btw. I have a schedule called sunrise (or also weekdays), do I have to add this trigger to any PLEG device or can I use a separate device with such common variables?

Will a schedule shut the light off afterwards?

I would add in the Day/Night app. It switches at Sunrise/Sunset and integrates into PLEG very nicely.

so you have in essence…made slight changes to type easier… add a summer schedule to adjust the on time

ShadesOpenWinter = !Summer AND IsWeekday AND IsSunrise AND (AlarmArmedAway AND (MotionKitchen, DoorOpened, MotionLivingRoom; Now,2:00:00))

ShadesOpenSummer = Summer AND IsWeekday AND SummerShadeOnSchedule AND (AlarmArmedAway AND (MotionKitchen, DoorOpened, MotionLivingRoom; Now,2:00:00))

SummerShadeOnSchedule is the time you want them on in the summer.
Summer is a schedule that starts in the spring and ends in the autumn.

Looking like what you want?

Not exactly.

Maybe I try to explain what I want in words.

Principally the shades should go up at sunrise so the plants get light and in winter the sun heats up the rooms.
However if I’m still sleeping I don’t want it to happen until I get up (hence the three motion sensors).

But if I sleep longer the shades should still go up - just later, depending on weekday or weekend.

Thanks for your help, I really appreciate it.

So, the shades open at sunrise unless there is No motion

ShadesOpen = Sunrise AND (MotionKitchen,DoorOpened,MotionLivingRoom,NOW<20:00:00)

says open the shades if it is sunrise and I am up and about.

So now, sunrise has passed an you want to open them when you are finally up and about.

Shades Open = ShadesClosed and IsDay and (MotionKitchen OR MotionLivingRoom OR DoorOpened)

This will open the shades if they are closed, if it is daytime (use Day/Night app) and motion/movement is detected in your house. You can use any combination of motion to determine what you want to be ‘up and about’, but I figure if you are in the kitchen or Living Room or left the house, you are OK with the shades opening.

better?

ShadesOpen = Sunrise AND (MotionKitchen,DoorOpened,MotionLivingRoom,NOW<20:00:00)
I think here should be 02:00:00 otherwise it would always open because I triggered the sensors in the evening, right?.

Shades Open = ShadesClosed and IsDay and (MotionKitchen OR MotionLivingRoom OR DoorOpened)
I don’t have any information about ShadesClosed. I just have to assume they are if they are not opened today.

And I only want to do this once a day. Like this it would probably fire every time I trigger the motion sensors.

What about the case if I sleep too long and still want to have some light for my plants?

Without knowing how Sunrise is defined … it is not easy to comment on.

i.e. is Sunrise only TRUE at the instant in time of Sunrise ? Or is it True until Sunset ?

Basically you want logic to be based on if you are home or away.
Some folks implement this as a virtual switch …
This switch can be set by automation logic and/or manually.
Then you can play with the logic needed to determine if you are home and/or away and separate it from the logic to open/close your shades based on presence.

RichardTSchaefer thanks a lot for that plugin - it is very helpful.

However I’m stuck with some things that I don’t know.

If I make one condition with (Temperature > 20) will this switch on a switch every time this condition is met (without a trigger)?
What happens after a restart?
What happens if switch is switched off manually but the condition is met?

If the condition becomes false will it switch off the switch?

How often are the values read for the conditions?

If I use a trigger name multiple times (referring to the same thing) is this a problem or is there a better way?

Can I set variables?

Can I set variables that expire after some time?

… more to come

Thanks

If I make one condition with (Temperature > 20) will this switch on a switch every time this condition is met (without a trigger)?
It will fire its Action whenever it becomes true. To become true, it must have been false. So the Action will fire when Temperature was less than or equal to 20 and becomes more than 20.
What happens after a restart?
Nothing special. Conditions will only fire if something has changed.
What happens if switch is switched off manually but the condition is met?
The state of a switch will only be reflected in Conditions if you include it as a Trigger term.
If the condition becomes false will it switch off the switch?
No. If you want that to happen, you will need to include another Condition to do that.
How often are the values read for the conditions?
Whenever they change.
If I use a trigger name multiple times (referring to the same thing) is this a problem or is there a better way?
It isn't a problem. If you use the same expression in several Conditions, it could be worth making it a Condition itself so that you can use that in place of the expression. I would not expect it to have much impact on CPU load but it can make the logic more readable.
Can I set variables?
You can set VariableContainer variables using an Action. You can set State Variables (see PLEG Basics). You can also use a Condition as a variable.
Can I set variables that expire after some time?
You can start a Self-Trigger timer and, when it ends, change your variable.