averageSince(now.minusMinutes) in rule not working

Does anybody have an idea why the second part of my rule is not working when the lux value reaches 65535?

As long as the lux value is above 40000, the rule works fine. It also works fine when it drops below 40000.
But as soon as the lux meter reaches its maximum of 65535 constantly, the wrong part of the rule is fired …

items:

Number ESP8266_Four_Lux "Lux [%.2f lx]" (gInfluxdb) { mqtt="<[mosquitto:/esp8266four/light/intensity:state:default]" }
Number ESP8266_Four_Lux_AVG "Lux avg [%.0f lx]" // only for displaying lux average on sitemap

rule:

val Number LuxHysteresis = 5 //in minutes
val Number SunDetectLuxTop = 40000

rule "sun lux roof detection"
when
	Item ESP8266_Four_Lux received update
then
	var Number Lux_four_avg = ESP8266_Four_Lux.averageSince(now.minusMinutes(5))
	ESP8266_Four_Lux_AVG.postUpdate(Lux_four_avg)
	if (Lux_four_avg > SunDetectLuxTop) {
		ShutterLuxTopDetected_Proxy.sendCommand(ON)
		logInfo("SHUTTER", "lux top shutter high detected, Lux avg = "+ESP8266_Four_Lux_AVG.state)
	}
	else if (Lux_four_avg <= SunDetectLuxTop) {
		ShutterLuxTopDetected_Proxy.sendCommand(OFF)
		logInfo("SHUTTER", "lux top shutter low detected, Lux avg = "+ESP8266_Four_Lux_AVG.state)
	}
end

log:

2017-04-17 09:30:44.320 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 64153.73706462422
2017-04-17 09:31:48.570 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 65535.0
2017-04-17 09:32:53.610 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0

That does sound like a behaviour at end of the possible values of the variable. Although I’may not sure what those values would be for the number type.

Thought about that too but haven’t found any info on the range …

I am not common with xtend, and also googled now for 15 minutes but cant find any infos on that. It sounds like your if does a 16bit compare in memory and so just have the 16LSB in memory from your origin value. But i cant believe, number sounds something more flexible like in js.

May you log the “Lux_four_avg” value as an additional info to your current logs. Maybe the *.averageSince() does something strange.

What is the max value from “ESP8266_Four_Lux.state”?

Already did that, can’t find anything strange except the weird behaviour on value 65535:

	Line 10782: 2017-04-17 10:23:51.725 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 15657.81287026009
	Line 10794: 2017-04-17 10:24:56.782 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 15657.81287026009
	Line 10802: 2017-04-17 10:26:01.920 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 20207.04031402952
	Line 10822: 2017-04-17 10:27:06.907 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 22270.51785933826
	Line 10834: 2017-04-17 10:28:11.983 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 23079.23563898451
	Line 10842: 2017-04-17 10:29:17.055 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 22684.69070358902
	Line 10858: 2017-04-17 10:30:22.941 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 21688.01453585229
	Line 10878: 2017-04-17 10:31:27.224 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 21315.05438419255
	Line 10890: 2017-04-17 10:32:32.248 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 21315.05438419255
	Line 10902: 2017-04-17 10:33:37.853 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 30723.35901574607
	Line 10914: 2017-04-17 10:34:42.905 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 42036.50942902748
	Line 10926: 2017-04-17 10:35:47.979 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 42036.50942902748
	Line 10946: 2017-04-17 10:36:53.050 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 61625.42112547540
	Line 10954: 2017-04-17 10:37:58.096 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 65535.0
	Line 10962: 2017-04-17 10:39:03.167 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 10970: 2017-04-17 10:40:08.248 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 39262.5
	Line 10978: 2017-04-17 10:41:13.317 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 45489.40175834812
	Line 10998: 2017-04-17 10:42:19.210 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 52229.07423699941
	Line 11006: 2017-04-17 10:43:23.431 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 55512.03993445747
	Line 11014: 2017-04-17 10:44:28.507 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 50848.33297412965
	Line 11022: 2017-04-17 10:45:33.583 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 45650.83009423416
	Line 11042: 2017-04-17 10:46:39.469 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 32117.31134776136
	Line 11050: 2017-04-17 10:47:44.531 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 39024.05956594920
	Line 11062: 2017-04-17 10:48:49.581 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 41482.49901382937
	Line 11070: 2017-04-17 10:49:54.643 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 44569.21011431745
	Line 11082: 2017-04-17 10:50:59.718 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 49788.87202168284
	Line 11098: 2017-04-17 10:52:04.800 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 51459.29921135828
	Line 11110: 2017-04-17 10:53:09.858 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 55619.19132646201
	Line 11126: 2017-04-17 10:54:15.746 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 55619.19132646201
	Line 11138: 2017-04-17 10:55:19.965 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 51822.93302123834
	Line 11158: 2017-04-17 10:56:25.031 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 50191.64792098075
	Line 11170: 2017-04-17 10:57:30.156 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 53210.58219058298
	Line 11182: 2017-04-17 10:58:35.184 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 56300.60450766758
	Line 11194: 2017-04-17 10:59:40.234 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 62416.95525197655
	Line 11210: 2017-04-17 11:00:45.336 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 65535.0
	Line 11226: 2017-04-17 11:01:50.370 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11234: 2017-04-17 11:02:55.439 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11242: 2017-04-17 11:04:00.487 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11254: 2017-04-17 11:05:05.562 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11266: 2017-04-17 11:06:11.455 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11282: 2017-04-17 11:07:15.708 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11294: 2017-04-17 11:08:20.754 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11306: 2017-04-17 11:09:25.835 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11314: 2017-04-17 11:10:30.937 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11334: 2017-04-17 11:11:35.945 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11350: 2017-04-17 11:12:41.026 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11358: 2017-04-17 11:13:46.086 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11366: 2017-04-17 11:14:51.159 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11378: 2017-04-17 11:15:56.214 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 35086.0
	Line 11394: 2017-04-17 11:17:01.308 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 29668.83129522376
	Line 11406: 2017-04-17 11:18:07.189 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 24877.80685764996
	Line 11418: 2017-04-17 11:19:11.421 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 21267.32302107144
	Line 11430: 2017-04-17 11:20:16.492 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 14375.41483386669
	Line 11438: 2017-04-17 11:21:21.556 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 10009.69681760383
	Line 11458: 2017-04-17 11:22:26.606 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 8078.653044352974
	Line 11466: 2017-04-17 11:23:31.678 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 7862.606327027692
	Line 11478: 2017-04-17 11:24:36.742 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 8666.978895099791
	Line 11490: 2017-04-17 11:25:41.809 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 9893.458455793368
	Line 11506: 2017-04-17 11:26:46.904 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 11228.18548687592
	Line 11518: 2017-04-17 11:27:52.045 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 12892.63515252063
	Line 11530: 2017-04-17 11:28:57.017 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 17456.18304380897
	Line 11542: 2017-04-17 11:30:02.921 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 23190.99879567900
	Line 11554: 2017-04-17 11:31:07.169 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 23190.99879567900
	Line 11570: 2017-04-17 11:32:12.243 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 30998.26277396102
	Line 11578: 2017-04-17 11:33:17.299 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 31754.35229101917
	Line 11590: 2017-04-17 11:34:22.898 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 29802.54760549513
	Line 11602: 2017-04-17 11:35:27.967 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 33298.00124606531
	Line 11626: 2017-04-17 11:36:33.013 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 41918.71489588485
	Line 11638: 2017-04-17 11:37:38.070 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 50276.34142441972
	Line 11650: 2017-04-17 11:38:43.166 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 45327.51473051362
	Line 11658: 2017-04-17 11:39:48.219 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 39963.15618649179
	Line 11666: 2017-04-17 11:40:53.308 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 31802.63432113559
	Line 11686: 2017-04-17 11:41:59.186 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 43136.10770117463
	Line 11698: 2017-04-17 11:43:03.413 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 48663.24456183488
	Line 11706: 2017-04-17 11:44:08.496 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 59546.92342887437
	Line 11714: 2017-04-17 11:45:13.547 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 65535.0
	Line 11728: 2017-04-17 11:46:18.610 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11748: 2017-04-17 11:47:23.662 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11764: 2017-04-17 11:48:28.739 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11772: 2017-04-17 11:49:33.808 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11784: 2017-04-17 11:50:38.908 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11804: 2017-04-17 11:51:43.949 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11812: 2017-04-17 11:52:49.001 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11824: 2017-04-17 11:53:54.894 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11836: 2017-04-17 11:54:59.138 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11848: 2017-04-17 11:56:04.229 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11868: 2017-04-17 11:57:09.264 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11876: 2017-04-17 11:58:14.344 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11888: 2017-04-17 11:59:20.237 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 11900: 2017-04-17 12:00:24.471 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 28999.23763011331
	Line 11916: 2017-04-17 12:01:29.565 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 24238.38887295523
	Line 11928: 2017-04-17 12:02:34.613 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 20803.83636960856
	Line 11940: 2017-04-17 12:03:39.687 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 13681.66169080413
	Line 11952: 2017-04-17 12:04:44.736 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 10184.48114852976
	Line 11968: 2017-04-17 12:05:50.636 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 8582.056010860948
	Line 11984: 2017-04-17 12:06:54.869 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 8414.225457730517
	Line 11996: 2017-04-17 12:07:59.909 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 9393.700622442511
	Line 12008: 2017-04-17 12:09:05.016 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 11183.34403585135
	Line 12016: 2017-04-17 12:10:10.080 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 13359.06361198136
	Line 12028: 2017-04-17 12:11:15.141 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 15814.78313683458
	Line 12052: 2017-04-17 12:12:20.250 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 15814.78313683458
	Line 12064: 2017-04-17 12:13:25.250 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 21296.16358233382
	Line 12076: 2017-04-17 12:14:30.643 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 21296.16358233382
	Line 12088: 2017-04-17 12:15:35.734 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 26780.72777952563
	Line 12108: 2017-04-17 12:16:40.793 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 30562.65767924637
	Line 12124: 2017-04-17 12:17:46.675 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 34707.55759779079
	Line 12136: 2017-04-17 12:18:50.910 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 38849.36891178572
	Line 12144: 2017-04-17 12:19:55.991 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 44863.35924377819
	Line 12156: 2017-04-17 12:21:01.119 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 49043.31189799524
	Line 12176: 2017-04-17 12:22:06.201 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 52130.91449892897
	Line 12184: 2017-04-17 12:23:11.248 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 57450.45706604190
	Line 12196: 2017-04-17 12:24:16.319 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 60044.96702448392
	Line 12208: 2017-04-17 12:25:21.391 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 62790.90066001275
	Line 12228: 2017-04-17 12:26:26.450 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 65535.0
	Line 12240: 2017-04-17 12:27:31.524 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 12248: 2017-04-17 12:28:36.569 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 12260: 2017-04-17 12:29:42.527 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 12276: 2017-04-17 12:30:46.710 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 12296: 2017-04-17 12:31:51.768 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 12308: 2017-04-17 12:32:56.854 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 65535.0
	Line 12316: 2017-04-17 12:34:01.926 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 35788.0
	Line 12328: 2017-04-17 12:35:06.988 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 31897.86419999693
	Line 12340: 2017-04-17 12:36:12.041 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 28203.41514614431
	Line 12360: 2017-04-17 12:37:17.114 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 25394.65188385307
	Line 12372: 2017-04-17 12:38:22.173 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 20176.85174036651
	Line 12380: 2017-04-17 12:39:27.275 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 16497.64239317487
	Line 12388: 2017-04-17 12:40:32.366 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 14396.57885993686
	Line 12408: 2017-04-17 12:41:37.437 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 13313.20095403429
	Line 12420: 2017-04-17 12:42:42.472 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 12910.42183430771
	Line 12432: 2017-04-17 12:43:47.550 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 12992.69488436231
	Line 12440: 2017-04-17 12:44:52.611 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 13269.24468775812
	Line 12452: 2017-04-17 12:45:59.053 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 13497.78410993144
	Line 12464: 2017-04-17 12:47:02.757 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 13806.05812573229
	Line 12476: 2017-04-17 12:48:07.825 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 13806.05812573229

@sihui: Try a division by 10 and set

val Number SunDetectLuxTop = 4000
var Number Lux_four_avg = ESP8266_Four_Lux.averageSince(now.minusMinutes(5)) / 10

Give it a try and still want to know possible max value from your sensor.

Upps, missed that one:

Wide range and High resolution. ( 1 - 65535 lx )

https://www.dfrobot.com/wiki/index.php/Light_Sensor_(SKU:SEN0097)

Will try … sun is not shining at the moment :heart_eyes:

Did that, lux meter is constantly to 65535 since four minutes (sun is shining again),

lux average is

Line 12708: 2017-04-17 13:10:54.177 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 0.00000000
Line 12728: 2017-04-17 13:11:59.251 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 0.00000000
Line 12736: 2017-04-17 13:13:04.309 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 0.00000000
Line 12744: 2017-04-17 13:14:09.394 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 0.00000000

Xtend is kidding us :anguished:


https://eclipse.org/xtend/documentation/203_xtend_expressions.html#if-expression

A floating-point literal creates a double (suffix D or none), a float (suffix F) or a BigDecimal (suffix BD). If you use a . you have to specify both, the integral and the fractional part of the mantissa. There are only decimal floating-point literals.

42d // double
0.42e2 // implicit double
0.42e2f // float
4.2f // float
0.123_456_789_123_456_789_123_456_789e2000bd // BigDecimal

Appreciate your help!

What does that mean for my rule? I have no idea how to implement your suggestion :joy:

Try it this way without declaration of type.

val SunDetectLuxTop = 4000d
val Lux_four_avg = ESP8266_Four_Lux.averageSince(now.minusMinutes(5)) / 10d

Hope this is working otherwise i think im just waisting your time.

Not at all :grinning:

One question: Why you have a else if part, it should make no diffrence but a else without expression should do the same and looks more friendly.

if (Lux_four_avg > SunDetectLuxTop) {
		ShutterLuxTopDetected_Proxy.sendCommand(ON)
		logInfo("SHUTTER", "lux top shutter high detected, Lux avg = "+ESP8266_Four_Lux_AVG.state)
	}
	else {
		ShutterLuxTopDetected_Proxy.sendCommand(OFF)
		logInfo("SHUTTER", "lux top shutter low detected, Lux avg = "+ESP8266_Four_Lux_AVG.state)
	}

Thx, will try both, have to wait for sunshine again …

Okay, did both suggestions, as soon as the high level is reached for the second time, lux_four_avg drops to zero.
ESP8266_Four_Lux was constantly on 65535 the last 5 minutes …
Any more ideas?

	Line 13654: 2017-04-17 14:18:43.898 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 6546.90263078
	Line 13658: 2017-04-17 14:18:54.728 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter high detected, Lux avg = 6547.15322442
	Line 13666: 2017-04-17 14:19:24.415 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 0.00000000
	Line 13674: 2017-04-17 14:19:34.968 [INFO ] [lipse.smarthome.model.script.SHUTTER] - lux top shutter low detected, Lux avg = 0.00000000

I do not trust this *.averageSince() methode. Or something is wrong within persistence.

What you are getting if you do a request like this in your browser…
http://<openhabip>:8080/rest/persistence/items/ESP8266_Four_Lux?starttime=<time_since_sensor_reports_max>

Note: <openhabip> is your host and <time_since_sensor_reports_max> should be something like
2017-04-17T14%3A35%3A00.000Z (info ‘:’ need to be url encoded => %3A)

You also can check your database or persistence service.

If you do persistense on every change for your sensor item there would be no entry in database when it has reached the max value and keeps the same value for a long time. If you than calculate an average over last 5 minutes there are no values for that timespan in database and you will get a zero.

I suspect this is your problem. Sry it tokes me that long to figure it out.

Of course you can undo the division by 10. Excuse for the misleading.

1 Like

Yes, I do!
Sounds all very logical and the rule is actually working as expected, although not the way it was intended.
Have now persisted my Lux item for every minute and have to wait again … it’s raining.

No reason to excuse for anything :grinning:
Will report back when the sun is shining again …

I shortened this a bit and published the max value manually to my lux item:
everything is working as expected, problem was - as usually - between my ears. If you want to call any “since minutes” stuff from persistence, you have to persist that item everyMinute. :sunglasses:

@CodingHarry, thanks for not giving up on me!

2 Likes