Jump to content

Program with if(variable) condition doesn't run


Steve L
Go to solution Solved by larryllix,

Recommended Posts

I have two light switches and two motion sensors. While either of the sensors detect motion, I want the two switches to be on for two minutes, then turn off. Any new motion resets the time to two minutes.

Following the ideas in https://forum.universal-devices.com/topic/37370-interesting-way-of-looking-at-programming-on-isy994/ , I have the following programs:

Front Sensor On - [ID 0003][Parent 000E]

If
        (
             'Driveway Motion Sensor / ZW 002 Home Security Alarm' Home Security is Motion (no location)
          Or 'Walkway Sensor / ZW 011 Home Security Alarm' Home Security is Motion (no location)
        )
 
Then
        Set 'Front Door Switch' On
        Set 'Driveway Light switch' On
        $Clock.FrontLights  = 3
        Run Program 'Timer.Lights' (If)
 
Else
   - No Actions - (To add one, press 'Action')
 

FrontLights.Off - [ID 0012][Parent 000E]

If
        $Clock.FrontLights < 1
 
Then
        Set 'Front Door Switch' Off
        Set 'Driveway Light switch' Off
        Stop program 'Timer.Lights'
        $Clock.FrontLights  = 255
 
Else
   - No Actions - (To add one, press 'Action')
 

Timer.Lights - [ID 0010][Parent 000F]

If
   - No Conditions - (To add one, press 'Schedule' or 'Condition')
 
Then
        Repeat Every  1 minute 
           $Clock.FrontLights -= 1
           Wait  1 second
 
Else
   - No Actions - (To add one, press 'Action')
 

Turning on the lights is no problem. I can see the variable decrementing to zero, and then... FrontLights Off never runs and the variable continues to decrement. I can manually run the Off program and it does what it is supposed to do, but why doesn't it run when the variable goes to zero?

 

Edited by Steve L
Link to comment
  • Solution

Too much complication for the usual and typical triggered light timer.

A condensed version

if Motion is switched on
Then
turn on light
Wait 2 minutes
turn off light

Else
turn off light...this handles some rare cases that other lines in if cause the Wait to be cancelled mis time out.

When an if condition is triggered it causes the program to start over. 2 minutes can last forever.

Sent from my SM-G781W using Tapatalk

  • Like 1
Link to comment
1 hour ago, Steve L said:

The Timer.Lights program did run, and it would have been stopped if the FrontLights.Off program had run. 

Without State variable type usage the program would never trigger.
With State variable type usage the program would have triggered, set the variable to 255, re-triggered the program and ran else due to >= 1. (Caused it's own event)

However your Then section most likely would have been completed and worked. There are times where lines can get executed ahead of other lines when they are called in different programs.

Edited by larryllix
Link to comment
Guest
This topic is now closed to further replies.

×
×
  • Create New...