HUE Motion Sensor + Timer + Time + Lux + Fade in one Rule


Raspberry Pi 4B with Openhab 2.5.5

I want to use Openhab for what the Hue App is doing.
Example: Turn Light on from 0-8am, when lux under 1 with 1%, after 5 secs turn the light off.

I am here for now:

var Timer StevensFlur = null                                                                                                                          // Timervariable definieren

rule "Bewegungsmelder mit timeout"
    Item StevenFlursensorPresence received update ON //changed                                                                                            // Bewegung wurde erkannt
    if(now.getMinuteOfDay >= 00*60  && now.getMinuteOfDay < 08*60)
        (StevensFlurlichtToggle.state != ON)
            StevensFlur = createTimer(now.plusSeconds(5), 
        (StevensFlurlichtToggle.state != OFF) 
            StevensFlur = null
            ]                        )

This works nice! But thats only a part of what i want to realize.

i just thought it would be as easy as change:

if(now.getMinuteOfDay >= 00*60  && now.getMinuteOfDay < 08*60)


if(now.getMinuteOfDay >= 08*60  && now.getMinuteOfDay < 21*60 && StevenFlursensorIlluminance.state < 1)

“StevenFlursensorIlluminance.state” was 0.9 by testing it and oh wonder it doesnt work like i thought, but it also did not produce an error.

hell, what do i miss here?

Special question:
is there a easy why for me, to fade the light out? from 8-21 i will leave the light on for 30 secs, would be nice if this would fade out. i tried the “universaldimmer rule” but i failed hard :sob: :sob: :sob:

@Udo_Hartmann maybe you can help me, i figured you out as the nerd of doom :smiley:

Thanks guys!

This looks reasonable. Add logging to find out what now.getMinuteOfDay is returning. Or simplify it and call getHourOfDay and get rid of all those *60s. Also log out StevenFlursensorIlluminance.state and add log statements to see which parts of the code are running.

1 Like

sounds good, i will try it tomorrow!

how do i add logging? i think thats a problem for me, cause i am not a “programmer”, i am a “google it and try to adopt it and sometimes throw the computer out of the window” guy :smiley:

1 Like

okay, i have to logg something after every entry so i can see where it stops, check!

so i found the mistake!
the value of “StevenFlursensorIlluminance.state” was “0.9997697679981565 lx”
i thought <1 would be enough, but no, it seems to be rounded to “1” so the rule did not fire. the only strange thing is that I tried it yesterday with <100 and it didn’t work…but now it works with <2, but i think i will switch to “StevenFlursensorLightLevel.state”, because its easier to tune.

so for now it works!

special question, i realized that my light turns on faster controlled by the hue app and a little bit slower over openhab, is there a way to fasten this up?

do you can help me with the fading?

Wait, that isn’t what is going on. That Item is using Units of Measurement. You need to compare it to a number with units.

StevenFlursensorIlluminance.state < 1 | lx

I don’t use Hue so couldn’t say and probably won’t be of much help.

that did the trick =)

i realized that my light turns of after the suggested timer, even if i am dancing in front of the motion sensor, how can I get round this?