Virtual Solar Light Sensor [3.3.0;3.4.9)

This rule template works as a virtual light sensor, providing a software only approximation of a hardware outside light sensor.
It takes total sun radiation, as provided by the Astro binding, and corrects it for clouds with data provided by the by the Synop Analyzer binding or a weather binding. The resulting light intensity value in Lux updates an item that can be used to trigger outside light level dependent behaviour in other rules.

Language: javascript (ECMAScript 5.1 Nashorn)

A version for OH 4.0 for the JavaScript Scripting Add-on (ECMAScript 2022+ ES6) is available here

Dependencies

  • Total Radiation item: item representing total sun radiation in a location, as provided by the Astro binding.
  • Cloudiness item: item representing cloudiness. This can be an okta value as provided by the Synop Analyzer binding or a cloudiness percentage as provided by a weather binding.

Configuration

The rule template needs to be configured with 2 input and 1 or 2 output items.

Input:

  • Total Radiation: name of the item (Number) that represents the total (sum of direct and diffuse) sun radiation.
  • Cloudiness: name of the item (Number) that represents to okta value or cloudiness percentage. The okta value is a value between 0 and 8 (integer values) representing the level of cloudiness, with 0 a clear sky.
  • Percent: flag indicating if the cloudiness input is an okta value (percent = false), or a cloudiness percentage value (percent = true).

Output:

  • Lux: name of item (Number:Illuminance) that represents the total sun radiation in Lux without considering the cloud layer.
  • Weighted Lux: name of item (Number:Illuminance) that represents the sun radiation in Lux, considering the effect of the cloud layer.

One of the output items can be omitted if not relevant for your use case.

Changelog

Version 0.7

  • Use event data for items

Version 0.6

  • Fix for UNDEF inputs

Version 0.5

  • Added support for cloudiness percentage from weather bindings
  • Treat UNDEF inputs

Version 0.4

  • Converted to javascript and rule template

Version 0.3

  • Converted to jython

Version 0.2

  • DSL rule modified to use Okta from Synop Analyzer binding and Total Radiation from Astro binding

Version 0.1

Resources

A wider discussion and history can be found in the community thread.

https://raw.githubusercontent.com/mherwege/openhab-rule-templates/main/virtualLightSensor/virtualLightSensor.yaml

4 Likes

Thanks for posting. I could find this useful in my setup but most of the weather bindings provide cloud cover in a percentage instead of okta. It would be pretty cool if there were a flag to set and have the rule work with either measurement.

To convert percent to okta you just need to divide by 8 and round. There can be all sorts of argument about the proper way to round but for a home automation system just doing a normal round should be sufficient I would think.

var okta = items[OKTA];
if({{percent}} == true) {
    okta = Math.round(Number.parseInt(items[OKTA]) / 8);
}

Need to parse the state in case the Item is a Number:Dimensionless and the Item’s state is carrying units.

Thanks for the feedback Rich. I updated it with your suggestion, but using a mapping table rather than a division.

1 Like