HowTo: Use Philips Hue sensors (Motion Sensor / Dimmer Switch)

Tags: #<Tag:0x00007faecce8d370> #<Tag:0x00007faecce8d230>

Where exactly? :thinking:

Right at the beginning. It should be cancelled every time we will go back into the room. But do not forget to check for null in advance.

Like this?

var Timer timer = null

rule "Flur Motion Sensor ON" 
when 
    Item Flur_MotionSensorPresence changed from OFF to ON
then
    if(timer === null || timer.hasTerminated) {
        timer.cancel
        timer = null
        FlurSchalter.sendCommand(ON)
        logInfo("Motion Flur", "Bewegung erkannt -> Licht an")
    }
    else {
        timer.cancel
        timer = null
        logInfo("Motion Flur", "Bewegung erkannt -> Timer gelöscht")
    }
end

rule "Flur Motion Sensor OFF"
when
    Item Flur_MotionSensorPresence changed from ON to OFF
then
    logInfo("Motion Flur", "Keine Bewegung mehr erkannt -> Timer gestartet")
    timer = createTimer(now.plusSeconds(10), [ |
        timer.cancel
        timer = null
        FlurSchalter.sendCommand(OFF)
        logInfo("Motion Flur", "Timer abgelaufen -> Licht aus")
    ])
end

Maybe it is sufficient to cancel the timer only in the else branch.

1 Like

Yes, it make sense.

Another question, what is the advantage of using Hue groups? (now I’m using groups openHAB)

Short version:

  • We need them to support the new luminaires. They combine more than one controllable light in one device.
  • The number of commands are restricted to 10 per seconds. If you have more than 10 lights in a group you will see artifacts when you try to control them.

Have a look here or here for detailed examples.

2 Likes

in openhab i have added 10 hue motion sensors . so now i have all my hue motion sensors with the right name but for the temperature sensors i cant tell which temperature sensor belong to hue sensor . they are all in the Hue temperature sensor 1 or Hue temperature sensor 2 until Hue temperature sensor 1 10.
how to tell which temperature sensor belong to a room motion sensor?

thanks

@uddup1976 Can you check the output of the API if you navigate to http://<bridge ip address>/api/<username>/sensors in your browser? Maybe we can find a property which will relate the different sensors.

Otherwise keep in mind that every Philips Hue Motion sensor owns three different IDs - one for each sensor part - and they are - most of the time - increased by one during creation. Meaning if the ID of your ZLLTemperature is 10, the IDs of
the related ZLLPresence and ZLLLightLevel are 11 and 12.

Hey,
just another question.
Working with the Hue motion sensors is very nice. But now I tried to use the illuminance sensor. I added the following if-condition after the “then” in my rule above:

rule "Flur Motion Sensor ON" 
when 
    Item Flur_MotionSensorPresence changed from OFF to ON
then
    if (Flur_Illuminance.state > 30 && FlurSchalter.state == OFF) {
        return false
    }
    if(timerFlur === null || timerFlur.hasTerminated) {
        timerFlur = null
        FlurSchalter.sendCommand(ON)
        logInfo("Motion Flur", "Bewegung erkannt -> Licht an")
    }
    else {
        timerFlur.cancel
        timerFlur = null
        logInfo("Motion Flur", "Bewegung erkannt -> Timer gelöscht")
    }
end

This is working, if I walk into the room. But when I leave the room and come back after the lights turned off, the lights won’t turn on again.

Any idea how I can solve this?

You can add some logging before the return statement to see what state the tested items have at that moment…

Thank’s for your answer and sorry for my late reply - I missed the notification e-mail.

I added

logInfo("Motion Flur", "Item 'Flur_Illuminance': "+Flur_Illuminance.state.toString)

And my openhab log is:

2019-02-17 17:51:54.900 [INFO ] [e.smarthome.model.script.Motion Flur] - Item 'Flur_Illuminance': 0.9997697679981565
2019-02-17 17:51:54.901 [INFO ] [e.smarthome.model.script.Motion Flur] - Bewegung erkannt -> Licht an
2019-02-17 17:51:59.752 [vent.ItemStateChangedEvent] - Flur_Illuminance changed from 0.9997697679981565 to 36.70286784810968
2019-02-17 17:52:18.735 [INFO ] [e.smarthome.model.script.Motion Flur] - Timer abgelaufen -> Licht aus
2019-02-17 17:52:26.031 [INFO ] [e.smarthome.model.script.Motion Flur] - Item 'Flur_Illuminance': 36.70286784810968
2019-02-17 17:52:26.306 [vent.ItemStateChangedEvent] - Flur_Illuminance changed from 36.70286784810968 to 0.9997697679981565

The problem is, that the Item “Flur_Illuminance” received an update after the motion Item.
I can use a short timer (300 milliseconds?) and check the item again.

Do you have another idea to solve my problem?

What polling rate have you set in the binding? A delay would be a ‘last resort’, since the timing may vary.

Btw, from my experience the Hue motion sensor sends an OFF signal after about 15 seconds. With the 10 seconds timer, that should result in the 24 seconds in the log file. Did you observe that behavior as well?

What does your complete rule set look like now?

My polling rate is 250ms for the sensors and 5seconds for everything else.

My actual rule is:


rule "Flur Motion Sensor ON" 
when 
    Item Flur_MotionSensorPresence changed from OFF to ON
then
    logInfo("Motion Flur", "Item 'Flur_Illuminance': "+Flur_Illuminance.state.toString)
    if (Flur_Illuminance.state > 25 && FlurSchalter.state == OFF) {
        Thread::sleep(300) // Warten bis Flur_Illuminance aktualisiert wurde
            if (Flur_Illuminance.state > 25 && FlurSchalter.state == OFF) {
                return false 
            }
    }
    
    if((timerFlur === null || timerFlur.hasTerminated) && FlurSchalter.state == ON) {
        logInfo("Motion Flur", "Licht war schon an")
        return false
    }

    motionFlur = true

    if(timerFlur === null || timerFlur.hasTerminated) {
        timerFlur = null
        FlurHelligkeit.sendCommand(60)
        FlurFarbtemperatur.sendCommand(60)
        FlurSchalter.sendCommand(ON)
        logInfo("Motion Flur", "Bewegung erkannt -> Licht an")
    }
    else {
        timerFlur.cancel
        timerFlur = null
        logInfo("Motion Flur", "Bewegung erkannt -> Timer gelöscht")
    }
end

rule "Flur Motion Sensor OFF"
when
    Item Flur_MotionSensorPresence changed from ON to OFF
then

    if (motionFlur == true) {
        logInfo("Motion Flur", "Keine Bewegung mehr erkannt -> Timer gestartet")
        timerFlur = createTimer(now.plusSeconds(10), [ |
            timerFlur.cancel
            timerFlur = null
            motionFlur = null 
            FlurSchalter.sendCommand(OFF)
            logInfo("Motion Flur", "Timer abgelaufen -> Licht aus")
        ])
    }
    else {
        logInfo("Motion Flur", "Licht nicht ausschalten, da nicht über Motion Sensor eingeschaltet")
    }
end

With this rule it is working fine, but maybe there is a better solution.

Yes.

Hi Sebastian13,

In your most recent rules in this post, what is:

Is it an Item, or is it a declared var(iable) in your .rules file?

Thanks! :slight_smile:

Hi Alan,
sorry for my late response, I missed the e-mail notification.

“motionFlur” is only a variable in my rule file.