Light level based on luminescence

Im trying to find a way to dim some lights based on the light level outside reported by a aeon multi sensor. I want to adjust the lights brighter as it gets dark outside and dimmer as it gets brighter. Anyone know of a way to accomplish this?

I wrote an app to do this, though you could probably work something using rule machine using lux as a trigger, then light state as a condition so as to only adjust devices that are already on.
Also I do the opposite, the brighter it is outside the brighter the device.

1 Like

I tried rule machine and wasn’t able to figure out how to transition the light brighter as it got darker. And back the other way.

Care to share your app Mike?

1 Like

Hi,

coming from ST I wrote a Piston in webcore to do it. I'm using a TSL2561 with ST_Anything/HubDuino, here's the code:

My current workaround are three rules with Hubitat simple lighting which set captured scenes in the Group and Scenes app based on luminance and one to kill the lights when it's bright enough. The rule for the lowest level, when it's bright but below off, must be restricted, else the off and other rules will play ping pong :wink:

I'm a little confused by this. Your first If states > 25 lux. But then you have an Else-if lux is between 0-150. Won't the first fire for everytihing > 25 and the second only for things < 25?

Maybe it's not clear in the picture, but the piston goes like this:
Lux >= 251: Lights off
Lux <= 250: dim lights to 40 and 30%
Lux 0...150: dim lights to 65 and 80% and switch on an non-dimable light
I'm using two light groups
@lichtsensor is the light sensor defined as global variable.

Okay...maybe I'm missing it but I'm not seeing 251 or 250 anywhere in your piston. But if it's working, great!

I use this app. Still in the works and couple formatting to do but so far it's been working pretty consistently for me.

Thanks, it looks like it's for ST, amiright?

Was initially, yes, but it also works on hubitat.

Updated the app. If any of you is still using it or stopped using it due to the very same issue I just fixed, you might want to update your instance using this new code. No need to reinstall, just copy paste the new code.

Great. I’ll give it a shot. What did you fix?

I made sure that the program doesn't send dimmers commands when the light is already set to the desired level. I was previously assuming that this was managed on devices drivers' end but I saw in my logs that it wasn't the case. I also brought some modifications in terms of reliability some days ago but I don't remember in details what it was about.
How has it been working for you so far?

Update 1: I made another update just after this one because I had forgotten to comment out some schedules meant for debug only. Feel free to just comment out the line #224 or simply copy paste the last version.

line 224: //runIn(10, mainloop) // DEBUG ONLY DON'T FORGET TO COMMENT OUT AFTER YOU'RE DONE TESTING THIS APP

Update 2:

line 432: //state.enablelogging = true // FOR DEBUG ONLY COMMENT OUT AFTER YOU'RE DONE TESTING THIS APP

Testing the changes out and getting the below errors.

I updated the code.

Couldn't reproduce the error the app is working fine on my end. Had to made a change due to the fact that in HE, contrary to ST for which this app was initially written, adjusting a dimmers level doesn't automatically turn on the device if it was previously turned off.

Can you send me a screen shot of the settings page, if you still have it installed? Also, I could use a list of the devices you have since it seems there's a returned value by one of your device that causes the problem. If I can find which one it is, then I can adapt the app's behavior.

Sorry just seen this. I here are some screen shots. I tried testing with just 2 lights. All the lights I’m trying to transition are hue lights integrated with hue b smart.

Thank you for your feedback. I still can't manage to reproduce the error but my guess is that (judging by the line number in the error message) you are still using the older version, which is my fault because I published it on two locations and I forgot to update my github's repository. I had only updated the one as a mere copy-paste post...

Let me know if it's working after updating your app's code in HE.

Here is the new submit:
elfege/eternalSunshine/blob/master/eternalSunshine.groovy

Yeh updated and getting the same error.

app:19532019-12-28 11:45:00.018 am errororg.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'null' with class 'null' to class 'int'. Try 'java.lang.Integer' instead on line 397 (mainloop)

app:19532019-12-28 11:44:00.053 am errororg.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'null' with class 'null' to class 'int'. Try 'java.lang.Integer' instead on line 397 (mainloop)

app:19532019-12-28 11:43:35.442 am errororg.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'null' with class 'null' to class 'int'. Try 'java.lang.Integer' instead on line 397