---
title: "Home Automation Using OpenHab Server and Google Assistant"
url: "https://maker.wiznet.io/midnightcow/projects/Home-Automation-Using-OpenHab-Server-and-Google-Assistant/"
markdown_url: "https://maker.wiznet.io/midnightcow/projects/Home-Automation-Using-OpenHab-Server-and-Google-Assistant/md"
type: "UCC: User Created Content"
author: "midnightcow"
author_url: "https://maker.wiznet.io/midnightcow/"
original_author: "midnightcow"
original_url: "https://www.hackster.io/minnu-maria-joseph/home-automation-using-openhab-server-and-google-assistant-bfdfb1"
published: "2021-02-02"
language: "en"
hardware: ["WIZnet WIZ750SR", "WIZnet WIZwiki-W7500", "RCWL-0516"]
likes: 0
views: 629
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# Home Automation Using OpenHab Server and Google Assistant

> Home Automation Using OpenHab Server and Google Assistant

Original author: midnightcow (source: https://www.hackster.io/minnu-maria-joseph/home-automation-using-openhab-server-and-google-assistant-bfdfb1)

## Components

- **WIZnet WIZ750SR** x 1: Serial to Ethernet Gateway Module ([docs](https://docs.wiznet.io/Product/S2E-Module/WIZ750SR/))
- **WIZnet WIZwiki-W7500** x 1: mbed Borad ([docs](https://docs.wiznet.io/Product/Mbed-WIZwiki-Platform/wizwiki-w7500))
- **RCWL-0516** x 1: Mircowave sensor
- Software: **Google Assistant SDK**: Google Assistant SDK

## Article

How easy would it be if you could turn ON things just by telling them to turn ON.. With help of Google assistant that's precisely what you can do. Tell google to do it.

Add a security feature to alert you when there is a security breach in your home/room. When there is movement, you get a mail.

The components I have used are:

- Wiznet?*WIZ750SR*?serial to Ethernet module

- WIZNET W7500

- Ethernet cable and connections

- lightbulb

- Microwave motion sensor

- Google assistant app in your phone

To get started with home automaton:

Integrate google assistant(GA) with openhab.?<https://github.com/openhab/openhab-google-assistant#testing--usage-on-google-app>?is the link for that.

Link for the project demo(Part 1):?<https://youtu.be/LdSTWMUIu2Y>

![Workflow](https://hackster.imgix.net/uploads/attachments/512140/image_xBBrPgld8i.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Workflow

Initially a bulb is connected with w7500, then this board is connected to w750sr through UART. w750sr is connected to internet using ethernet. MQTT protocol is used for subscribing the status of light from oopenhab and accordingly the light is switched ON/OFF. Similarly other devices can be connected and controlled. I have used a relay in interfacing a bulb because this is a normal lightbulb and would only with AC current.

Google assistant is integrated with OpenHAB, hence when you tell google to turn on light, it is reflected in OpenHAB.

![](https://hackster.imgix.net/uploads/attachments/512139/image_obZcNsgFsP.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Here is the code for Wiznet W750sr to publisha and subscribe messages :

Subscribes the status of light and publishes security factor.

The openHAB should be updated with UUID secret and UUID password and also with your mailID. Install openhab from google store on your android. Below is the code for writing in openhab/conf/services/rules.

![The rules file to update android app](https://hackster.imgix.net/uploads/attachments/522512/image_Mp4SuTN7ng.png?auto=compress%2Cformat&w=740&h=555&fit=max)

The rules file to update android app

Once the microwave sensor senses a data immidiately the security switch turns ON and a notification is received on phone.

```
 #include "mbed.h"
#include "MFRC522.h"
#include "SPI.h"
#include "MQTTEthernet.h"
#include "MQTTClient.h"
#define ECHO_SERVER_PORT   7
// Nucleo Pin for MFRC522 reset (pick another D pin if you need D8)
//#define MF_RESET    D8
#define SPI_MOSI D11
#define SPI_MISO D12
#define SPI_SCK D13
#define SPI_CS D10
#define MF_RESET D9
//Serial connection to PC for output
Serial pc(USBTX, USBRX);
Serial a(D1,D0);
char c[100]="";
int main(void) {
   //pc.printf("starting...n");
   Serial pc(USBTX, USBRX);
   Serial a(D1,D0);
  // pc.baud(115200);
   printf("Wait a second...rn");
   char* topic = "light";
   MQTTEthernet ipstack = MQTTEthernet();
   MQTT::Client<MQTTEthernet, Countdown> client = MQTT::Client<MQTTEthernet, Countdown>(ipstack);
   char* hostname = "172.16.73.4";
   int port = 1883;
    int rc = ipstack.connect(hostname, port);
   if (rc != 0)
   printf("rc from TCP connect is %dn", rc);
   printf("Topic: %srn",topic);
   MQTTPacket_connectData data = MQTTPacket_connectData_initializer;       
   data.MQTTVersion = 3;
   data.clientID.cstring = "parents";
   if ((rc = client.connect(data)) == 0)
       printf("rc from MQTT connect is %dn", rc);
  // if ((rc = client.subscribe(topic, MQTT::QOS1, messageArrived)) != 0)
//        printf("rc from MQTT subscribe is %dn", rc); 
// 
 //Init. RC522 Chip
 while (true) {
   if (a.readable())
   {
       int i;
       c[i]=0;
       for(i=0;i<1;i++){
       char c1 =a.getc();
       c[i] = c1; 
       } 
  pc.printf("The value returned is %s ",c);
   MQTT::Message message;
   char buf[100];
   sprintf(buf, "%s", c);
    message.qos = MQTT::QOS0;
           message.retained = false;
           message.dup = false;
           message.payload = (void*)c;
           message.payloadlen = strlen(c);
           rc = client.publish("security", message);
           pc.printf("Rc result: %c n ",rc);
           client.yield(60);
            }
}
}
```

## **Schematics

### WIZW750sr

One the main component used in this project is the wiznet Wizw750SR ( S2E) and it's evaluation board.

![](https://hackster.imgix.net/uploads/attachments/512143/img_20180625_151758246_%281%29_ZiX7SVDlOX.jpg)

### The screenshot of the openHAB interface

OpenHAB server is used for publishing the status of light . As user commands ON/OFF the slider on OpenHAB also changes and it publishes this status. The w7500 subscribes this and accordingly we can change the lightbulb to ON/OFF.

![](https://hackster.imgix.net/uploads/attachments/533451/openhab_EVJMF7xpOv.jpg)

### Openhab with Google assistant

Describes the components used in this project.

### Block Diagran

this is the basic working of this project.

![](https://hackster.imgix.net/uploads/attachments/512125/capture_zXQDu0luWi.PNG)

### The screenshot of mobile notification when security switch becomes ON

![](https://hackster.imgix.net/uploads/attachments/533442/screenshot_20180725-114843_3jLAcR7wum.png)

### Receiving notification

![](https://hackster.imgix.net/uploads/attachments/533444/screenshot_20180725-114900_ZIHarFNUE0.png)

## **Code

### W7500 code

C/C++

Code for the w7500, with which the bulb is interfaced.

```
#include "mbed.h"

//DigitalOut myled(D0);
//DigitalOut buzz(D2);
//AnalogIn ldr(A0);
//AnalogIn gas(A1);
DigitalOut myled(D2);
void turnoff();
void turnon();
Serial pc(USBTX,USBRX);

Serial a(D1,D0);

int main() 
{
while(1)
{
    if(a.readable()>0)
    { 
        char c = a.getc();
        pc.printf("%c",c);
        
        
        if(c=='0')
        {
            turnoff();
            
            }
            
            if(c=='1')
        {
            turnon();
            
          }
        }
    
    }

}
  
void turnoff()
    {
        myled=0;
        pc.printf("off");
        
    }
    
void turnon()

    {
        myled=1;
         pc.printf("on");
    }
```

---

Source: https://maker.wiznet.io/midnightcow/projects/Home-Automation-Using-OpenHab-Server-and-Google-Assistant/
