Outdoor illuminance based on sun elevation and weather conditions


I have just found this Home Assistant script what calculates outdoor illuminance based on either sun elevation and current weather conditions obtained from Openweathermap. For me it would be useful to adopt it to OH because I am thinking about to schedule my blinds based illuminance.

What do you think, would it be possible to adopt it to OH?

1 Like

Seems simple enough to implement even just as a rule.

in the market place there is a rule for this
I’ll see if I can find it and post a link… yep… here…

1 Like

I’m using the timelinepicker in v3 with integration of sunrise and sunset. The only dependency is the astro binding and for me it’s working with blinds and lights perfectly for over a year.

Here a example of use:

In the first picture you can see:
For monday to friday the light is

  • from 9.00am to 9.15am switch ON if no sun
  • from 9.15am to 10.30am switch OFF if sun
  • 10.30am switch OFF
  • from 3.15pm to 6.00pm swich ON if no sun
  • 6.00pm switch OFF

In the second picture is the manuell correction values for sunrise, sunset and the checkbos for activation of sunevents.

The not includet correction for clouds is not a real problem and it’s one less depandancy.


Thank you I installed it. I will see tomorrow if it works, now it is already dark. :slight_smile:

I have an actual light sensor pointed out the kitchen window. The lighting in my flat adjusts up and down during the day based on the amount of real light coming through the windows.
I tried the virtual solar light sensor rule just to see how accurate it was. I used cloudiness as reported by the open weather map binding to weight the rule. Overall the virtual sensor reported much higher values then the real sensor but still accurately report approximate outside light. With some adjustment to the scale it could be made to work to adjust the lighting although not so much in real time, more in general (as in dawn —> midday —> dusk)

Thank you Andrew. The sript is really interesting as an experiment, but I am also not fully satisfied with that. What kind of sensor do you use? I am also considering to build or buy something.
Cheap light sensors are usually only for indoor usage, and I guess most of them send data only if they detect some motion. However your idea to put that to the window is smart. :smiley: I already have some wireless Z-wave devices but z-wave usually bit more expensive then other devices. :thinking:

I found the same… the Hue motion sensors worked fine in this role but needed batteries every six months because I had them set to report every 5 minutes. Cheapest mains powered sensor I could find was $70 (zwave)
So I built one myself from a esp3266 ($3) and this sensor (at the time $3 now $5 or 6) It plugs into the wall (never needs batteries) and reports every 30 seconds
With this set up the lighting in my flat adjusts in (almost) real time. Sun goes behind a cloud, lighting comes up, sun pops back out, lighting goes down. It is really cool and so sutle, you hardly notice

Thank you for the info. I also have some MySensors devices. So you found this TSL2561 Luminosity Sensor reliable. Good to know! Thanks. :+1:

yes, beyond reliable, it has been running at least two or three years now. It also reports in Lux and seems well calibrated. Only problem is when I checked yesterday to figure out which sensor I used, it looks like it might be out of stock on Adafruit website or possibly discontinued but still available on Amazon. The TSL2591 looks like an updated version of the same sensor

Just to bring up an alternative idea, I built myself a simple sunshine sensor with two temperature sensors. One is placed in direct sunlight (when the sun is up), the other is in the shade. By analysing the difference you get very reliable data to detect if the sun is shining:

On the screenshot you can see the data of both sensors and the temperature difference. The blue areas are the times when my OH logic determined that the sun is currently shining.


Another smart and simple idea. :+1: Nevertheless, I would like to control blinds based on illuminance what also changes when no sun or time is after sunset.

Is that enough sensitive to measure changes even after sunset? I mean I don’t want to measure illuminance during night but around sunset.

The sensor actually has a dynamic range that automatically switches between three ranges (I think) So it is very accurate in bright sunlight during the day but also remains accurate at much lower light level as dusk approaches. However, pointed out the window, once it is completely dark outside, it kind of goes back and forth between 2 and Nan. (maybe a car drives by with the headlights on) My rules have a ‘but only if’ clause that sets the Item to 0 if the sensor reports anything lower then 3 (just because Nan looks stupid in the user interface :wink:)
During the day, here in Florida USA, on a cloudless sunny day it can reach as high as 15,000 - 16,000 Lux. My lighting pretty much turns off at anything over 10,000 Lux because the flat is fully lit by the outside sunlight. As sunset approaches, it gets down to around 1200 - 1000 Lux. Once the sun drops below the horizon (sunset) it reports around 900. By the end of Civil dusk (about 20 minutes later) it is < 5
You can also use the Astro binding Sun phase channel, which is a string and reports NIGHT and DAYLIGHT (amongst other things) to discern if it is night time.
When the sensor is reporting anything below about 400 - 200, it is pretty much dark outside although on a really stormy cloudy day it can get below 1000. It’s very accurate, it’s practically a scientific instrument. My Hue motion sensors don’t have anywhere near the range or fidelity

So, I have anoher solution. We have kitchen windows directly to south and during winter time sun is too low and during lunch time is directly to persons, which are sitting at desk.
My solution, I bought internal sun stop blinds, I have built motorization based on DC motor with encoder and ESP32.
Based on elevation and daytime ( something like 11:30-13:30 ) I calculate simple perpendicular rectangle based on distance of desk corner from window and elevation, output is height of opened part of window, which is mapped to open percentage of window, which is sent to controller.
Regarding sun detection, I have solar panel (rated to 21V ) which charges batteries on outdoor blinds in first floor and in my case, if voltage is bellow 17V I assume that is cloudy and blinds are fully opened. Voltage level was decided based on analysis and real behavior, so is definitively specific for my usecase.
Rule is executed every minute (mostly to recalculate sunlight)
Works like perfect and all users are satisfied, we have maximum of day light and nobody needs to close eyes during lunch.

@Vaclav_Bittmann I’ve wanted to do something like this. Can you share anything about your design? Components you used, software or sketches used to run the esp, circuit schematics, etc?

I know there are retail products to do this, but I have ethernet poe ports next to the windows and am hoping to someday power my window shades with that.

I will try to collect and publish something, so design for blinds are based on ESP-32, DRV-8872 drivers, JGA-25 Chinese motors, As it was learning project, its definitively quite dirty than clean projects.

Rule script (js) which control percentage of shades. It contains also recalculation from distance to percentage thru spiral length (formula I found somewhere on internet, but I haven’t bookmark.

Rule java script :

// distance of zero level from courtain  [cm] (table corner from window glass)
var dist=180;
// max height of courtain from desk level [cm]  means dimmer=0
var maxLevel=150;   
// min height of courtain from desk level  [cm] means dimmer=100%
var minLevel=55;
// measured  thickenss of blind itself  [cm]  can be used to tune precision
var thickness=0.06;
// diameter of axis when we are on 100% down 
var axisDiam=2.3;
// spolar power, which is understood as full sun
var solarTreshold=18000.0;
// full lenght of shade 
var fullLen=100;
// amount rotations of roller to extend from 0 to 100% 
var fullRotations=10.5;
// read astro value with current angle
var currentAngle=parseFloat(items.getItem("AstroSunData_Elevation").state);
// var currentAngle=32;
var solarPower=parseFloat(items.getItem("RollerCNC_Solar").state);
console.log("Current Solar power is ",solarPower );
console.log("Current anle is [deg] ",currentAngle );
var angleRad=0.0174532925*currentAngle;
console.log("Current anle is [rad] ",angleRad );
var targetLen=Math.tan(angleRad)*dist;
console.log("Target Len is ",targetLen );
// expected rollout counted from fully open state
var newPos=fullLen-(maxLevel-targetLen);
console.log("New Pos is ",newPos );
// new rotation position from top (means from max rotations)
var odm=Math.pow((axisDiam-thickness),2)+(4.0*thickness*newPos)/3.14159 ;
// var odm=(axisDiam-thickness)*(axisDiam-thickness) ;
// console.log("Odmocnina", odm );
var newRot=(thickness-axisDiam+Math.sqrt(Math.pow(axisDiam-thickness,2)+(4*thickness*newPos)/3.14159))/2/thickness;
console.log("Final rotations ",newRot );
var targetProc=(fullRotations-newRot)/ullRotations*100;
console.log("Target Proc is  ",targetProc );
console.log("Target Proc fin is  ",Math.round(targetProc) );
console.log("Window operation finished");

Thanks for the code, @Vaclav_Bittmann. I’d be super interested in how the components are all wired together (circuit diagrams and such) as well as how it’s connected to the actual blind to move it. I would love anything you’re willing to share.

In my opinion, don’t worry about it being “dirty”. Every project is revision 1 unless you do it again. But why do it again if it’s good enough?

Hi, I created github repo with HW component and Sketch Repo