Need some input for my new rule

Hi all.
I’m trying to do a rule that makes something like this this: When it’s dark enough (my luminance sensor reports below 100 lux), light up all window lamps. Then turn them off at defined times (childrens bedrooms 20.00, parents bedroom 22.00, living room 23.00).

I’ve solved most of it: When the value of the light sensor changes it checks if the value is below 100, it’s really afternoon and if this hasn’t been triggered before (so if I turn off a lamp manually it doesn’t turn it on again and again). If all this is true it turns the a group containing those items on. And then some cron stuff to turn them off at correct times. Everything fine.

This works nice now that it’s winter. Problem will be in some months when sunset happens later (I’m living in Sweden). If the value of the luminance sensor doesn’t get below 100 until after 20.00, then of course the lamps in the childrens bedrooms should never be turned on at all. Any idea on how to solve this without overcomplicating things? I realize I probably can’t use the group at all since I’m not sure all lamps should be turned on at all. I could turn them on one by one and for every lamp also check what time it is (so it isn’t too late to turn this specific lamp on), but is seems to me the script is growing out of proportions. Am I missing some easier way to do this?

Here just a thought

but come spring/early summer you may want to switch the lights on at any given time before 20:00 when your lux threshold has been met (say 19:00).
So you may need to define ‘afternoon’ in another way.

On the other hands you have one master group and three sub-groups (children, parents, livingroom). Depending how high up north you live, is there a potential that you reach the 100lux after 22:00 in summer? That would trigger potentially a similar issue for the light in the parents bedroom.
Would it make it easier to disaggregate and write a separate rule for the all three? To me it looks like you have potentially three different on and three different off conditions. Surely they can be put into one ‘on’-rule, but maybe the code would be cleaner with three separate rules?
As said above, just a thought.

1 Like

Yep. You’re kinda confirming what I was expecting, that the simplest would be splitting this up entirely. The sun is up almost til midnight here during summer, so definitely after 22, yes :slight_smile:

Actually it’s a bit more complicated than I described. Some more lamps, and also I want the lamps to turn off later on fridays and saturdays. Plus probably I want a way to do it later sometimes if we’re up later. Guess this will be a bit of scripting to do…

Why dont you have a look at the astro binding? it can set the time of sun rise or sun dawn to items or even trigger a rules.

I wanted to recommend the astro-binding too, but thought that wouldn’t better the problem with switching the lights off. Maybe you would be better off by using three timers with individual runtimes for switching off the lights rather than setting a fixed time? this way you could also easily implement a “Cancel” button if you want a light on for longer. I use this for several independent alarm clocks with good results; each alarm triggers lights, radios etc, to turn on and later off after a definable time. The runtime of the alarm can be defined through setpoints.

Calculated sunset and sunrise? No thanks! I used that many years ago, before I bought my first light sensor. Total crap. Either the lamps where turned on all too early on sunny days or I had to turn them on manually on cloudy ones. Measured values are always superior to calculated ones. But yes, as a poor mans alternative it’s a good thing being able to calculate sunset and sunrise.

As for the cancel button I’m thinking about having a virtual item (ie one that isn’t connected to any thing) that I can turn on if know I’m gonna be up late and if that item is on the lamps shouldn’t turn off until later. I guess the ultimate solution would be motion sensors to see if anyone is still up. Or maybe pressure sensors in the bed :smile: