Thanks, will play around with it when I have the time again, yesterday my first son was born so no PC time the last days
Will also look into that, for now the rule really works great and just how I wanted it
Thank you for this, I have read through the thread with interest and havre replicated the âTimers Versionâ and it works, which as a newbie I am pleased with
Could you explain the line:
if(occupancyTimer === null || occupanctTimer.hasTerminated()) {
as a beginner I struggle to find places to look up the syntax?
I assume â===â means does not equal?
What do the â||â characters mean?
and one final question, I thought occupanctTimer was a typo, but as it works, it is obviously not a typo, it is only referenced here and does not get reused, can you explain this in a little more detail please?
Sorry for all the questions, Iâm finding OpenHab a steep learning curve
Ian
Itâs a âspecial equalâ really, it means âis the same thingâ in computer terms.
Consider
A = 2
B = 2
A has the same value as B, but is not the same thing as B. For a start, itâs called A. Equal but not identical. We can change A and that would not change B.
A === A is true, these are the same thing.
A === B is not true; same value but not same thing.
You generally only meet === (or the ânotâ opposite !==) in rules where null is involved. Things that are null really are null, not just having a value of null.
OR in logical evaluation.
AND is represented as && which isa bit more obvious.
It is a typo.
So the test could never be true there, but it would very rarely matter as in real life the timer is either timing or is null.
hasTerminated should never come about for this particular timer really - when it does terminate, it sets itself to null.
Thanks for the explanations, that makes more sense now.
Iâve also got your âExpire Bindingâ version working, although didnât realise that binding was being used as in the true sense of a HA binding and took me a while to get it working, as I didnât have the binding installed
I like the idea of not using the OFF message of a motion detector, so you can define your own duration when the light is on. But this brought me to the following: Who likes to read on the toilet?
What i would like to do is that after the timer expires, instead of turning off the light, dim the light to for ex. 50% to indicate the user that the light is about to go off. Then start a 2nd timer (donât know if this is a good idea) to turn the light off after x seconds if the motion sensor does not detect any movement anymore. If movement is detected brighten up the light again and restart the timers.
Any idea how to implement this in the original timer example above?
Kind regards,
Eric
This is not problem. You need two timers.
- On motion, cancel and delete the second timer if it exists, turn the light up all the way, and set the first timer.
- If motion occurs again, reschedule the first timer.
- When motion hasnât happened for long enough the fist timer goes off. This timer dimms the light to 50% and sets a second timer.
- When the second timer goes off it turns off the light.
I donât understand this example unfortunately.
I have the following items and rules defined to turn on/off a Hue bulb using a Hue motion sensor.
Items:
Switch Motion_Badezimmer_Bewegungsmelder "Badezimmer Bewegungsmelder" <network> { channel="zigbee:philips_sml001:XXX:XXX:motion" }
Dimmer Lampe_Badezimmer_Decke "Badezimmer Lampe Decker" <lightbulb> { channel="zigbee:device:XXX:XXX:XXX_11_dimmer" }
Rules:
rule "Philips Hue Motion Sensor ON"
when
Item Motion_Badezimmer_Bewegungsmelder changed from OFF to ON
then
//execute your code here
Lampe_Badezimmer_Decke.sendCommand(100)
end
rule "Philips Hue Motion Sensor OFF"
when
Item Motion_Badezimmer_Bewegungsmelder changed from ON to OFF
then
Lampe_Badezimmer_Decke.sendCommand(0)
end
The Hue motion sensor changes back to OFF too quickly and therefore I want to delay this to turn off the lamp later. From the tutorial, I would have thought that modifying the motion detector item like so would work:
Switch Motion_Badezimmer_Bewegungsmelder "Badezimmer Bewegungsmelder" <network> { channel="zigbee:philips_sml001:XXX:XXX:motion", expire="5m,command=OFF" }
But it still turns off as soon as the Hue motion sensor sends the OFF state.
Because you didnât remove the rule. So when the motion sensor turns offer it triggers your Rule to turn off the light. Remove the rule.
Could you explain this a bit more I am new to rules and openhab and I have the same problem as michaelmell. Thank you
Rules are event driven. An event occurs and Rules configured to trigger on that event. The Event that triggers the Rule is defined in the when
clause.
michalemell has two Rules, one defined to trigger when Motion_Badezimmer_Bewegungsmelder changes from OFF to ON. This Rule sends essentially and ON command to Lampe_Badezimmer_Decke. The second rule triggers when Motion_Badezimmer_Bewegungsmelder changes from ON to OFF and sends essentially an OFF command to Lampe_Badezimmer_Decke.
So it doesnât matter what is done with the Expire binding to control the light. The Rule will always trigger when the motion sensor goes to OFF and it will always turn off the light. If the light needs to be turned OFF by the Expire binding instead of by the Rule, the Rule must be removed.
Oh ok that makes sense, but I have a problem where even even when I use your simples design pattern
rule "Motion sensor triggered"
when
Item zwave_device_f57cb095_node16_alarm_motion received update ON
then
FibaroDimmer1_DimmerSwitch1.sendCommand(ON)
end
with this switch
Switch zwave_device_f57cd095_node16_alarm_motion "Motion Alarm" <motion> (motion_zwave) {channel="zwave:device:f57cd095:node16:alarm_motion", expire="2m,command=OFF"}
then it just never expires after 2 minutes and it seems to me that its identical to your example. I tried to make it with the expire on FibaroDimmer1_DimmerSwitch1
being 2min aswell but it doesnt make a difference.
How often does the motion sensor Item get updated? The Expire timer gets reset on every update. If the updates come faster than every two minutes it will never Expire.
Also, what evidence are you looking for that the Expire happened? You donât have a Rule that does anything when the motion sensor goes to OFF. You donât have a Rule that turns off the light when the motion sensor goes to OFF. If you are expecting the light to go off after 2 minutes of the last motion, you should put the Expire config on the Light.
A reminder also that expire is an installable binding, not a built-in feature.
Ok thank you for that, it does turn off after 2 minutes now but is there a way where I could have the Expire be on the motion sensor so when I for example, turn all the motion sensors off then the light does not turn off after 2 minutes? Is it even possible to turn off devices from sitemap? I had this idea where I could turn off a Group item of motion sensors but I am wondering if thats possible.
Also to answer your question the motion sensor gets updated after 30 seconds to turn OFF
Iâm not sure your question makes much sense. What do you mean by âturning off the motion sensorsâ. The motion sensor Item is linked to a device. The device generates updates to the motion sensor Item when it sees motion. The update cause events (changed, updated) that trigger Rules. The Item will always receive those updates as long as it is linked to the device. However, what you do with those motion events is up to you.
So if you want to control the light with the motion sensor sometimes but not at other times, you need to add that code to your Rule. And you will probably not be able to use the Expire binding on the light and will have to create a Timer in your Rule itself.
It seems that there is a typo in the design pattern, it should be âoccupancyTimerâ and not âoccupanctTimerâ in the condition
Hi,
I am new to OH3, just playing around with the basics, got my Hue system with ~80 bulbs working, plus some dimmer switches and one experimental Fibaro Roller Shutters.
Now I wanted to get my Hue Motion Sensors working. Seems much off the older documentation and community content, especially when it comes the Expires AddOn, doesnât apply to OH3 anymore.
Getting a motion sensor installed was straight forward, and after some playing around it does now trigger a bulb to get turned on.
However, I am now struggling getting something like a timer set up, that after some period of time switches that bulb off again. Started playing with rules for that purpose, but somehow canât find the tree in the middle of the forrest :-).
Any suggestions welcome, Thanks in advance!
Expire has been merged into the core. So you configure it the same as it always has but you donât have to install a separate binding to use it.
If thatâs all you need then I recommend configuring the Expire Item metadata on the switch.
Any examples of rules that you see will still work in OH 2.5 with minor changes (usually to do with changing the date time classes or executeCommandLine). So pretty much everything in the original post will work as is. To use the Python code youâll need to install the Python add-on and the Helper Libraries for OH 3.
thanks. That seemed so easy, I tried it right away :-). So I added this Expiration Timer to the Hue Motion Sensor metadata:
value: 0h2m0s,command=OFF
config: {}
However, this doesnât change anything, thus I am guessing I got something wrong.