sinricpro / non-sdk-issues

Report non sdk related issues here (Alexa, Google Home, SmartThings, IFTTT, API)
2 stars 0 forks source link

Current Temperature - Thermostat example - Google Home app #43

Closed pmsalvino closed 2 years ago

pmsalvino commented 2 years ago

Hi! I’ve tried the Thermostat example to replace the Temperature Sensor example and I’ve found 2 issues: 1- There is no place (in example) to send to Google Home and SinricPro webpage current temperature as available in the Temperature Sensor example. Is it enough to include “SinricProTemperaturesensor &mySensor = Sinric Pro [TEMP_SENSOR_ID];” to get current temperature to both? If not, any plans to make it available? 2- If I change Thermostat mode using SinricPro webpage, Google Home device mode doesn’t update mode (at least not after 2 minutes). Is it expected to be this way?

I’ve looked for an email address to send this issues but I couldn’t find one at SinricPro webpage. Could you confirm which email address should be used?

thanks in advance.

sivar2311 commented 2 years ago
  1. SDK-Related question: Thermostat also have sendTemperatureEvent function - see documentation SDK related issues are tracked and answered via github issues - this is the right place :)

  2. Server-Related question @kakopappa can you check this please?

pmsalvino commented 2 years ago

Hi sivar2311! Thanks for the quick reply. I’ll read the documentation more carefully and I’ll try to include sendTemperatureEvent in the example. I give you feedback as soon as I finish it. I’ll try to send mode to the server too as part of the project I’m developing which also includes Blynk (Blynk part os finished). I aim to send commands to NodeMCU using Google Home and SinricPro.

pmsalvino commented 2 years ago

Hi

Hi sivar2311! Thanks for the quick reply. I’ll read the documentation more carefully and I’ll try to include sendTemperatureEvent in the example. I give you feedback as soon as I finish it. I’ll try to send mode to the server too as part of the project I’m developing which also includes Blynk (Blynk part os finished). I aim to send commands to NodeMCU using Google Home and SinricPro.

Hi! I have news after trying sendTemperarureEvent based on Thermostat example. I managed to send current temperature to SinricPro and Google Home app. Great! But.....It didn't work when i tried to do the same using ### sendThermostatModeEvent. I've checked Serial Monitor using Arduino IDE and i get reply from server that both events were sent....but Mode didn't change, just Temperature.

I'm willing to share Sketch (I had to do some changes in the available example) and provide any other information.

Once again....regarding point 2 in my first post: Google Home app doesn't update temperature and mode when it is done by SinricPro side. I'm not sure if it is a SinricPro Issue, but definately it is not desirable behavior. In order to see updated Temperature and Mode in Google Home App, i need to come back to Main page and then back to Device's Icon.

kakopappa commented 2 years ago

Hi @pmsalvino

The earlier issue with the Temperature Sensor device type is fixed from the server-side. UI is set to "cool" mode by default and you should be able to see the temperature without the UI glitch in the Google Home app.

If you still want to use a Thermostat device type: What mode did you send? it should be AUTO, COOL, HEAT. I recommend going with "COOL"

The core issue is in the Google Home app does not support Temperature sensors so we had to do a workaround fix to show the temperature in the app rather than the Google Home app showing a dumb UI.

pmsalvino commented 2 years ago

Hi @kakopappa! Answering your question: I’ve tried all 3 modes (AUTO, COOL and HEAT). I’ve tried to be careful about spelling and also with Capital Letters. I believe Thermostat example is better for my project than Temperature Sensor as Thermostat allows me to send command from Google Home app. I plan to use mode to turn my Water Heater display on and off (I can already do it using Blynk). At this point, sending mode from NodeMCU to SinricPro / Google Home app is the only desirable feature I can’t perform so far. Have you tried sendThermosthatModeEvent function with any of available examples? Did it work? At least it would be useful if I find out that it’s not working due to my poor code skills. I appreciate if you can try the sendThermosthatModeEvent in any sketch. Another point: Is there any way to track events sent by my device to SinricPro? If so, I can send you information from Serial Monitor so you can track how far my event goes. And….thank you for the reply about Google Home app update. It is something that I’ll have to deal with.

kakopappa commented 2 years ago

Hi @pmsalvino

Here's the sketch I used for testing. It sends random values to Google Home every 1 min. I can see the latest values are reflected in the app correctly. if you leave the thermostat screen open, it does not automatically refresh. You have to close the thermostat window and reopen it to see the latest values

  1. You can use #define ENABLE_DEBUG to see what's SDK sending / receiving from server
  2. Why do you use Blynk/Sinric pro both instead of one?
#define ENABLE_DEBUG // << Enable logs

#ifdef ENABLE_DEBUG
       #define DEBUG_ESP_PORT Serial
       #define NODEBUG_WEBSOCKETS
       #define NDEBUG
#endif 

#include <Arduino.h>
#ifdef ESP8266 
       #include <ESP8266WiFi.h>
#endif 
#ifdef ESP32   
       #include <WiFi.h>
#endif

#include "SinricPro.h"
#include "SinricProThermostat.h"

#define WIFI_SSID         ""    
#define WIFI_PASS         ""
#define APP_KEY           ""      // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
#define APP_SECRET        ""   // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
#define THERMOSTAT_ID     ""    // Should look like "5dc1564130xxxxxxxxxxxxxx"
#define BAUD_RATE         9600                     // Change baudrate to your need

float globalTemperature;
bool globalPowerState;

SinricProThermostat &myThermostat = SinricPro[THERMOSTAT_ID];

bool onPowerState(const String &deviceId, bool &state) {
  Serial.printf("Thermostat %s turned %s\r\n", deviceId.c_str(), state?"on":"off");
  globalPowerState = state; 
  return true; // request handled properly
}

bool onTargetTemperature(const String &deviceId, float &temperature) {
  Serial.printf("Thermostat %s set temperature to %f\r\n", deviceId.c_str(), temperature);
  globalTemperature = temperature;
  return true;
}

bool onAdjustTargetTemperature(const String & deviceId, float &temperatureDelta) {
  globalTemperature += temperatureDelta;  // calculate absolut temperature
  Serial.printf("Thermostat %s changed temperature about %f to %f", deviceId.c_str(), temperatureDelta, globalTemperature);
  temperatureDelta = globalTemperature; // return absolut temperature
  return true;
}

bool onThermostatMode(const String &deviceId, String &mode) {
  Serial.printf("Thermostat %s set to mode %s\r\n", deviceId.c_str(), mode.c_str());
  return true;
}

void setupWiFi() {
  Serial.printf("\r\n[Wifi]: Connecting");
  WiFi.begin(WIFI_SSID, WIFI_PASS);

  while (WiFi.status() != WL_CONNECTED) {
    Serial.printf(".");
    delay(250);
  }
  IPAddress localIP = WiFi.localIP();
  Serial.printf("connected!\r\n[WiFi]: IP-Address is %d.%d.%d.%d\r\n", localIP[0], localIP[1], localIP[2], localIP[3]);
}

void setupSinricPro() {

  myThermostat.onPowerState(onPowerState);
  myThermostat.onTargetTemperature(onTargetTemperature);
  myThermostat.onAdjustTargetTemperature(onAdjustTargetTemperature);
  myThermostat.onThermostatMode(onThermostatMode);

  // setup SinricPro
  SinricPro.onConnected([](){ Serial.printf("Connected to SinricPro\r\n"); }); 
  SinricPro.onDisconnected([](){ Serial.printf("Disconnected from SinricPro\r\n"); });
  SinricPro.begin(APP_KEY, APP_SECRET);
}

void setup() {
  Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n");
  setupWiFi();
  setupSinricPro();
}

int interval = 60000;
int previousMillis = 0;

void loop() {
  SinricPro.handle();

  if (millis() - previousMillis > interval) {
    previousMillis = millis();             

    Serial.printf("Sending temperature !\r\n");
    int temperature = random(20, 30);
    int humidity = random(30, 40);
    myThermostat.sendTemperatureEvent(temperature, humidity); // send event

    Serial.printf("Sending mode !\r\n");
    myThermostat.sendThermostatModeEvent("HEAT"); // send event

    Serial.printf("Sending target temperature !\r\n");
    int targetTemperature = random(10, 20);
    myThermostat.sendTargetTemperatureEvent(targetTemperature); // send event
  }
}

image

pmsalvino commented 2 years ago

myThermostat.sendThermostatModeEvent("HEAT"); // send event

Hi @kakopappa! Answering your questions: 1- Okey, I'll enable debug so i can see what SDK is sending to and receiving from the server. 2- I intend to use both (SinricPro and Blynk) due to positive points in each plataform. Example: Blynk 1- Provide Notification in which Blynk app (mobile phone) notify me when something wrong happens to the water heater (Erro 12 in LCD screen - stop heating water); 2- Blynk allows me update data more often. It is useful to see that Temperature in raising among minutes (default SinricPro update interval is 1 minute - too long to check temperature changes when Water Heater starts working); 3- I can share Blynk app with my family. SinricPro 1- Allows me to see data from Nodemcu in Google Home app and ask question about it to the Google Home Mini Speaker (I've already tried it. It works fine!); 2- Allows me to control NodeMCU from Google Home app and Speaker (Google Home Mini) - I need to develop the code to link myThermostat.onXXXX() to existing functions in my Blynk Sketch (turn on / off - adjust heating intensity);

My main goal is to have Speaker to warn me if there is a Error in Water Heater (So far it only seems to be possible using NodeRed plus a dedicated Ubuntu Server (even virtual).

After reading your Sketch, i quickly realise 1 diference in sendThermosthatModeEvent:

Yours: myThermostat.sendThermostatModeEvent("HEAT"); // send event Mine: bool success2 = myThermostat.sendThermostatModeEvent(mode); // send event

I've declared mode variable in parenthesis, not the work between "". I'll change my Sketch now and give you feedback in minutes. Once again: Thank you very much for your support.

kakopappa commented 2 years ago

Thanks for the feedback

For TTS you may want to try this.

https://github.com/horihiro/esp8266-google-tts

On Fri, 3 Jun 2022 at 10:08 AM pmsalvino @.***> wrote:

myThermostat.sendThermostatModeEvent("HEAT"); // send event

Hi @kakopappa https://github.com/kakopappa! Answering your questions: 1- Okey, I'll enable debug so i can see what SDK is sending to and receiving from the server. 2- I intend to use both (SinricPro and Blynk) due to positive points in each plataform. Example: Blynk 1- Provide Notification in which Blynk app (mobile phone) notify me when something wrong happens to the water heater (Erro 12 in LCD screen - stop heating water); 2- Blynk allows me update data more often. It is useful to see that Temperature in raising among minutes (default SinricPro update interval is 1 minute - too long to check temperature changes when Water Heater starts working); 3- I can share Blynk app with my family. SinricPro 1- Allows me to see data from Nodemcu in Google Home app and ask question about it to the Google Home Mini Speaker (I've already tried it. It works fine!); 2- Allows me to control NodeMCU from Google Home app and Speaker (Google Home Mini) - I need to develop the code to link myThermostat.onXXXX() to existing functions in my Blynk Sketch (turn on / off - adjust heating intensity);

My main goal is to have Speaker to warn me if there is a Error in Water Heater (So far it only seems to be possible using NodeRed plus a dedicated Ubuntu Server (even virtual).

After reading your Sketch, i quickly realise 1 diference in sendThermosthatModeEvent:

Yours: myThermostat.sendThermostatModeEvent("HEAT"); // send event Mine: bool success2 = myThermostat.sendThermostatModeEvent(mode); // send event

I've declared mode variable in parenthesis, not the work between "". I'll change my Sketch now and give you feedback in minutes. Once again: Thank you very much for your support.

— Reply to this email directly, view it on GitHub https://github.com/sinricpro/non-sdk-issues/issues/43#issuecomment-1145540857, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABZAZZVYSIO4PENLHCAZ2U3VNFZK3ANCNFSM5WQHXYGQ . You are receiving this because you were mentioned.Message ID: @.***>

pmsalvino commented 2 years ago

@kakopappa it works! Your Sketch allowed me to set mode, target temperature, temperature from NodeMCU to Google Home App. This time i didn't get to device's screen in Google Home app, i've stayed at main page and it made easier to see changes in: Mode, TargetTemperature & Temperature. One remark: Despite working at Google Home, at SinricPro Webpage TargetTemperature and Mode didn't update, just current (internal) temperature. For me, it's not a big deal, but i think i should let you know about it.

Now i have to do a couple of adjustment to my existing sketch. I think we can close the issue. I'll wait until tomorrow (in case you want to provide any reply) to close.

Thanks.