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
228 stars 121 forks source link

Fetch thermostat temperature from sinric server to esp8266 on reboot #266

Closed amanjn92 closed 2 years ago

amanjn92 commented 2 years ago

Hi

I am trying to make a thermostat which regulates my AC (using IR LED acting as remote) and a fan (using relay) depending upon room temperature (using DHT11). I have been able to put everything together but am facing 1 small issue. I don't know how to fetch the thermostat temperature from the server when the device restarts.

In my code, when somebody changes the thermostat temperature, that temperature is set as low temperature (temp at which AC shuts down and Fan switches on).

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

if (controlstatus==true){ lowtemp = temperature; hightemp = lowtemp+2; }

This happens only when somebody changes the thermostat temp using Google Home. How do I make this happen everytime the device restarts or periodically say once every hour?

sivar2311 commented 2 years ago

Hello @amanjn92 !

The desired temperature is transmitted to your device in the onTargetTemperature callback. You should save the temperature in a variable so that your Sketch can access it at any time.

To "fetch" this value from the server when your device is restarted, call the function SinricPro.restoreDeviceStates(true); before calling SinricPro.begin(...).

When your device is restarted, the last value known to the server is then transferred to your device (using onTargetTemperature). So you don't need to implement anything else.

Please see the documentation for restoreDeviceStates

stale[bot] commented 2 years ago

This issue has gone quiet. Spooky quiet. We currently close issues after 14 days of inactivity. It’s been at least 7 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. As a friendly reminder, the best way to fix this or any other problem is to provide a detailed error description including a serial log. Thanks for being a part of the SinricPro community!

stale[bot] commented 2 years ago

Hey again! It’s been 14 days since anything happened on this issue, so our friendly robot (that’s me!) is going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to comment on this issue or create a new one if you need anything else. As a friendly reminder, the best way to fix this or any other problem is to provide a detailed error description including a serial log. Thanks again for being a part of the SinricPro community!