If door is opened, PHPoC sends a message to your Facebook Messenger.


Hardware components
× 1
Adafruit Magnetic Contact Switch
× 1
Software apps and online services




Demonstration






System Architecture

Wiring
  • One pin to GND.
  • Another pin to 11.



How to Create IFTTT Applet


Follow 12 steps (see red square)



1. Create Applet




2. Set Trigger




3. Search "Webhooks" and click Webhooks





4. Choose "Receive a web request"




5. set Event Name is "door_open" and click "Create trigger" button





6. Click "+that" button to create the action




7. Search "Facebook Messenger" and click





8. Choose Action "Send message". It needs to connect to Facebook for the first time.




9. Create the content of message and then click "Add ingredient" button





10. Choose "OccurredAt". This is time of door open.





11. Click "Create action" button




12. Click "Finish" button

Now Applet is created. Get Webhooks Key


Go to this link https://ifttt.com/maker_webhooks

Click "Documentation" to see the Webhooks Key.



Copy the Webhook Key and put it in PHPoC code
PHP Code:
<?php

if(_SERVER("REQUEST_METHOD"))
    exit; 
// avoid php execution via http request

include_once "/lib/sn_http_b2.php";
include_once 
"/lib/sd_340.php";

define("IFTTT_WEBHOOKS_KEY""xxxxxxxxxxxxxxxxxxxxxx"); // change your webhooks key here

function send_notification()
{

    
$url "https://maker.ifttt.com/trigger/door_open/with/key/" IFTTT_WEBHOOKS_KEY;
    
$resp_head http_request("GET"$url"");
    
$resp_body "";

    if(
$resp_head !== "")
        
$rlen http_read_sync($resp_body);

    
http_close();

    echo 
"$resp_body\r\n";
}

uio_setup(011"in_pu");  // configuring pin 11 of the UIO 0 to input with pull-up

$previous_status 1;

while(
1)
{
    
$current_status uio_in(011); ;

    if(
$previous_status == && $current_status == 1) { // if door is opened...
        
echo "door is opened\r\n";
        
send_notification();
        
usleep(100000);
    } else if(
$previous_status == && $current_status == 0) { // if door is closed...
        
echo "door is closed\r\n";
    }

    
$previous_status $current_status;
}
?>