sinricpro / esp8266-esp32-sdk

Library for https://sinric.pro - simple way to connect your device to Alexa, Google Home, SmartThings and cloud
https://sinric.pro
Other
230 stars 124 forks source link

Humidity #5

Closed conuxconux closed 4 years ago

conuxconux commented 4 years ago

Is it not possible to see in the Alexa app or ask for the current humidity value? I have set both temperature and humidity but I can see and ask only for current temperature.

Many thanks

kakopappa commented 4 years ago

Alexa app - No. API does accept humidity Sinric app - Yes

conuxconux commented 4 years ago

I understand.

So besides not displaying it, isn't possible to ask Alexa for the value of humidity?

When will be Sinric pro on iOS Ita available?

Many thanks, it is a nice work!

kakopappa commented 4 years ago

@conuxconux

  1. No only temperature

  2. IOS app development has completed. We need to test it a little bit before uploading to AppStore.

There seems to be a problem your esp sending data too often to the server. How often are you sending temp details to the server?

conuxconux commented 4 years ago

Nice. I send new data to every temperature or humidity change so that it is always up to date. But I can set a reading every 5 sec if too much data arrives.

kakopappa commented 4 years ago
  1. You should send it when it changes.

  2. 30 to 60 seconds polling is a reasonable number I think.

In the real environment, temperature changes happen gradually not immediately

On Tue, 26 Nov 2019 at 1:58 PM conuxconux notifications@github.com wrote:

Nice. I send new data to every temperature or humidity change so that it is always up to date. But I can set a reading every 5 sec if too much data arrives.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/sinricpro/esp8266-esp32-sdk/issues/5?email_source=notifications&email_token=ABZAZZQ5E3AASSKSHCL5FI3QVTCIDA5CNFSM4JRQM7NKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFE56RI#issuecomment-558489413, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABZAZZSZMT4MVWIQBOTEYKTQVTCIDANCNFSM4JRQM7NA .

conuxconux commented 4 years ago

Nice. This evening I will change to 30 sec.

Many thanks for suggestions.

sivar2311 commented 4 years ago

Hi conuxonux! May i see your code where you setup device and send events? Usually SDK is limited to 1 temperature event every 60 seconds.

conuxconux commented 4 years ago

Hi conuxonux! May i see your code where you setup device and send events? Usually SDK is limited to 1 temperature event every 60 seconds.

Hi sivar2311.

This is the code:

void loop() {
  ArduinoOTA.handle();
  server.handleClient();
  delay(50);

  dht.read();

  if (dht.getState() == DHT_OK)
  {
    if (temperature != dht.getTemperatureC() || humidity != dht.getHumidity())
    {
        temperature = dht.getTemperatureC();
        humidity = dht.getHumidity();
        SinricProTemperaturesensor& mySensor = SinricPro[SENSOR_ID];
        mySensor.sendTemperatureEvent(temperature, humidity);        
    }
  }

  SinricPro.handle(); 

}
sivar2311 commented 4 years ago

Thank you. What about setup()? Anything special about creating / adding your sensor to SinricPro?

conuxconux commented 4 years ago

Thank you. What about setup()? Anything special about creating / adding your sensor to SinricPro?

This is the Setup:

void setup() {
  Serial.begin(115200);
  dht.begin();

  while (!Serial)  // Wait for the serial connection to be establised.
    delay(50);

  pinMode(led, OUTPUT);
  pinMode(rele, OUTPUT);
  digitalWrite(led, LOW);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  if (WiFi.waitForConnectResult() != WL_CONNECTED) {
    //Serial.println("WiFi Connect Failed! Rebooting...");
    blinkSignal(3, 50); 
    delay(1000);
    ESP.restart();
  }  
  ArduinoOTA.begin();

  server.on("/", []() {

    if (!server.authenticate(www_username, www_password))
      //Basic Auth Method with Custom realm and Failure Response
      //return server.requestAuthentication(BASIC_AUTH, www_realm, authFailResponse);
      //Digest Auth Method with realm="Login Required" and empty Failure Response
      //return server.requestAuthentication(DIGEST_AUTH);
      //Digest Auth Method with Custom realm and empty Failure Response
      //return server.requestAuthentication(DIGEST_AUTH, www_realm);
      //Digest Auth Method with Custom realm and Failure Response
    {
      blinkSignal(2, 100); 
      return server.requestAuthentication(DIGEST_AUTH, www_realm, authFailResponse);
    }

    if(server.args() != 1)
    {
       blinkSignal(4, 50);   
       server.send(200, "text/plain", "0");
    }
    else
    {
      if(server.argName(0) == "rele")
      {
          SinricProTemperaturesensor& mySensor = SinricPro[SENSOR_ID];
          if(server.arg(0) == "1")
          {
            digitalWrite(rele, HIGH);
            //digitalWrite(led,high);
            server.send(200, "text/plain", "1");
            // send powerstate event
            mySensor.sendPowerStateEvent(HIGH); // send the new powerState to SinricPro server            
          }
          else if(server.arg(0) == "0")
          {            
            digitalWrite(rele, LOW);
            //digitalWrite(led,low);         
            server.send(200, "text/plain", "0");
            // send powerstate event
            mySensor.sendPowerStateEvent(LOW); // send the new powerState to SinricPro server                  
          }
          else
          {
            bool relState = digitalRead(rele);
            server.send(200, "text/plain", String(relState));
            mySensor.sendPowerStateEvent(relState); // send the new powerState to SinricPro server   
          }

      }
      else if(server.argName(0) == "sensor")
      {   
        dht.read();
        if (dht.getState() == DHT_OK)
        {
          temperature = dht.getTemperatureC();
          humidity = dht.getHumidity();
          //digitalWrite(led, low);
          server.send(200, "text/plain", "Temperatura " + String(temperature, FLOATROUNDING) + " C\nUmidita' " + String(humidity, FLOATROUNDING) + " %");
          //digitalWrite(led, high);
          SinricProTemperaturesensor& mySensor = SinricPro[SENSOR_ID];
          mySensor.sendTemperatureEvent(temperature, humidity);          
        }
        else
        {
          server.send(200, "text/plain", "Cannot read sensor!");
        }
      }

    }
  });
  server.begin();
  blinkSignal(2, 1000);
  digitalWrite(led, HIGH);

  // create and add a Sensor to SinricPro
  SinricProTemperaturesensor& mySensor = SinricPro[SENSOR_ID];
  // set callback function
  mySensor.onPowerState(onPowerState);
  // startup SinricPro
  SinricPro.begin(APP_KEY, APP_SECRET);  
}
sivar2311 commented 4 years ago

Hi @conuxconux Thank you for your support. Version 2.2.3 has been released. Please update. New release will prevent flooding the server but it is always good way to send events only when state or values have been changed.

conuxconux commented 4 years ago

Many thanks @sivar2311. I have a had changed the routine to update the data every 30 sec if one of the values is changed.

sivar2311 commented 4 years ago

Hi @conuxconux! Have a look at our new examples for TemperatureSensor:

conuxconux commented 4 years ago

Hi @sivar2311 , many thanks for the suggestion and update.

I have already changed my code with following approach:

void updateData(void)
{
  uint64_t now = millis();
  if ((now - lastRead) > INTERVAL_UPDATE) 
  {  
    dht.read();

    if (dht.getState() == DHT_OK)
    {  
      if (temperature != dht.getTemperatureC() || humidity !=  dht.getHumidity())
      {
        temperature = dht.getTemperatureC();
        humidity =  dht.getHumidity();

        SinricProThermostat& mySensor = SinricPro[SENSOR_ID];
        mySensor.sendTemperatureEvent(temperature, humidity); 
        mySensor.sendTargetTemperatureEvent(humidity);

        lastRead = now;

-------

In this mode for any change in the interval i can see new value because I use the Thermostat to see the humidity as Target Temperature in Alexa App and I can ask to Alexa for the current Target Temperature to obtain the current humidity, than I update when I detect any change. With your sample you can detect any change if both are changed.

if (temperature == lastTemperature || humidity == lastHumidity) return; // if no values changed do nothing...

Thank you 👍

sivar2311 commented 4 years ago

Your code looks good, except two things:

1) You're using the wrong device! For sensor, please use SinricProTemperaturesensor

2) sendTargetTemperatureEvent is for Thermostat! Please remove this code for your temperature sensor, since this is only a sensor!

sendTargetTemperature is used when you change the "targetTemperature" on your Thermostat manually, to report new target temperature back to SinricPro server.

conuxconux commented 4 years ago

Oh yes, @sivar2311 I have update the previous post. : )

sivar2311 commented 4 years ago

Oh, so you're "missusing" targetTemperature to report humidity?

conuxconux commented 4 years ago

Yesss... to see it in Alexa App and to ask she the target temperature and obtain current humidity. It is a workaround to obtain both. ;)

conuxconux commented 4 years ago

This is the control in Alexa app

B7360297-133E-463A-959F-247980B85A01

sivar2311 commented 4 years ago

Okay, creative way to use some functionallity that alexa doesn't offer right now...

santiagoarroyo22 commented 4 years ago

@conuxconux would you be so kind of posting the full code to read the temperature in the alexa app, I have been working on it, I have the DHT readings on the serial monitor of arduino but it seems like I cant send that variable to the alexa app. Thank you in advanced.

conuxconux commented 4 years ago

@conuxconux would you be so kind of posting the full code to read the temperature in the alexa app, I have been working on it, I have the DHT readings on the serial monitor of arduino but it seems like I cant send that variable to the alexa app. Thank you in advanced.

Hi @santiagoarroyo22 , i haven't write an app for alexa.

After, I can see new added Sinric Pro device that will be update with sended data from esp8266.

You can refer to the following sample: https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/examples/temperaturesensor/temperaturesensor.ino

santiagoarroyo22 commented 4 years ago

@conuxconux thank you so much, that is another point of view of what I was looking for by I think I can change some stuff to fit my idea, have a great day