Help, I'm ready to give up

  1. I’m not sure. If you have any doubts download from the link above.

  2. Yes, ctrl-space

  3. And 4. Sounds like you are not running 0.8. when running 0.8 the only false negatives will be calls to add-on actions.

There was a couple day period when 0.9 was the current download at that site.

If it were useless I would not advocate it’s use.

Thanks – as always…

found in my change log distribution-1.8.3-designer-win.zip
just downloaded eclipsesmarthome-incubation-0.8.0-designer-win64.zip
started it… and…

… looks (evidence) whatever I touch in this OH context never works from the start.

No idea what to do with this.

Any help appreciated…

I may have misremembered. You are running 1.8? In that case I told you wrong and you need openHAB Designer. But I’m pretty sure that isn’t being maintained any longer. I’m not even sure where to download it any longer. I’m sure it’s on bintray or cloudbees. I’m on my phone so can’t really search at the moment.

No worries… a reason to get rid of it for good! :slight_smile:

Could someone take a look at this rule to turn on/off a light based on a motion sensor? BA_HUE_Motion is of course the hue motion sensor and bathroom_light is the hue light. The rule is working all EXCEPT keeping the light as long as motion is detected. I’ve searched around the site and found several ways to do this and tried them but couldn’t get them to work. This is what I’ve pieced together myself. If you have some other .rule code that works I’m game to switch to that. Note that I am checking if the time is between 6am and 11pm if it is then the bathroom_light is 100% if not then it’s 15%.

rule "BALightOn"
    when   
            Item BA_HUE_Motion changed       
    then   
logInfo('BA_HUE_Motion', 'Motion detected in Bathroom')
logInfo('bathroom_light', 'Turning Bathroom Light ON')
var DateTime t11p = new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 23, 00, 0)
var DateTime t6a = new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 6, 00, 0)

	if(BA_HUE_Motion.state==ON) {    
		if(now.isBefore(t11p) && (now.isAfter(t6a)) )	{
               	bathroom_light.sendCommand(100)
               	if(timer!=null){
        			timer.cancel
        			timer = null
        		}
     	} else {
                bathroom_light.sendCommand(15)
                if(timer!=null){
        			timer.cancel
        			timer = null
        		}
		}
	} else {
        	if(BA_HUE_Motion.state==OFF){
        		timer = createTimer(now.plusMinutes(3)) [|
        			bathroom_light.sendCommand(0)
        			logInfo('BA_HUE_Motion', 'No Motion in Bathroom for 3 minutes')
        			logInfo('bathroom_light', 'Turning Bathroom Light OFF')   			
        		]
        	} 
	}
end

After 133 postings to this thread, something like this probably should be posted into its own thread so it can be found by other readers of the forum easier. Answers to questions like these are particularly helpful.

Question: How does the motion sensor behave? By this I mean does it send an ON when motion is triggered and then send an off after a certain amount of time, just sends ON when motion is detected with no OFF, send ON immediately followed by OFF?

This is important because how the motion sensor behaves will greatly impact how the rule you want need to be written.

Let’s assume that the motion sensor either only sends ON commands or stays ON for a shorter or longer period of time than we want the light to stay on. This should cover most of the motion sensor behaviors listed above.

NOTE: I’ve made a number of other simplifications to your code below. Ask if you have any questions.

var Timer timer = null

rule "BALightOn"
when
    Item BA_HUE_Motion received command ON // only trigger when motion is detected, we don't care when the motion sensor goes OFF
then
    logInfo("BALightOn", "Motion detected in Bathroom")

    val t6a = now.withTimeAtStartOfDay.plusHours(6) // better way to get to something to compare to now
    val t11p = now.withTimeAtStartOfDay.plusHours(23) // better way to get to something to compare to now

    // Calculate brightness as a separate step to make the logic simpler
    var brightness = 15
    if(now.isBefore(t11p) && now.isAfter(t6a) brightness = 100

    logInfo("BALightOn", "Turning bathroom light to " + brightness)
    bathroom_light.sendCommand(brightness)

    // create a timer to turn off the light if one doesn't already exist
    if(timer == null){ 
        timer.createTimer(now.plusMinutes(3), [|
            logInfo("BALightOn", "Turning bathroom light off") // if you log the ON you should log the OFF
            bathroom_light.sendCommand(OFF)
            timer = null
        ]
    }
    // if there is a timer, reschedule it for another 3 minutes
    else {
        timer.reschedule(now.plusMinutes(3))
    }
end

However, this rule can be made even simpler using the Expire binding.

Item

bathroom_light "label" { hue="...", expire="3m,command=0" }

Rule

rule "BALightOn"
when
    Item BA_HUE_Motion received command ON // only trigger when motion is detected, we don't care when the motion sensor goes OFF
then
    logInfo("BALightOn", "Motion detected in Bathroom")

    val t6a = now.withTimeAtStartOfDay.plusHours(6)
    val t11p = now.withTimeAtStartOfDay.plusHours(23)

    var brightness = 15
    if(now.isBefore(t11p) && now.isAfter(t6a) brightness = 100

    logInfo("BALightOn", "Turning bathroom light to " + brightness)  
    bathroom_light.sendCommand(brightness)
end

The expire binding config above will wait for three minutes after the Item is set to something and then sendCommand(0) to the light after the last update to the Light is received. The rule will sendCommand the brightness every time the motion sensor is triggered, rescheduling the expire binding.

The Rule above this does the exact same thing using Timers.

See also:

  • Motion Sensor Timer for a more detailed explanation of the code above.
  • Time of Day for a better way to manage time periods in your home automation so you don’t end up with checks to see if it is between certain time periods scattered all over your rules.
1 Like

The Hue motion sensor appears to send both ON and OFF commands. The best I can tell, as long as it detects motion it stays on. Once it stops detecting motion it sends an OFF command a few seconds after no motion is detected. For my purposes, I just want the rule to react on the ON to turn on the light and then X amount of time after the OFF motion detection turn the light off. But if it detects motion after turning OFF and turns back ON then the timer should cancel so the light stays on.

It all boils down to how long the motion sensor stays ON. If it stays on for longer than 3 minutes without sending more ON commands then we have a problem. If it is shorter than 3 minutes what I have above will work.

No, the timer should be rescheduled so the lights turn off 3 minutes after the last motion was seen. If you cancel the timer then the lights will never go off.

The hue website says there is a 30 second delay after no motion is detected before the off command is sent. So your code should work. I’ll test it and see.

There was some mismatched () in your code I fixed to get it to turn the light on. It never turns the light off though. Also, for some reason the rule would not react to received command…have to use changed from OFF to ON

var Timer timer = null

rule "BALightOn"
when
    Item BA_HUE_Motion changed from OFF to ON // only trigger when motion is detected, we don't care when the motion sensor goes OFF
then
    logInfo("BALightOn", "Motion detected in Bathroom")
	//say("Motion detected in Bathroom")
    val t6a = now.withTimeAtStartOfDay.plusHours(6) // better way to get to something to compare to now
    val t11p = now.withTimeAtStartOfDay.plusHours(23) // better way to get to something to compare to now

    // Calculate brightness as a separate step to make the logic simpler
    var brightness = 15
    if(now.isBefore(t11p) && now.isAfter(t6a)) brightness = 100
    
    logInfo("BALightOn", "Turning bathroom light to " + brightness)
    bathroom_light.sendCommand(brightness)

    // create a timer to turn off the light if one doesn't already exist
    if(timer == null){ 
        timer.createTimer(now.plusMinutes(1), [|
            logInfo("BALightOn", "Turning bathroom light off")
            say("Turning Bathroom light off"
            bathroom_light.sendCommand(OFF)
            timer = null
        ])
    }
    // if there is a timer, reschedule it for another 3 minutes
    else {
        timer.reschedule(now.plusMinutes(1))
    }
end

Seems likely. I typed it on my phone. I recommend using Designer to find and fix the sorts of errors.

The motion sensor may just post updates instead of commands. Use received update ON instead.

Look in the logs when the file loads for parse errors. Content everything out but the log statements to verify the rule triggers

I am using Designer but in rules almost every line gives an error.

Ok. finally figured it out. Here is the code that works:

var Timer timer = null

rule "BALightOn"
when
    Item BA_HUE_Motion received update ON // only trigger when motion is detected, we don't care when the motion sensor goes OFF
then
    logInfo("BALightOn", "Motion detected in Bathroom")
	//say("Motion detected in Bathroom")
    val t6a = now.withTimeAtStartOfDay.plusHours(6) // better way to get to something to compare to now
    val t11p = now.withTimeAtStartOfDay.plusHours(23) // better way to get to something to compare to now

    // Calculate brightness as a separate step to make the logic simpler
    var brightness = 15
    if(now.isBefore(t11p) && now.isAfter(t6a)) brightness = 100
    
    logInfo("BALightOn", "Turning bathroom light to " + brightness)
    bathroom_light.sendCommand(brightness)

    // create a timer to turn off the light if one doesn't already exist
    if(timer == null){ 
        timer = createTimer(now.plusMinutes(1)) [|
            logInfo("BALightOn", "Turning bathroom light off")
            //say("Turning Bathroom light off")
            bathroom_light.sendCommand(OFF)
            timer = null
        ]
    }
    // if there is a timer, reschedule it for another 3 minutes
    else {
        timer.reschedule(now.plusMinutes(1))
    }
end

What version of Designer are you using? That looks like the 0.9 version which is currently unusable. There is a fix undergoing test but for now we should use 0.8. There is a statement in the docs that makes it sound like we should use the latest nightlies which is currently incorrect while this error is in place.

With 0.8 none of those lines would be marked as errors.

Glad you got it working.

Yeah i was following the instructions and using the .9 version. I switched
back to the .8 version.

Zwave is frustrating!!! I cant’ seem to get it working. I did once and then had like 20 nodes and wanted to reset it so that only the 3 nodes that actually exist show up. So I deleted all things, reset the zwave devices and now I can’t get anything to work.

I cannot confirm that statement, zwave is working fine here without any bigger problems.
You are giving not many details on your actual problem, so it’s hard to help.

If you really did that you have excluded all your devices from your network. Resetting a device means automatically excluding. So you have to start over again and do an inclusion …
Your REALLY need to start reading the docs!

I’d love to dig into it, if I only could get it to open :wink:

Yes, your post is very frustrating. Every Raspberry pi is the same, so take a working Rapsberry Pi coupled with a decent power supply and a good micro SD card correctly programmed with OpenHabian and a reliable internet connection, will correctly install Openhab EVERTIME, no exceptions.

If not, then either you are doing something wrong or part of your equipment is faulty.

1 Like

Hello Ed, everyone here just wants to help. Sadly from your posting there is not much to go with.

What still boggles me is that an apt-get setup puts files in different directories than the manual setup.

That’s the way Linux organizes files. Over the last decades thousands and thousands of people have perfected this and everyone working with Linux should read up on these basics. Regarding the openHAB setup, we’ve made sure to make 100% clear, where the files are located. It still boggles me how so often people are rattled by this.

it just doesnt work with no indication why

``

do exactly as told… does nothing.

``

For openHAB to become a serious platform first and foremost it needs to work.

How could one even start to give an advice here… The process of setting up openHAB is straight forward. The installation instructions (especially addressing the one for Debian/Ubuntu) are crystal clear and were updated almost monthly lately. With openHABian we even provide a ready-to-go solution without any need for manual setup steps: quote

Why cant it just work predictably after people follow the official setup.

It does. For (looking at download statistics) probably around a few thousand people over the last month alone. If you are not seeing the results you are aiming for, you are either not following the instructions or you are expecting the wrong results. In both cases it would help us and yourself, if you would compose a message, with a clear description of the situation you are in.

I’m the last one to not help a new openHAB user. Pointless rantings like seen in a few postings here in this one thread make me question the value of this effort on my side.

1 Like