ChipChop Support Forum
Log in
Log out
Join the forum
My Details
REPLIES: 8
VIEWS: 218
BACK
REPLY TO THIS POST
Svetlana Simic
09 Nov 2023
Actions help
Hello,

I have a small problem making one action. Here is an explanation, I want to make a door bell with 2 different parts.

Part 1 is the door bell (button) outside the house with esp8266 number 1
Part 2 is speaker inside the house with esp8266 number 2

I have strong wifi so distance is not a problem, I just want simply to make an "action" when "esp 1" button is pressed "esp 2" receive command ON for speaker component and play sound but also my kids can use web app to "ping" the house if in problem (different sound on esp2)

I've tried this on breadboard but it works ok first time button is pressed (action works ok) but after that nothing and have to restart the esp to work but only one time?

summocoder
09 Nov 2023

any code to see?
Svetlana Simic
09 Nov 2023

sorry ok, here is just simple part for send/receive (I do button debounce no problems not including that). Sorry, english not main language so I've translate variables I hope it's ok

It's very simple:

ESP 1 - door bell button

void loop(){
    
    if(digitalRead(buttonPin) == LOW){

        //debounce and if ok

        triggerEvent("button1","ON");

    }

}

ESP 2 - speaker

void ChipChop_onCommandReceived(String component,String value, String source, int age){

if(component == "sound1"){
if(value == "ON"){
playSound(1);

}

}
    if(component == "sound2"){
    if(value == "ON"){
         playSound(2);
         }
    }
}


Action

Trigger Device = Door Bell
Trigger Component = button1
Value Is = ON
Target = Speaker
Target Component = sound1
Value = ON

I want also to make Action 2 but trigger is fake Button 2 component in Door Bell device to use in Web App

Thank you for help
summocoder
09 Nov 2023
ACCEPTED

I think I know what is the problem @Svetlana
Your speaker code looks fine, it's the button that needs changing a little bit.

As far as I understand Actions will only run if the Trigger Component > Value has changed from previous one.

Basically, the first time you press the button and send the triggerEvent the state of that button will become ON.
Next time you press it it will try to execute the action but because it's already ON that means there was no change so the action ignores it.

What you need to do is to "reset" the button after it has been pressed. I mean not physically, you just need to tell ChipChop that the button is gone into an OFF state. It's a good practice anyway otherwise you will permanently see that button as being ON.

I would be careful not to use another triggerEvent straight away but maybe wait half a second, it's same thing as a debounce, you are practically blocking the button for a little bit before the next press.


Something like this




unsigned long buttonReset = 0;
int canReset = 0;

void loop(){

    if(digitalRead(buttonPin, LOW){
        
        ......your code here

        ChipChop.triggerEvent("button_1","ON");
        buttonReset = millis();    
        canReset = 1;
    }

    //and then somewhere later
    
    if(canReset == 1){
        if(millis() - buttonReset > 500){
            ChipChop.triggerEvent("button_1","OFF");
            canReset = 0;
        }
    }
    

}



I think that should work
FreeWilly
09 Nov 2023

I would just be careful with the number of triggerEvents sent!

I've made my own doorbell with a pretty much same setup but my postman is an idiot and can press the button like 1000000 times a second so what I do is to send an event on the first press and then cache subsequent presses for 10 seconds so if there are more presses I send just one more event.

It's actually ok to get the bell in the house ring once more just in case you didn't hear it the first time.
summocoder
09 Nov 2023

@FreeWilly ah, not just a pretty face :-) That's not a bad idea at all.
FreeWilly
09 Nov 2023

@Sumocoder how do you know, you've never seen my face! Ok, it is pretty good looking face I admit, and I am quite tall for my hight.
Svetlana Simic
09 Nov 2023

That works! How simple

Thank you
kennyFx
22 Nov 2023

I've gone few steps further with my doorbell (same story with a lunatic postman) so now I have a motion sensor that when it detects motion nearby "arms" a gesture sensor (APDS-9960) and when that detects the stinky finger in it's proximity it fires the doorbell.

The button on the doorbell is just for show, not wired to anything :-))

Haven't missed a single delivery so far but I may add an extra ding-dong after few seconds.