Click image for larger version

Name:	cover.PNG
Views:	1292
Size:	87.5 KB
ID:	688


Demonstration



“Why uses PHPoC for this project?”. The answer is PHPoC is an IoT hardware platform which has a web server and a variant of PHP interpreter. From PHP script, We can control others device or read value from sensor an send back to client via HTTP response.



How It Works

Google Home -> Google Assistant -> IFTTT Applet->PHPoC
  • You say a phrase “turn on/off the light” to Google Home.
  • Google Home send it Google Assistant.
  • Google Assistant trigger an event to IFTTT Applet
  • FTTT Applet take action of making HTTP request to PHPoC
  • PHPoC performs a work according to that phrase (e.g. turn on/off the light)

What We Need to Do
  • Configure Google Home (e.g. Wi-Fi information, Google Account)
  • Create an IFTTT Applet
  • Writing source code on PHPoC to handle HTTP request from IFTTT applet

Configure Google Home

Refer to this link https://support.google.com/googlehom...DAndroid&hl=en


Create IFTTT Applet

An IFTTT applet include two components. “trigger and action”. IFTTT stand for “if this then that”, where “this” is trigger, “that” is action.
In this project, trigger is “turn on/off the light” which is created using “Google Assistant” service on IFTTT, and action is “Make a web request” which is created using “Maker Webhooks” service.
So, when the applet is created, “if this then that” becomes “if you say ‘turn on/off the light’ then make a web request”.
Now let’s see how to create it.

1. Create an Applet

Go to https://ifttt.com/ and log in.
Find the button “New Applet” and click

Click image for larger version

Name:	1.PNG
Views:	411
Size:	48.6 KB
ID:	675


You will see

Click image for larger version

Name:	2.PNG
Views:	325
Size:	25.1 KB
ID:	676


Click “this” button to create the trigger

2. Create Trigger

In search box, type “Google Assistant” and then click Google Assistant icon

Click image for larger version

Name:	3.PNG
Views:	337
Size:	32.4 KB
ID:	677

Click “Connect” button.

Click image for larger version

Name:	4.PNG
Views:	345
Size:	48.3 KB
ID:	678


You will be asked to login into Google account if you did not login. Note that this account must be the same as the account you set on Google Home device. After logging in, you will be back with a screen to choose trigger type. Find and Click “Say a phrase with a text ingredient”.

Click image for larger version

Name:	5.PNG
Views:	337
Size:	64.9 KB
ID:	679


Fill information as follow:

Click image for larger version

Name:	6.PNG
Views:	370
Size:	122.6 KB
ID:	680


where $ symbol represent for ingredient. Ingredient is something like argument passed from trigger to action.
For example, if you say “turn on the light”, the text “on” is ingredient and is passed to action.
Click “Create trigger” button. After creating the trigger, the following screen will be shown. Click “that” button to create the action.

Click image for larger version

Name:	7.PNG
Views:	315
Size:	25.0 KB
ID:	681



3. Create Action

In search box, type “maker”, choose “Maker Webhooks”.

Click image for larger version

Name:	8.PNG
Views:	341
Size:	42.6 KB
ID:	682


Choose make a web request

Click image for larger version

Name:	9.PNG
Views:	337
Size:	53.1 KB
ID:	683


Type URL http://domainame_or_iport_number/index.php?state=
http://domainame_or_ip/index.php?state= if the default port (80) is used
In case of you use a private IP, you need to set the port forwarding on your router or access point.
Click “Add ingredient”, select “TextField”

Click image for larger version

Name:	10.PNG
Views:	323
Size:	48.5 KB
ID:	684


Put other information as shown in below image and click “Create action” button

Click image for larger version

Name:	11.PNG
Views:	365
Size:	100.2 KB
ID:	685



4. Review and finish

Click “Finish” button

Click image for larger version

Name:	12.PNG
Views:	329
Size:	33.4 KB
ID:	686


Click “check now” button.
Click image for larger version

Name:	13.PNG
Views:	339
Size:	70.5 KB
ID:	687


Now upload source code to PHPoC and test it with Google Home

PHPoC Source Code

This code handles HTTP request from IFTTT applet and turns on/off the light

PHP Code:
<?php
    
include_once "/lib/sd_spc.php";

    
$text_ingredient  _GET("state");
    
$is_on strpos($text_ingredient"on");
    
$is_off strpos($text_ingredient"off");

    if(
$is_on !== false || $is_off !== false)
    {
        
spc_reset();
        
spc_sync_baud(115200);
        if(
$is_on !== false)
                
spc_request(144"set 0 output high");
            else
                
spc_request(144"set 0 output low");
    }
?>