Custom Timer Struggling to get mInput() to work

65 views
Skip to first unread message

Duane Scott

unread,
Jan 25, 2017, 6:18:18 AM1/25/17
to souliss
Hi Folks.

Please could you help me? I am having some issues getting mInput(LightSlot)=0, or mInput(LightSlot)=Souliss_T1n_OffCmd  to work on a  Nodemcu (ESP8266 12e-01) module.

I am trying to get a light to turn off after a certain time.  (The AUTOLIGHT feature did not work for me so I am trying a different approach)

The use case is:
1. Turn light on with Souliss app (or capsense button) if it is darker that the LDR threshold.
2. PIR keeps light on while there is someone present (and moving)
3. When movement stops, a timer counts down to a set threshold.
4. When the threshold is reached the light switches off.

(I will be duplicating this setup for a fan.)

Here is the snippet that I am having trouble with.

The "if" statement evaluates correctly because the debug code runs perfectly.

            if(LIGHTTIMER > 0){// If the LIGHTTIMER is greater than 0, run the countdown logic to switch the light off.
              OnTime1 = (LIGHTTIMER * 1000);
              if(millis() - PreviousMillis >= OnTime1 && mOutput(LIGHTSLOT) == 1 ){
                mInput(LIGHTSLOT) = 0;  // Turn off the light. I initially tried mInput(LightSlot)=Souliss_T1n_OffCmd but it did also not work
                if (Debug.ative(Debug.DEBUG)){
                   Debug.println("------------------------------------------------------");
                   Debug.print("mOutput(LIGHTSLOT) --- "); 
                   Debug.print("\t");
                   Debug.println(mOutput(LIGHTSLOT)); 
                   Debug.print("Previous Millis --- "); 
                   Debug.print("\t");
                   Debug.println(PreviousMillis);
                   Debug.print("Millis --- "); 
                   Debug.print("\t\t");
                   Debug.println(millis());
                   Debug.print("OnTime1 --- "); 
                   Debug.print("\t\t");
                   Debug.println(OnTime1);
                   Debug.print("Millis-PrevMillis --- "); 
                   Debug.print("\t");
                   Debug.println(millis() - PreviousMillis); 
                   delay(100);                             
                }

              }              
            }



When I move the mInput(LIGHTSLOT) =0 to this piece of code, It works as expected by switching the light off immediately after switching it on.

              if(mOutputAsFloat(LDRSLOT) < LDRTHRESHOLD){//Only allow the light to be turned on below LDR threshold.
                Logic_SimpleLight(LIGHTSLOT);   //Logic to drive the light.
                nDigOut(LIGHTOUTPUTPIN, Souliss_T1n_Coil, LIGHTSLOT);
                mInput(LIGHTSLOT) = Souliss_T1n_OffCmd; 
              }



Would you need to see the whole sketch ?




Duane Scott

unread,
Jan 25, 2017, 11:59:52 AM1/25/17
to souliss
A further update to the problem, I did more reading on the Typicals and changed the code to the following:

            if(LIGHTTIMER > 0){// If the LIGHTTIMER is greater than 0, run the countdown logic to switch the light off.
              OnTime1 = (LIGHTTIMER * 1000);
              if(millis() - PreviousMillis >= OnTime1 && mOutput(LIGHTSLOT) == Souliss_T1n_OnCmd ){
                mInput(LIGHTSLOT) = Souliss_T1n_OffCmd;  // Turn off the light.
                if (Debug.ative(Debug.DEBUG)){
                   Debug.println("------------------------------------------------------");

And now the "if" statement no longer evaluates.  This is really confusing because the Garage door example uses a similar "if" statement to turn a light off if the garage door is closed.

            // If the door or gate is open / opening, switch ON the light
            if((mOutput(GARAGEDOOR_NODE2) == Souliss_T2n_Coil_Open) || (mOutput(GARAGEDOOR_NODE2) == Souliss_T2n_LimSwitch_Open))
                mInput(GARAGELIGHT_NODE2) = Souliss_T1n_OnCmd;
            else if((mOutput(GARAGEDOOR_NODE2) == Souliss_T2n_Coil_Close) || (mOutput(GARAGEDOOR_NODE2) == Souliss_T2n_LimSwitch_Close))
                mInput(GARAGELIGHT_NODE2) = Souliss_T1n_OffCmd;

Duane Scott

unread,
Jan 25, 2017, 12:06:35 PM1/25/17
to souliss
I have been struggling with this for 2 weeks now, and am at a loss.  Can anyone help me resolve this please?  The full sketch is attached both for clarity as well as sharing.
I am not a coder at all, so the code my be bloated with all the comments I added to help me keep track of what was going on.

Thanks in advance


On Wednesday, January 25, 2017 at 1:18:18 PM UTC+2, Duane Scott wrote:
ScottysHouse_Souliss_v1.6.zip

javier gomez perez

unread,
Feb 6, 2017, 5:50:59 PM2/6/17
to souliss
Can you test with

if(((millis() - PreviousMillis) >= OnTime1) && (mOutput(LIGHTSLOT) == Souliss_T1n_OnCmd)){
mInput(LIGHTSLOT) = Souliss_T1n_OffCmd;

Reply all
Reply to author
Forward
0 new messages