Help with JavaScript rule to compare luminance

Hi Matthias

Thanks for your explanation. My reading of " Units of Measurement / Quantity Handling" at the link below led me to believe I was working with two quantity items but I have obviously misunderstood:

The updated rule below uses the methods .lessThan and .greaterThan and this now seems to be working. Maybe my use of the > < operators wasn’t correct :thinking:

		var reportedLuminance = items.getItem("Sensor2_luminance").quantityState;
		var thresholdLuminance = Quantity('300 lx');

		if (reportedLuminance.lessThan(thresholdLuminance)) {
			console.log (`RULE: Master Bathroom Heat Lamp Is On | Luminance value [${reportedLuminance}] is less than threshold: [${thresholdLuminance}]`);
		}
		else if (reportedLuminance.greaterThanOrEqual(thresholdLuminance)) {
			console.log (`RULE: Master Bathroom Heat Lamp Is On | Luminance value [${reportedLuminance}] exceeds threshold: [${thresholdLuminance}]`);
			//
		}

Thanks again for your help.

1 Like