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
Dependencies
JavaScript Scripting Add-on installed.
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 1.0
Adapted older version of rule template (developed for ECMAScript 5.1) to ECMAScript 2022+ (ES6), for use with JavaScript Scripting Add-on and OH4.0.
Version 0.4
Converted to JavaScript ECMA 5.1 (Nashorn) and rule template, available here.
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
I love how your version history is pretty much the same as most of my rule templates! First Rules DSL, then Python, then Nashorn and finally JS Scripting.
This is totally weird but I’m not seeing this in my list of rule templates to install, even when I toggle “show unpublished” for the community marketplace. Your version string looks fine and I see no other reason why it wouldn’t be listed.
I’m on a 4.1 snapshot from a week or so ago (upgrade to the latest is in process). Can someone confirm whether it’s just me or if this is a wider problem?
That’s definitely part of it. I just removed my Presence Simulation rule template that uses the exact same versioning as above. I need to experiment to figure out if our version string is wrong or if there is a bug that needs to be filed. I’ll come back with my findings.
I don’t think this is a problem with 4.0.x releases, only 4.1. Thanks for confirming.
I think the current snapshot is borked. Errors everywhere from Zigbee. I’m going to go back to 4.1 M1 and will report back when I see what’s going on there.
I figured it out.
The version numbers are not working because snapshots and milestones have third and fourth level version numbers. [4.0.0.0;4.1.0.0) is excluding the snapshots and milestones because I think it means 4.0.0.0 <= x < 4.1.0.0 and 4.1 M1 is greater than 4.1.0.0.
I’ve been able to make Presence Simulation show back up using [4.0.0.0;4.9.9.9]. I’m sure other ways that will work. That’s just the first one I happened upon. I’ll continue to experiment a bit but it looks like the fix is to change the version ranges in the titles.
After experimenting some I’ll update all my titles and you can use those as a tempalte.
It should. I’m experimenting with [4.0;4.9][4.0.0.0;4.9.9.9] to basically catch all OH 4 versions (assuming we don’t go above 4.9). That way I don’t have to remember to update it when a new release is made. But I’m finding a weird refresh issue with the list. I don’t think OH hits the forum every time you reload the page making it hard to test.
I’ve been running it in 5 without errors. I can’t promise it’s actually working as I’ve not looked to ensure it it but it’s not throwing errors anyway.
You can go to Settings → Community Marketplace and toggle on “Show Unpublished” and you’ll see this in the list of add-ons you can install. Try it out and let us know if it works and then we can see about updating the version range.
I expect it to work, but didn’t test yet. I just enhanced the version range, so it should become visible for OH 5. If you are testing this on 0H 5, let us know if you found any issues.