Design Pattern: Motion Sensor Timer

gerat info, Thanks for let me know, it will save me lot of time on trying,
I will continue try on the code see which part goes wrong

if you donā€™t mind, would you just a short question,
will if(receivedCommand==OPEN){ works? or it should only works when ==ON?

If the item that triggers the rule is a Contact, OPENED. If it is a Switch, ON.

Each Item type has different state types. You have to use what is appropriate for the Item type.

Thanks, I think I need to study on Docs regarding item type,
Itā€™s really a long way to go for me to make OH2 runs as I expecte

Hi @rlkoshak

change to StringItem still not works, rules get trigger without error but just no further action
I change to switch items with transform than it works :grinning:
your provide information helps me a lot, Thank you in deep.

As Watou said on Jan 11, addressing a state that has not been updated for a while works well with the expire binding.

Here is a tutorial I did on using expire binding to catch nodes that have not reported in for a while. The tutorial includes links to expire binding documentation by Watou.

3 Likes

Great tutorial! Thanks for sharing it.

Just a note that the Expire binding is the brainchild of Michael Wyraz; I just pushed it along a bit. :smile:

Thank you @rlkoshak for great examples.
Just want to point out a small typo:

There should be a terminating ) just before the ] at the end of the lambda I think

Cheers

Actually the paren goes after the ]. Thanks for catching the error.

@rlkoshak

Rich,

sorry for opening this old threadā€¦
concerning the expire binding on a motion sensor, what happens if motion is constantly being triggered?
Does it still turn off after X time, or will it restart the timer if for example a rule calls for turning a switch on?

I have a functioning motion sensing rule which adds 1m to a timer when continous motion is tracked. Unfortunately once in a while, sometimes daily this timer is not being cancelled correctly, thus the lights remain on.

Checking for this ā€œopenā€ timer is quite hard, as the system cannot know whether it should/should not be there.

It gets rescheduled for each trigger. It is only after the set amount of time after the last motion event that the expire binding triggers.

Great, thanks for the swift reply.
Will rebuild my rules accordingly with the expire bindings.

Hi,
is it possible to post a running motion detection rule (whole code) when someone succeed in?
I try to make some tests with the aeon multisensor 6ā€¦ and want to use it as a trigger when motion than message and when dark and motion than turn on light as long as 5 min are no more motionā€¦
another combination could be turn on light if motion but dont turn off if tv still one ore something like thisā€¦ there are a lot of examples, but not completly explained and often missing code or information or with some problemsā€¦
I am new here, but isnā€™t here a section with complet examples and not with 100 of posts in it with coments which is working and which not etcā€¦?
Till now everyone has to search in several diferent websites for answers regarding a special item, f.ex. zwave items like my sensorā€¦ and than collect all this info with diferent examples to adaptā€¦ isnā€™t it possible to acumulate here one by one the devices and examples etc???

kind regards,

Oliver

Hi Oliver, i feel your pain, ive been scratching my head for a while myself and doing alot of testing to make sure that the rules i use work correctly. i can give you an example here of rules that work in my case:

I use Expire binding with items
My multisensor 6 has a motion timeout of 10sec

Switch Bad1VDTimer	 			{expire="7m,command=OFF"}
Switch Bad1VDTimerNight	 		{expire="3m,command=OFF"}

First rule is to allow me to have an override switch: here i take the zwave device and move it to an virtual device ā€œIFā€ override is not ON

rule "Bad1MotionON"
	when
	Item Bad1Motion received update ON
	then if(Bad1VDMotionOverride.state==OFF){Bad1VDMotion.sendCommand(ON)}end

rule "Bad1MotionOFF"
	when
	Item Bad1Motion received update OFF
	then if(Bad1VDMotionOverride.state==OFF){Bad1VDMotion.sendCommand(OFF)}end

Here is the rule for motion on Daytime/NightTime

    rule "MotionOn Daytime/NightTime"
	when
    Item Bad1VDMotion received update 
	then if ((Bad1VDMotion.state==ON) &&(GoodnightMode.state==OFF) && (CozyMode.state==OFF)&&(Bad1LightON.state==OFF)) {
	sendCommand(Bad1Dim1,100)
	sendCommand(Bad1VDSonos,ON)
	sendCommand(Bad1LightON,ON)}
	else if ((Bad1VDMotion.state==ON) && (GoodnightMode.state==ON)){
	sendCommand(Bad1Dim1,10)
	sendCommand(Bad1LightON,ON)}
	else if ((Bad1VDMotion.state==ON)&&(CozyMode.state==ON)&&(GoodnightMode.state==OFF)){
	sendCommand(Bad1Dim1,10)
	sendCommand(Bad1VDSonos,ON)
	sendCommand(Bad1LightON,ON)}
	end

When motion off is received from Zwave device (virtual device) i starts the timer

rule "MotionOff"
 	when
 	Item Bad1VDMotion received update OFF
 	then sendCommand(Bad1VDTimer,ON) end

Here the timer runs out but will only turn off the light IF there is no motion

rule "LightOff"
	when
	Item Bad1VDTimer received update OFF
	then if (Bad1VDMotion.state==OFF){
	sendCommand(Bad1Dim1,0)
	sendCommand(Bad1VDSonos,OFF)
	sendCommand(Bad1LightON,OFF)}end
  
rule "LightOff Nighttime"
  when Item Bad1VDTimerNight received update OFF
  	
  then if ((Bad1VDMotion.state==OFF)&&(Bad1VDTimer.state==OFF)){
	sendCommand(Bad1Dim1,0)
	sendCommand(Bad1VDSonos,OFF)
	sendCommand(Bad1LightON,OFF)}end
  	     
  
rule "LightManualOff"
	when
	Item Bad1Dim1 received update 0
	then 
	sendCommand(Bad1VDSonos,OFF)
	sendCommand(Bad1LightON,OFF) end

The Bad1LightON switch is used to allow me to manually dim the light and not having it getting triggered back to the original setpoint the next time i trigger the motion sensor.

Hope this helps alittle :slight_smile:

Regards Chris

Sadly the answer is no. There are over 200 technologies that OH supports each of which can have upwards of a thousand separate devices. There are literally billions of combinations of technologies, devices, and rules. We could start now and stop development on OH entirely and dedicate all of our time compiling just a list of all of these combinations and we wouldnā€™t finish in our lifetimes.

Home automation is hard and the fragmented nature of the industry makes it even harder. There isnā€™t a whole lot OH can do about it. But you should be able to find everything you need to make OH work with devices/technologies that OH supports from the OH docs or from this forum.

There are literally two functional complete and working examples at the top of this thread. The comments and discussions are inevitable as the fact that every oneā€™s OH system is completely unique there are enevitable cases that donā€™t quite work the same as the OPā€™s example, there are suggestions for changes or improvements, etc. This is a good thing and most of the posters go back and update the top posting with corrections and improvements.

Would you rather just have examples with no corrections or alternative suggestions? You want to just hope it works for you and if not you are out of luck? Or would you rather have the opportunity to ask for help from the very person who posted the example?

I understand your frustration and am not belittling it. But what you are asking for has been brought up multiple times and no one has been willing to work on it, largely because it is an impossible task. It is hard enough for the Zwave devs and users to keep up with just that one technology.

Thanks for the great design pattern @rlkoshak

It seems like several people here on the forum uses xiamo or hue motion sensor, all of these reports strings back(MOTION, true or similar). The disadvantages with these sensor(as far as I know) is that you need to poll them to get the status, I tried setting the polling interval to 0.5s but this made my rpi crashā€¦ so I ended up with 1.0s which is to slow for bathroom but might be OK for garage etcā€¦ I am still searching for MQTT motion sensors or similar, so please tip me if you know any devices like that.

If you still want to use hue motion sensor, then you could use map function to get it to work:

(function(i) {
    var json = JSON.parse(i);
    return ((json['state']['presence'])) == true ? "ON" : "OFF";
})(input)

Then the switch item will use both the http and expire binding:

Switch HallwayMotion "Hallway Motion" (Group_Presence,Group_Hallway) { http="<[http://192.168.0.??????/api/?????????????????????????r/sensors/3:1000:JS(getHueMotion.js)]" , expire="3m,command=OFF" }

Then in your rule use as @rlkoshak suggested:

when
Item HallwayMotion received command ON
then
// Do ur stuff
end
1 Like

Hi Rich,
thanks for the detailed answerā€¦ i think you are right and i will try to find out my problems hereā€¦
i am not a totally dummyā€¦ and i think i will solute my problemsā€¦ at the moment i am trying and testing as much as i can to install oh2 in my new house in the middle of next yearā€¦ so enough time.
but i have to find out which devices i will useā€¦
i was thinking about to use the zwave uzb1 and the zigbee raspbee module from dresden-elektronik to be able to use both technologies. I want to use ikea lights and leds from the german company Paulman ā€¦ which are working with zigbee tooā€¦ (Paulmann is in the ā€œsmart-friendsā€ alliance). I dont know if this is a good ideaā€¦ but i will try and no i am waiting if the zigbee device will be workingā€¦ to test light action combined with the sensorā€¦
maybe i have to change my compnentsā€¦ i want to use aeotec multisensor 6 and also ā€œDoor / Window Sensor 6ā€ from themā€¦and lots of zigbee controled lights for not having to use knx with a dali-device which is much more expensive.
Every advice is welcomeā€¦

kind regards,

oliver

Hi Chris,

great example. Big thanksā€¦ i will try to adapt it for my usageā€¦ think it will work.
where do you define CozyMode and GoodnightMode?
You also implemented Sonos? I also want to doā€¦ when entering the room you play music?
how you do?
i would like to see more of your rules and configsā€¦ i think i can adapt a lotā€¦
At the moment my mane problem is, i am waiting on the integration of raspbee device to controk my test ligt via zigbee, but i also ordered an cheap zigbee usb with ti chipā€¦
kind regards,

Oliver

Hi Chris,

thanks for your rule example.

On my try i got:
[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ā€˜EGFlurMotionOFFā€™: The name ā€˜EGFlurVDMotionOverrideā€™ cannot be resolved to an item or type; line 12, column 10, length 22

Is xVDMotionOverride to set as an item?

GoodnightMode and CozyMode too?

Hi Marcello

I have all my items stated in the example above as an item.
This way you can link them to your sitemap page and turn the motion detection on or off.

As of now the GoodnightMode and CozyMode are separate switches but would probably be better to put as a Number item and then just define them in a MAP file.

Chris

Hi Oliver,

I have currently defined the items CozyMode and GoodnightMode as a switch item and trigger GoodnightMode with a switch by the masterbedroom. CozyMode is currently set to trigger at 9PM with a cron rule if AwayMode (a switch by the frontdoor) is not activated.

The sonos are implemented for both bathrooms and the kitchen. The bathrooms detect motion, turns off the fan, dim the light up and turn on the selected radio channel and volume defined in my sitemap.

In the kitchen i sense the watt usage on the cooking top and turn on the Radio and fan. Fan turns off if the wattage is below a certain value for more than 30seconds. Wattage is definded in my sitemap.

Iā€™ll try to upload some of my codes this weekend.

Regards

Chris