Jump to content

Programming - possible to include multiple steps / paths ?


Badrobots

Recommended Posts

I have an ISY 99 with various insteon switches and outlets. I've gotten simple programs to work, but am not having much luck with more ambitious projects. There are two basic things I'd like to do:

 

1. Include multiple options depending on different conditions. I don't know if this is possible, or if you need to write a seperate program for each option, but here is what I'd like to do: I have an evening program that evaluates conditions, and then turns lights on. Depending on conditions, I would like it do different things. For example: The program is activated when the door switch (connected via EZIO) is activate, AND its after sunset AND the lights are not already on. So far so good. But, if the thermostat is still in daytime mode, I'd like to kick it into evening mode. And if the some of the lights are already on, I would like to run a limited version of the program (just hallway lights). I could do seperate programs for each of these actions, but I'd be duplicating a lot of code, and it's not a very elegant solution. Is this sort of thing possible?

 

2. Run a series of events without re-evaluating the initial conditions. So, taking the evening program: It activates when the door is opened and the lights are all off. So far so good. Then it slowly adjusts the lighting from "bright so I don't trip on stuff in the hall" to a more mellow, evening lighting. When it re-evaluates the initial conditions, now the lights are on, so the program stops. OK, I found a "hack" way around this. I set the program to turn one of the lights to an odd value - e.g. living room to exactly 97%, and then include this value as an "OR" under the original conditions. Since its very unlikely that I would accidently set the living room lights to exactly 97% when I'm home, it works ok. But is not very elegant. I was thinking of trying to use a variable to solve this but am having some difficulty. My thought was (this is just the logic, not code)

 

IF (door open, lights off, after sunset, etc)

OR IF (Variable "ImHome" = 1)

 

THEN:

Set Variable "ImHome" = 1

Set initial light

WAIT

Change lighting

WAIT

Change lighting again

Set Variable "ImHome" = 0

 

Seems logical to me, but doesn't work.

 

Any comments welcome!

Link to comment

There are no embedded Ifs. What can be done is have Program 1 Then clause which runs when Program 1 If evaluated to True perform some function and then invoke Program 2. Program 2 contains additional If conditions which will be evaluated only when Program 1 If evaluated True. Programs can be cascaded in this fashion to accomplish what embedded Ifs would do.

 

Difficult to evaluate pseudo code results. Right click Program name, select Copy to Clipboard, post actual Program to forum which as much detail as to what is desired and what actually happens.

Link to comment

Here is the code - thanks!

 

 

If

From Sunset

To 9:00:00PM (same day)

And Status 'Garage door' is Off

And Status 'Kitchen Keypad.1' is Off

And Status 'Living Room' is Off

Or $Honeyhometrue is 1

 

Then

$Honeyhometrue = 1

Set 'Thermostat- Main' 20° (Heat Setpoint)

Set 'Basement Keypad.1' On

Set 'Living Room' 70%

Set 'Kitchen Keypad.1' 70%

Set 'Bar/Sink' 70%

Wait 2 minutes

Set 'Basement Keypad.1' 60%

Set 'Living Room' 50%

Set 'Dining Room' 60%

Wait 2 minutes

Set 'Basement Keypad.1' 40%

Set 'Dining Room' 40%

Set 'Kitchen Keypad.1' 35%

Set 'Bar/Sink' 55%

Set 'Den plug in lights' 30%

Set 'Living Room' 30%

Set 'Library' 30%

Set 'Library Ceiling Light' 18%

Wait 2 minutes

Set 'Basement Keypad.1' Off

Set 'Dining Room' Off

Set 'Fountain' On

$Honeyhometrue = 0

 

Else

- No Actions - (To add one, press 'Action')

Link to comment

The If clause needs parens to get the order of precedence correct. Not sure what is supposed to be Anded together and what is should be Ored to what.

 

The first set of statements before the first Wait change the conditions the If is checking. This means the If will be reevaluated as soon as the Wait is executed. For example, Set 'Kitchen Keypad.1' 70% will make the Anded statements False because Kitchen Keypad.1 is no longer Off. That will cause the Else clause to execute.

 

Also need to know if the Variable is an Integer or State Variable. If a State Variable changing its value will cause the If to be reevaluated when a Wait is encountered.

Link to comment
The first set of statements before the first Wait change the conditions the If is checking. This means the If will be reevaluated as soon as the Wait is executed. For example, Set 'Kitchen Keypad.1' 70% will make the Anded statements False because Kitchen Keypad.1 is no longer Off. That will cause the Else clause to execute.

 

Yes, that's the reason I also include the "OR" statement which at that point should still be true. Only at the end of the program will it revert back to 0. But it doesn't work.

The variable is a state variable. Would it work in this case as an integer?

Link to comment

I think you wanted the If logic to say if all the first three conditions exist Or the last statement condition exists.

 

(

Status 'Garage door' is Off

And Status 'Kitchen Keypad.1' is Off

And Status 'Living Room' is Off

)

Or $Honeyhometrue is 1

 

Without parens that is not the result. The last Variable condition is Ored with the Statement above it

 

And Status 'Garage door' is Off

And Status 'Kitchen Keypad.1' is Off

And

(

Status 'Living Room' is Off

Or $Honeyhometrue is 1

)

 

The Ored statement does not produce the effect needed without parens.

 

Add parens to obtain the desired combination of conditions. Maybe this is what you want??

 

If
       From    Sunset 
       To       9:00:00PM (same day)
   And  (
                      (
                               Status 'Garage door' is Off
                       And Status 'Kitchen Keypad.1' is Off
                       And Status 'Living Room' is Off
                      )
              Or  (
                     $Honeyhometrue is 1
                     )
            )

Then

 

I think the Variable was added to avoid the reevaluation results when the Wait is executed. Easier to accomplish this by breaking the logic into two Programs. Have the Then in the first Program Run Program 2 which has the Then logic of the existing Program and nothing in the If clause. That way the changes the Then clause are making to the If conditions do not cause a reevaluation. The Variable can be removed completely if done that way.

Link to comment

Archived

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


  • Recently Browsing

    • No registered users viewing this page.
  • Who's Online (See full list)

  • Forum Statistics

    • Total Topics
      36.9k
    • Total Posts
      370.3k
×
×
  • Create New...