Jump to content
C4 Forums | Control4

Single sensor program not working


Recommended Posts

Our driveway had two probes, a south one nearer the driveway gate, and a north one nearer the house. The south one went bad so I changed the program for the north one to let it turn on the lights when we enter at night.

When we arm the security system to Away it also turns on the carport wall sconces so we can see getting in the car. Then when we drive off we want them turned off. This part works fine.

When the Equipment Room->North Driveway Sensor senses a vehicle
> Execute Announcement 'Driveway sensor activated'
? If Variables->Nighttime is True
  ? If the Equipment Room->Security System is Armed to Away
    ? If Carport/Front Porch->Carport Sconces is on
      > Turn off the Carport/Front Porch->Carport Sconces
      > Stop
  > Turn on the Carport/Front Porch->Carport Sconces

Also, when someone drive home and the alarm is not set because someone is already home, the lights turn on as expected.

The weirdness comes when we drive home and the alarm IS set to Away. The lights flash on, as expected, but then flash off, and after a couple of seconds delay they repeat, flashing on and then off, finally staying off.

Can anyone think how this behavior might happen?

Link to comment
Share on other sites

That's exactly what I would expect that code to do as the beam will keep triggering every couple of seconds.  The first time it triggers it will turn the lights on, the second time it triggers it will turn the lights off etc. A quick fix would be to activate a timer for (say) 2 minutes as a new line at the end of the code you have shown above. The timer does not need to do anything although you could turn the lights off when the timer expires if you want.  You then need to add one more nested if statement before turning off the lights. That will be "if new driveway timer is NOT running"

I hope that makes sense? There are probably more elegant ways to do this.

Good luck!

Link to comment
Share on other sites

Thank you kindly for this good lead. I'm certain you are correct, and I've added a timer check. I'll be able to test it tomorrow night.

I had lazily thought that since I only received a single announcement that there was only a single trip through the event code. But we know there is a built-in lag time for announcements, waiting for the amplifier to turn on.

Link to comment
Share on other sites

Didn't work, I'm afraid. It just reversed the behavior.

When the DrivewaySensor senses a vehicle
If DrivewaySensorTimer is running
Start DrivewaySensorTimer
Execute Announcement 'Driveway sensor activated'
If Nighttime is True
    If the SecuritySystem is Armed to Away
        If CarportSconces is on
            Turn off the CarportSconces
    Turn on the CarportSconces

The behavior is fine if the Security is not armed. It simply turns the lights on when we return at nighttime. But now, if the system is armed, it first flashes the lights off (they were turned on when we armed the system to Away), then back on. Then when we return the lights which were left on are, understandably, turned off.


Link to comment
Share on other sites



I have eave not given your code much thought but will try and look at it more carefully tonight. Assuming that we have the codin working properly on the driveway beam, I suspect that what we have both missed is that you would also need to fire off the same timer when you arm the system to away... That will stop the driveway sensor overriding things if you have just armed the system.

combined with this though, I suspect you will need to move the lights off command to the on timer expires event.

As an aside, you may also need to make the timer longer (e.g. 5 minutes). I don't know how long it takes you to get from arming the system to outised of sensor range?

Hope that makes some sort of sense? If not, I will try and look more carefully at it tonight.

Link to comment
Share on other sites

Thinking a little more about this and starting with a blank piece of paper, why not simply have:


When alarm is activated in away mode

   If nighttime 

       Turn lights on

        Reset timer


when driveway senses movement

   If nighttime 

       Turn lights on

        Reset timer


when timer expires

    Turn lights off


If you need the announcement, you would add that in up front in the driveway senses motion bit of code as:

   If timer is not running

      Execute announcement

Link to comment
Share on other sites

Thank you, "South Africa". I really appreciate your help.

I see the possibility in your code above, though it bugs me to have a fixed interval timer for how long the lights stay on. No telling how long we might need to get unpacked and inside on arrival.

It also bugs me that I feel I'm missing something fundamental in the original code. It appears that the code gets executed twice. I tried moving some of the code to the "Stops sensing a vehicle" event to "debounce" the circuit, but that didn't help either.

I did have a very short timer, only 5 seconds. Maybe the announcement was taking that long. Changed it to minutes, and we'll see tonight how it does.


Link to comment
Share on other sites

I would do this

alarm state changes

    When armed away

              turn on light

              set variable to leaving

    When disarmed

          Start timer or turn off the lights what ever you want here


on sensor trigger

turn on lights

 start timer 

if variable is set to away


     if alarm is armed away

          set variable to away





what should happen

if you arm the security the lights will turn on and stay on till you pass the sensor

if you come home and the alarm is set it will turn the lights on and stay on until you disarm the security

if you come home and the system is disarmed it will turn the lights on (you will need to decide when you want them to turn off or turn them off manually or use some other sensor) honestly time here would probably be best like twenty minute timer

Link to comment
Share on other sites

Okay, I think I've got this wired now. Hand testing shows it to be working as desired.

When security system armed to Away
	Set variable drivewayLeaving to True
	If nighttime
		Set Kitchen Light to 60
		Activate carportLightingOnScene

When the driveway senses a vehicle
	Execute announcement "vehicle on driveway"
	If nighttime
		Activate carportLightingOnScene
	If drivewayLeaving is True
		Toggle drivewayLeaving
		Activate carportLightingOffScene

I think the problem with the original was in relying on the status of the security system. We need a Variable.

When we arm security to Away we also set a variable to tell the driveway we are leaving. If it's night time we also turn on the kitchen and carport lights.

When we sense a vehicle, whether coming or going, we always make an announcement, and if it's night we always turn on the carport scene. It won't matter if the carport scene was already on from setting security to Away in the previous code. Then if the variable tells us we are leaving, we toggle the Leaving variable to False and turn off the lights. When we come back later that night, we always announce (the dogs like to know we're coming), and always turn on the lights, and since the Leaving is now False, the lights stay on!

So the programming principles for me are: 1) Design so default behaviors come first in the code, under as few "Ifs" as possible; 2) Use a Variable that you can toggle when you want to toggle behavior (here, turning lights on vs. off).

Thank you all for your attention and input. I hope you find this resolution method useful.

Link to comment
Share on other sites

Yes, thank you, Matt. I can't toggle the state of the security system (aside from physically changing it), so it seems simplest (and is so easy) to create a variable to keep track of the state of the security system AND whether the driveway sensor has been passed once.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.