How to use Google Home + Blynk with ESP8266 { without " IFTTT " }

==========================================================

How to use Google Home

==========================================================

.

1 Like

What does this have to do with Blynk? And don’t you have a topic about this already?

1 Like

you are strange, man
why you didn’t ask this before.
if you do a search Topic about Google Home you will find your answer.

Amazon Echo ESP8266 control, with natural speech commands

Control ESP8266 through Google Assistant without re-flashing your ESP

[SOLVED] Anyone willing to share code for Google Assistant, IFTTT and ESP8266?

NodeMCU + Blynk + IFTTT

Is there plans for Google Home support?

Blynk x Google Home IntegrationBlynk x Google Home Integration

Blynk IFTTT , Âż possible to send push button like command?

sorry but so what ? what is your problem
the topic was mainly about Amazon Echo , now it is GH.

Hmm, defensive much :thinking:

If you do a search on how to use RobotDyn boards, servo and stepper motors, RGB lighting, probably even coffee makers… you will find people with projects using those things with Blynk and asking questions or showing what they made.

Your post and the links I followed are great for GH… but not Blynk specific, contain no Blynk instructions, are not related to any actual Blynk project or tutorial that I could see, and thus my question.

If everyone posted topics about something they did that “could” work with Blynk, but doesn’t (in the topic)… well, this forum would be full of random tech topics without actual Blynk content.

Accordingly to the category, forum members are usually sharing more details about the project, like steps, code etc.

From your post it’s not very clear what was done, how it was done, how Blynk was used, and how others can use your achievements for inspiration or learning.

It would be better if you add more details to make a topic more helpful and insightful.

Thank you.

Ze_Pico, Hi, to what service did you connect your google home? what is Sinric?
Does Sinric send web requests to Blynk cloud?
UPDATE: Ok, I’ve read about it, it seems very interesting to me, will try it later. But still don’t know how Blynk is related to it.

To turn On and Off a Power Relay with Blynk is not a problem and you can find many posts showing this.

@Jamin
“SONOFF Clone” - Mini-ESP8266 Power AC Relay Controller

part of my sketch for a (+ve) activated Relay

https://community.blynk.cc/uploads/default/original/2X/e/ebe5d9c2728649d8791ae3772d692821af2a5b63.jpg

sinric/arduino_examples/google_home_switch_example.ino

/*
 Version 0.1 - March 17 2018
*/ 

//#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space  
  #include <ESP8266WiFi.h>
  #include <BlynkSimpleEsp8266.h>

  #include <Arduino.h>  // check if working
  #include <ESP8266WiFiMulti.h>
  #include <WebSocketsClient.h> //  get it from https://github.com/Links2004/arduinoWebSockets/releases 
  #include <ArduinoJson.h> // get it from https://arduinojson.org/ or install via Arduino library manager
  #include <StreamString.h>

ESP8266WiFiMulti WiFiMulti;
WebSocketsClient webSocket;
WiFiClient client;

#define MyApiKey "<API KEY>" // TODO: Change to your sinric API Key. Your API Key is displayed on sinric.com dashboard
#define WIFI_SSID "<WIFI NAME>" // TODO: Change to your Wifi network SSID
#define WIFI_PASS "<WIFI PASSWORD>" // TODO: Change to your Wifi network password

#define HEARTBEAT_INTERVAL 300000 // 5 Minutes 

uint64_t heartbeatTimestamp = 0;
bool isConnected = false;

 
void turnOn(String deviceId) {
  if (deviceId == "5axxxxxxxxxxxxxxxxxxx") // Device ID of first device
  {  
    Serial.print("Turn on device id: ");
    Serial.println(deviceId);
  } 
  else if (deviceId == "5axxxxxxxxxxxxxxxxxxx") // Device ID of second device
  { 
    Serial.print("Turn on device id: ");
    Serial.println(deviceId);
  }
  else {
    Serial.print("Turn on for unknown device id: ");
    Serial.println(deviceId);    
  }     
}

void turnOff(String deviceId) {
   if (deviceId == "5axxxxxxxxxxxxxxxxxxx") // Device ID of first device
   {  
     Serial.print("Turn off Device ID: ");
     Serial.println(deviceId);
   }
   else if (deviceId == "5axxxxxxxxxxxxxxxxxxx") // Device ID of second device
   { 
     Serial.print("Turn off Device ID: ");
     Serial.println(deviceId);
  }
  else {
     Serial.print("Turn off for unknown device id: ");
     Serial.println(deviceId);    
  }
}

void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
  switch(type) {
    case WStype_DISCONNECTED:
      isConnected = false;    
      Serial.printf("[WSc] Webservice disconnected from sinric.com!\n");
      break;
    case WStype_CONNECTED: {
      isConnected = true;
      Serial.printf("[WSc] Service connected to sinric.com at url: %s\n", payload);
      Serial.printf("Waiting for commands from sinric.com ...\n");        
      }
      break;
    case WStype_TEXT: {
        Serial.printf("[WSc] get text: %s\n", payload);
        // Example payloads

        // For Switch  types
        // {"deviceId":"xxx","action":"action.devices.commands.OnOff","value":{"on":true}} // https://developers.google.com/actions/smarthome/traits/onoff
        // {"deviceId":"xxx","action":"action.devices.commands.OnOff","value":{"on":false}}

        DynamicJsonBuffer jsonBuffer;
        JsonObject& json = jsonBuffer.parseObject((char*)payload); 
        String deviceId = json ["deviceId"];     
        String action = json ["action"]; 

/*
//-------------------------------------------------------------------------------
// if you need echo dot + home mini   uncomment   this part

   if(action == "setPowerState")  // Switch or Light
    {   String value = json ["value"];
        if(value == "ON") {
            turnOn(deviceId);
        } else {
            turnOff(deviceId);
        }
    }
    else if(action == "setBrightness") {
        
    }
    else if(action == "AdjustBrightness") {
      
    }
//        else if (action == "SetTargetTemperature") {
//            String deviceId = json ["deviceId"];     
//            String action = json ["action"];
//            String value = json ["value"];
//        }
//--------------------------------------------------------------------------------------
 */
        
        if(action == "action.devices.commands.OnOff") { // Switch 
            String value = json ["value"]["on"];
            Serial.println(value); 
            
            if(value == "true") {
                turnOn(deviceId);
            } else {
                turnOff(deviceId);
            }
        }
        else if (action == "test") {
            Serial.println("[WSc] received test command from sinric.com");
        }
      }
      break;
    case WStype_BIN:
      Serial.printf("[WSc] get binary length: %u\n", length);
      break;
  }
}

/*--------------------------------Setup --------------------------------------*/
  void setup() {
WiFi.mode(WIFI_STA);
//  Serial.begin(115200);// See the connection status in Serial Monitor

  #ifdef LOCAL_SERVER
Blynk.begin(AUTH, WIFI_SSID, WIFI_PASS, LOCAL_SERVER ,8080);
  #else
Blynk.begin(AUTH, WIFI_SSID, WIFI_PASS, Geo_DNS_SERVER);
  #endif
while (Blynk.connect() == false) {}
  
  WiFiMulti.addAP(WIFI_SSID, WIFI_PASS);
  Serial.println();
  Serial.print("Connecting to Wifi: ");
  Serial.println(WIFI_SSID);  

  // Waiting for Wifi connect
  while(WiFiMulti.run() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  if(WiFiMulti.run() == WL_CONNECTED) {
    Serial.println("");
    Serial.print("WiFi connected. ");
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());
  }

  // server address, port and URL
  webSocket.begin("iot.sinric.com", 80, "/"); //"iot.sinric.com", 80

  // event handler
  webSocket.onEvent(webSocketEvent);
  webSocket.setAuthorization("apikey", MyApiKey);
  
  // try again every 5000ms if connection has failed
  webSocket.setReconnectInterval(5000);   // If you see 'class WebSocketsClient' has no member named 'setReconnectInterval' error update arduinoWebSockets
}

/*----------------------------------Loop--------------------------------------*/
  void loop() 
  {
Blynk.run(); // Initiates Blynk
timer.run(); // Initiates Blynk Timer
   webSocket.loop();
  if(isConnected) 
    { uint64_t now = millis();
  // Send heartbeat in order to avoid disconnections during ISP 
  // resetting IPs over night. Thanks @MacSass
    if((now - heartbeatTimestamp) > HEARTBEAT_INTERVAL) 
      {  heartbeatTimestamp = now;
        webSocket.sendTXT("H");          
      }
   }   
 }
/*----------------------------------------------------------------------------*/

Hi
this is part of a large sketch I tried to simplify
you may find errors because I removed many pages but you can correct it easily

For now, I’ve web socket connection with iot.sinric.com from my esp8266, but how to add a device in the Google home app?
In the google home app, I see: [test] Sinric, and I tried to log in, it says: “successfully linked your [test] Sinric account”, but after that I still see [test] Sinric under “add new” section, and I don’t have “linked services” section in the app at all.

My code on esp8266 (websocket part)

void webSocketEvent2(WStype_t type, uint8_t * payload, size_t length) {
switch(type) {
case WStype_DISCONNECTED:
  isConnected = false;    
  Serial.printf("[WSc] Webservice disconnected from sinric.com!\n");
  break;
case WStype_CONNECTED: {
  isConnected = true;
  Serial.printf("[WSc] Service connected to sinric.com at url: %s\n", payload);
  Serial.printf("Waiting for commands from sinric.com ...\n");        
  }
  break;
case WStype_TEXT: {
    Serial.printf("[WSc] get text: %s\n", payload);
    // Example payloads

    // For Switch  types
    // {"deviceId":"xxx","action":"action.devices.commands.OnOff","value":{"on":true}}
    // https://developers.google.com/actions/smarthome/traits/onoff
    // {"deviceId":"xxx","action":"action.devices.commands.OnOff","value":{"on":false}}

    DynamicJsonBuffer jsonBuffer;
    JsonObject& json = jsonBuffer.parseObject((char*)payload); 
    String deviceId = json ["deviceId"];     
    String action = json ["action"];
    
    if(action == "action.devices.commands.OnOff") { // Switch 
    Serial.printf("Got command to control lights from sinric.com ...\n"); 
      
        String value = json ["value"]["on"];
        Serial.println(value); 
        
       // ====== Is it ok to call my functions here, like I did? and how to do it correctly ?
        if(value == "true") {
            changeMainLight(96, 200);  // my function to control light, it means turn ON
        } else {
           changeMainLight(0, 200);    // my function to control light, it means turn OFF
        }
    }
    else if (action == "test") {
        Serial.println("[WSc] received test command from sinric.com");
    }
  }
  break;
case WStype_BIN:
  Serial.printf("[WSc] get binary length: %u\n", length);
  break;
}

It says “Waiting for commands from sinric.com” so I think it works, but I still don’t know how to control it.

how many devices you add at sinric.com

Smart Home Device
You can link with Amazon Alexa or Google Home
Click on Add button to create a smart home device

https://community.blynk.cc/uploads/default/original/2X/e/e7dac67f5f243b502555326296171bb7288916e6.png

Thanks, it works now, I forgot to add a device :smile:
It seems much faster than IFTTT.
The last question: is it possible to check temperature from my sensors? I want something like “hey google, what is the temperature in my room?”

I think this is possible with Echo dot, I didn’t try yet
https://github.com/kakopappa/sinric/wiki/Supported-devices-and-their-capabilities.

if so it will be available on GH.

At Blynk Terminal :slight_smile:

Bedroom Lights
@ is for Blynk Button
R is for RF remote
G is activated by Google Home Mini
E is activated by Amazon Echo Dot

Reception Lights

2018_06_19_14_42_24

RF Remote

@Deimos

A youtube

Amazon echo reading Temperature and Humidity from sensor

Much easier if you use Node-Red and the Alexa Home Skill Bridge, but I don’t see how this addresses the question about querying the temperature with Google Home.

Pete.

1 Like

Seems like Alexa is more DIY friendly, but I have google home.
I am disappointed in google home, because when I say “turn lights on” it turns all of the lights on, even if I assign those lights to different rooms, Do you have the same problem with commercial lights, like Philips hue, Wemo, etc?

By the way, does anyone knows how to send light state to sinric (I mean send percentage value)

This only sends on/off states successfully:

     void setPowerStateOnServer(String deviceId, String value) {
     DynamicJsonBuffer jsonBuffer;
     JsonObject& root = jsonBuffer.createObject();
     root["deviceId"] = deviceId;
     root["action"] = "setPowerState";
     root["value"] = value;
     StreamString databuf;
     root.printTo(databuf);
     webSocket.sendTXT(databuf);
    }

got this exemple from here: https://github.com/kakopappa/sinric/blob/master/arduino_examples/thermostat_example.ino

That’s correct.
You must say turn on bedroom lights or turn on living room lights,
then all lights in bedroom will turn on ( 3 lights ) or all light in living will turn on (4 lights )
If you say turn lights on then all (7 lights ) will turn on.
You can also turn one light on by saying “turn on living room A”

I must say that it is the stupidest implementation from Google.
Real life example: If you are sitting next to me and I ask you “turn on lights, please”, I am sure that you will NOT go to the attic or basement, you will turn the lights on in this very room, where you and I right now… because it is obvious… but it is not obvious for the software engineers from Google.

One might make a similar observation re: this statement :stuck_out_tongue_winking_eye:

Soooo funny :rofl: … now you want the GH device to actually think and reason? It is a computer, not an AI (be thankful). How does the device know it is in the living room, unless you specifically program it to know? Or that you are not in fact calling loudly from another room entirely?

Don’t blame the Google engineers, use common sense and be specific with your directions to the poor simple computer :wink: we are not in the 23rd century yet. :computer_mouse::brain::thinking:

image

How does the device know it is in the living room, unless you specifically program it to know?

Yes, I assign every device in the particular room in the google home app, and I do it for a reason, there is no need for AI or even neural networks here.

Or that you are not in fact calling loudly from another room entirely?

In theory, you should have a google home in every room. (if you need to control something of course) So no problems here.
Actually, in this case, you should specify in which room you want to turn lights on/off, but not all of the times like it is now. Calling GH from another room is a relatively rare event, so I would not worry about it.

I think it is a bug or misunderstanding that no one wants to fix for some reason…
As I said it is a very simple problem, because it is not related to AI at all, Google already has info about in which room every device is (except maybe smartphones).

Well, then go bring this up on the Google Home forum.

Unitil everyone thinks the exact same way (I hope that never happens), I don’t see how our creations can differentiate one’s interpretations on what “turn on the lights” mean… Heck I know some people that would still look at you dumbly and wonder exactly which light in the room you are referring to :stuck_out_tongue: