Lighting Level Formula

lights
automation

#1

Hi all,
I know there are a number of threads on here to do with lighting automation and setting different light levels based on time of day. I wondered if we could collate the solutions and discuss pros and cons.

Personally, I am using a formula to sort the light level out based on time of day and similar formula to decide when the automation should run (offsets of sunrise and sunset). I wondered if anyone has anything better?

integer((3.82 * ($hour24 + ((1 / 60) * $minute)))-((0.4 * ($hour24 + ((1 / 60) * $minute))) ** 2) + 10 + if((8 < $hour24) && ($hour24 < 17), ($hour24 + ((1 / 60) * $minute)) * 3, if((17 < $hour24) && (($hour24 + ((1 / 60) * $minute)) <= 20.5), $hour24 + ((1 / 60) * $minute), 0)))

As requested:


The piston updates the current light level variable which is used every time a light is switched on in other pistons and also sets the level of any light which is currently on.


#2

Can you show that in a piston please


#3

Updated first post to show as requested.


#4

Interesting. So basically a simulated lux sensor.

Can you adapt that based on weather conditions? Cloudy would be different than sunny. Raining would also be different. Etc


#5

I just vary the whole house on a Lux sensor. I don’t use weather data as it’s too slow to react to cloud cover or intermittent rain.


#6

I do something similar with my kitchen lights:

First, if time is between sunrise and sunset, the level is set to 100.
Next, if time is before sunrise, it takes 100% and subtract 1% for every minute prior to sunrise.
Then, if time is after 8pm, it similarly subtracts 1% for every minute it is beyond 8pm.

Lastly, it checks limits - I never want the lights to fade below 15% automatically and I don’t want to send values above 100 to the lights and potentially cause issues. So if the calculated value is below 15, it sets the level to 15. If the calculated value is above 100, it sets the level to 100.


#7

I suppose I could, add an extra value to the end based on weather condition. The main body is a lovely quadratic which varies the base level throughout the day, then I add 10 to ensure the level never drops below 10%, then finally the IF statement adds an additional value based on time to bump up the middle of the day.

I would like a better base formula really, which is what I am hoping will come from this thread. I nice bit of maths which is beyond my comprehension must exist for it.

This would be preferable, but the only decent sensor I can find is the Aeotec (https://aeotec.com/z-wave-sensor) MultiSensor and at £60 a unit it’s a bit much to put throughout the house.


#8

Here is the graph of what the formula looks like: https://www.desmos.com/calculator/8eyt0ouswk


#9

I use the Aeon v6 lux but I only have one for the whole house. I point it out the back window and base my lighting off the yard reading. This works acceptably well; the only caveat is when a rogue black cloud darkens the south side where the living room and kitchen are but the sun is still shining on the north side.
First world problems.


#10

What exactly are you trying to achieve from your formula? Not taking away from your maths capabilities, but light intensity based on time should be achievable with some pretty basic arithmetic, unless you’re trying to do something I don’t quite follow yet.

Edit to add: I see your graph now - looks like you’re trying to make a non-linear relationship between time and light intensity?


#11

@michicago Exactly, I started thinking I wanted it to peak in intensity at midday but it turns out that presumption was poor, what I needed was quick boosts up and down at specific parts of the day. I was trying to avoid using if functions completely, so if someone who is better at Math than I (not hard barely got a GCSE) could create something fancy that would be great.


#12

Gotcha. Can you help me understand the x-axis? Your function crosses zero around -2.5, for example. Is that 2.5 hours before Sunset or Sunrise? Midnight? Or is the x-axis not in minutes at all, and I’m way out in the weeds?! haha


#13

X axis is in hours, using it as the 24 hour clock. So at X=0 or 24, y=~10 which gives me the minimum level of 10%. I add the formula (1/60)*minutes to give me a decimal of the hour for a smoother level change.

On the light activation piston I have similar formula for time before sunset and after sunrise which the lights should come on automatically.


#14

I am still trying to create a right thing for me here, so I have a question. Does webcore have built in sine and cosine functions? If so, how do I call them?


#15

Just to close this thread off in case anyone looks, I ended up with these forumla: https://www.desmos.com/calculator/td7jkhconh

The red light in the light level and the blue line is the light colour in Kelvin (when multiplied by 100). X-axis is still hour of the day on a 24 hour clock. To do sine and cosine functions I use a web service from another site and get the result to the equation I submit to it.


#16

Can you share your final piston and what webservice your using. I think this is exactly what I am trying to achieve. A nice smooth sine wave. Currently for some reason I am getting this.


#17

I am using the MathJS API, http://api.mathjs.org. If WebCoRE handled sine and cosine I could do it native, alas it doesn’t so this is my method.

I have a piston which just tracks light level and temperature through out the day and assigned to a global and update any active lights. All lights then check that global when they come on too.


#18

Very nice on the math.js page. Thank you!

Another question, though. I am having trouble writing the light formula in webcore to make the get request. I can do basic math stuff and get results I want, however, this site use some crazy abbreviations I can’t find the documentation for.


#19

Nevermind I think I figured out. Thanks!


#20

Sorry for the delayed reply and just in case it is useful, this is the expression I hold in WebCoRE that I push to the API for light level:
“sin((pi/2)cos((” + ($hour24+(0.0166*$minute)) + “/3.88)+2.8))*45+55”

That then evaluates for time of day down to the minute in the hour. I have it run every 10 minutes.