Philips Hue Motion Sensor Rule using motion & lux on OH3 & ECMA

hi all

I would have the following rule on my oh3 working (partially done, some issues)


  • Hue motion sensor connected to oh3 using deconz (added through UI)
  • some bulbs connected to oh3 (using hue bridge)

what I want to do is following:

  • Light should go on after motion is detected (done)
  • Light should go off 60 seconds after no motion ist detected (done)
  • there should be a possibility to disable the sensor and turn light on by switch (done)
  • Depending on the time of day there should be another light intensity and temperature (done using two rules)
  • During the day (rule 1) the light should only go on if there’s not sufficient light (lux) measured using the illuminance sensor (on the hue motion sensor)
    → my issue here’s the fact that I don’t really know how the illuminance is measured …thin in lux but what range?
    → the other thing is the refreshing cycle on this sensor …it seems that it’s not refreshing really often :frowning:

Here’s my script till now…

//var Log = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);
//"--- Bewegungsmelder Eingang ---");

this.myTimer = (this.myTimer===undefined) ? null : this.myTimer;
var illuminance = ir.getItem('BeleuchtungsstarkeEingang_Illuminance');
var lampeEingang = ir.getItem('Lampe_Eingang');
var sensorEnabled = ir.getItem('SensorEnabledEingang');
var illValue = illuminance.getStateAs(DecimalType.class);
var lampeEingangValue = lampeEingang.getStateAs(DecimalType.class);
//"illuminance Value " + illValue);
//"LampeEingang Value " + lampeEingangValue);

if(((illValue < 100) || (lampeEingangValue > 0)) && (sensorEnabled.getState() == 'ON')){
//"Wert erreicht...");

  events.sendCommand(lampeEingang, 100);

  var ScriptExecution = Java.type("org.openhab.core.model.script.actions.ScriptExecution");
  var ZonedDateTime   = Java.type("java.time.ZonedDateTime");
  if(this.myTimer !== undefined && this.myTimer !== null){
    this.myTimer = null;
  this.myTimer = ScriptExecution.createTimer(, function(){
    if(sensorEnabled.getState() == 'ON'){
      events.sendCommand(lampeEingang, 0);
    this.myTimer = null;
//"Wert nicht erreicht...");

with some logging stuff disabled at the moment

any hints how to deal with my issues?


Assuming that you’ve been running for a few days and have the default persistence set up, you should already have the data necessary to chart the light level readings from the sensor. You should be able to look at the chart and use your memory of how bright the day was (or how bright it is now) and come up with a threshold value that makes sense.

Ultimately knowing the units is less useful to you than just looking at how bright the room is now and what value the sensor is returning and going off of that.

If it’s battery powered that’s to be expected. There probably isn’t anything you can do about it.

thank you …there’s an option on the thing where the polling may be specified. Is that something that I may use or will that drain the battery if set to some minutes?

The faster the polling the faster the battery will drain. You can strike a balance and decrease the polling period but to get anything like one or two minute report times will likely drain the battery way faster. Keep in mind that going from once every 10 minutes to once every 5 minutes essentially doubles the amount of battery used.

Hold hard there … you cannot poll a sleeping battery device from openHAB.
You’d need to set a periodic “wakeup and report” inside the device,or more usefully “report when changed by a certain amount”. I don’t know what that’s called in device options.

ok …but what is this function on the thing for? Is it something that the deconz binding is implementing for fuse powered devices and also shown on battery driven things?

Well, yes.