Apex Fusion When Command Not Working

ariellemermaid

Well-Known Member
View Badges
Joined
Aug 21, 2020
Messages
624
Reaction score
473
Location
North Carolina
Rating - 0%
0   0   0
I’m trying to set up a “Water Change” virtual switch with a fallback in case it’s activated inadvertently or someone forgets to restart the tank. Especially important IMO because I’m linking the switch to Alexa. According to the documentation and forum posts the syntax is:

When ON > mmm:ss Then OFF

Full switch code I’m using:
Code:
Fallback OFF
Set OFF
When ON > 000:10 Then OFF


#10second trial, I’ve used many different numbers though. Final code would be like an hour.

Everything about this is working correctly with the corresponding pump code. However, the switch never turns off, and therefore my pumps never turn back on unless I manually do it. The When command was added specifically to turn off a switch/plug if it has been on a certain period of time, but this isn’t working at all for me.

As far as I can tell from testing, it seems to be because the switch is being activated with a manual ON that can’t be overridden with the When command. When I drop similar code into my light, it works, but only if the light starts on AUTO. If it starts OFF or ON I can’t change its status with the When command. And after the code is done, it’s fixed in either ON or OFF and not AUTO anymore; seems like that could be an issue as well. Setting AUTO doesn’t seem to be an option in code.

Another weird little quirk: “When ON....” is sent to the apex and I then go back into the switch code it changes to “When On” yet it seems ON/OFF are always fully capitalized.

Am I missing something, is this a half-baked feature, or am I maybe trying to use it beyond what it’s intended for? Thoughts, ideas, suggestions?
 
OP
OP
ariellemermaid

ariellemermaid

Well-Known Member
View Badges
Joined
Aug 21, 2020
Messages
624
Reaction score
473
Location
North Carolina
Rating - 0%
0   0   0
I thought I might be able to get around the problem by making another switch. The above switch would work in the background and a new one would be activated on the Home Screen.

This works to a degree. Now the background switch if started in AUTO does deactivate after 10 seconds and everything else turns back on. However, the new switch gets stuck in the ON position (ok-ish, this is a fail safe after all) and the background switch becomes permanently deactivated in OFF (not ok at all). Toggling the master switch has no effect on the background switch until manually moved back to AUTO. So I guess fundamentally that’s my issue with the When command...once it turns something OFF or ON it seems I can’t reverse it with code. Is there a setting to change this behavior maybe, or am I missing some code?

Even then, Neptune said the whole point of the When command was so people didn’t have to create switches to activate other switches to do something.
 

SuncrestReef

That Apex guy
View Badges
Joined
Jan 18, 2018
Messages
4,214
Reaction score
9,226
Location
Oregon
Rating - 0%
0   0   0
The problem is that you’re not using the Set ON command, and I assume you’ve been testing by sliding the output’s slider to the manual ON position instead of AUTO. The Apex ignores all programming if the slider is set to ON or OFF. It only runs the code when set to AUTO.

Fallback OFF
Set ON
When ON > 010:00 Then OFF

Each time you move the slider to AUTO, the Set ON command will turn it on (indicated in the text directly above the slider), and it will remain in the AUTO position until the When timer is exceeded, then move back to the OFF position. The When command is the only thing in the Apex programming language that can move a slider.
 

SuncrestReef

That Apex guy
View Badges
Joined
Jan 18, 2018
Messages
4,214
Reaction score
9,226
Location
Oregon
Rating - 0%
0   0   0
The When command is only meant to be a failsafe, not a general purpose timer. If you want something to only run for a set period of time, but not based on specific time of day, and not requiring manual intervention to move the slider back to AUTO, then using a virtual output is required:

[Pump]
Fallback OFF
Set OFF
If Low OPEN Then ON
If Output PumpTimer = ON Then OFF

[PumpTimer] <— virtual output
Set OFF
If Output Pump = ON Then ON
Defer 010:00 Then ON
Min Time 360:00 Then ON

This example will turn the pump on for 10 minutes when the Low switch is open then turn it off for at least 6 hours. It will only turn back on after 6 hours if Low is open again.

This isn’t necessarily what I would recommend for your water change scenario, but just an example of a general purpose timer.

See my Apex tutorials for more details and examples:
 
OP
OP
ariellemermaid

ariellemermaid

Well-Known Member
View Badges
Joined
Aug 21, 2020
Messages
624
Reaction score
473
Location
North Carolina
Rating - 0%
0   0   0
The problem is that you’re not using the Set ON command, and I assume you’ve been testing by sliding the output’s slider to the manual ON position instead of AUTO. The Apex ignores all programming if the slider is set to ON or OFF. It only runs the code when set to AUTO.

Fallback OFF
Set ON
When ON > 010:00 Then OFF

Each time you move the slider to AUTO, the Set ON command will turn it on (indicated in the text directly above the slider), and it will remain in the AUTO position until the When timer is exceeded, then move back to the OFF position. The When command is the only thing in the Apex programming language that can move a slider.
Thanks I think this helps the most; I suppose it’s not as much about how the When command works but more generally about how Apex works.

So by Set ON in this example I would simply use OFF (for off) and AUTO (for ON) and forget about ON altogether. Sounds like that will definitely work.

I only have to figure out if Alexa can set AUTO (for on) as that’s a strong secondary goal for me. I’m guessing not but I’m not home right now. I just love the convenience of voice control rather than going through several steps in my phone. Especially when I’m going from tank to tank doing water changes. Perhaps I could incorporate your second post for that.

I suppose there’s also the option of using a feeding mode...I just like to keep my programming and modes a little cleaner than that if possible.
 
OP
OP
ariellemermaid

ariellemermaid

Well-Known Member
View Badges
Joined
Aug 21, 2020
Messages
624
Reaction score
473
Location
North Carolina
Rating - 0%
0   0   0
And I take it back! Alexa can set my Water Change switch to Auto! So long as I just use OFF and AUTO, it’s doing exactly what I want! Thanks again!
 

When to mix up fish meal: When was the last time you tried a different brand of food for your reef?

  • I regularly change the food that I feed to the tank.

    Votes: 39 22.4%
  • I occasionally change the food that I feed to the tank.

    Votes: 60 34.5%
  • I rarely change the food that I feed to the tank.

    Votes: 55 31.6%
  • I never change the food that I feed to the tank.

    Votes: 16 9.2%
  • Other.

    Votes: 4 2.3%
Back
Top