Skip to content

Instantly share code, notes, and snippets.

@kakopappa
Last active September 15, 2021 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kakopappa/ec3a1c664e116a8423ce0a6b33ed7a7d to your computer and use it in GitHub Desktop.
Save kakopappa/ec3a1c664e116a8423ce0a6b33ed7a7d to your computer and use it in GitHub Desktop.
drape and curtain
//#define ENABLE_DEBUG
#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 "SinricProBlinds.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 DRAPE_ID "" // Should look like "5dc1564130xxxxxxxxxxxxxx"
#define CURTAIN_ID "" // Should look like "5dc1564130xxxxxxxxxxxxxx"
#define BAUD_RATE 9600 // Change baudrate to your need
int drapeBlindsPosition = 0;
int curtainBlindsPosition = 0;
bool onDrapePowerState(const String &deviceId, bool &state) {
Serial.printf("Drape %s power turned %s \r\n", deviceId.c_str(), state?"on":"off");
digitalWrite(22, HIGH);
return true; // request handled properly
}
bool onDrapeRangeValue(const String &deviceId, int &position) {
Serial.printf("Device %s set position to %d\r\n", deviceId.c_str(), position);
return true; // request handled properly
}
bool onDrapeAdjustRangeValue(const String &deviceId, int &positionDelta) {
drapeBlindsPosition += positionDelta;
Serial.printf("Device %s position changed about %i to %d\r\n", deviceId.c_str(), positionDelta, drapeBlindsPosition);
positionDelta = drapeBlindsPosition; // calculate and return absolute position
return true; // request handled properly
}
bool onCurtainPowerState(const String &deviceId, bool &state) {
Serial.printf("Curtain %s power turned %s \r\n", deviceId.c_str(), state?"on":"off");
return true; // request handled properly
}
bool onCurtainRangeValue(const String &deviceId, int &position) {
Serial.printf("Device %s set position to %d\r\n", deviceId.c_str(), position);
return true; // request handled properly
}
bool onCurtainAdjustRangeValue(const String &deviceId, int &positionDelta) {
curtainBlindsPosition += positionDelta;
Serial.printf("Device %s position changed about %i to %d\r\n", deviceId.c_str(), positionDelta, curtainBlindsPosition);
positionDelta = curtainBlindsPosition; // calculate and return absolute position
return true; // request handled properly
}
// setup function for WiFi connection
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() {
// get a new Blinds device from SinricPro
SinricProBlinds &myDrape = SinricPro[DRAPE_ID];
myDrape.onPowerState(onDrapePowerState);
myDrape.onRangeValue(onDrapeRangeValue);
myDrape.onAdjustRangeValue(onDrapeAdjustRangeValue);
SinricProBlinds &myCurtain = SinricPro[CURTAIN_ID];
myCurtain.onPowerState(onCurtainPowerState);
myCurtain.onRangeValue(onCurtainRangeValue);
myCurtain.onAdjustRangeValue(onCurtainAdjustRangeValue);
// 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);
}
// main setup function
void setup() {
Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n");
pinMode(22, OUTPUT);
setupWiFi();
setupSinricPro();
}
void loop() {
SinricPro.handle();
}
@nakamuramitsuhiro
Copy link

OK Thank you for your information.

@nakamuramitsuhiro
Copy link

Hello!
Please teach me how to use gpio at ”onDrapePowerState”.

There was an error at ”if ( state == on )” in my sketch.
error:'on' was not declared in this scope

bool onDrapePowerState(const String &deviceId, bool &state) {
Serial.printf("Drape %s power turned %s \r\n", deviceId.c_str(), state?"on":"off");
if ( state == on ){
digitalWrite(PIN_SEL3, HIGH);
digitalWrite(PIN_SEL4, LOW);
delay(3000);

@kakopappa
Copy link
Author

kakopappa commented Jun 14, 2021 via email

@nakamuramitsuhiro
Copy link

Thank you for your advice.
I wii take a course.

@nakamuramitsuhiro
Copy link

Hello!

I'm worried that I can't perform the next operation for about 3 seconds after operating something. Is there any way to improve response of SINRIC APP?

@kakopappa
Copy link
Author

kakopappa commented Jun 17, 2021 via email

@nakamuramitsuhiro
Copy link

bool onDrapeRangeValue(const String &deviceId, int &position) {
Serial.printf("Device %s set position to %d\r\n", deviceId.c_str(), position);
if (position == 100){
digitalWrite(PIN_SEL3, HIGH);
digitalWrite(PIN_SEL4, LOW);
delay(val);
digitalWrite(PIN_SEL3, LOW);
digitalWrite(PIN_SEL4, LOW);
}
else if (position == 0){
digitalWrite(PIN_SEL3, LOW);
digitalWrite(PIN_SEL4, HIGH);
delay(val);
digitalWrite(PIN_SEL3, LOW);
digitalWrite(PIN_SEL4, LOW);
}
return true; // request handled properly
}

@nakamuramitsuhiro
Copy link

Hello.
I found out why my APP response is slow.
Because "return true; // Since request handled properly"
was placed after
"delay (val) ;"
, it was not possible to operate during delay (val).

@nakamuramitsuhiro
Copy link

 if (position == 100){

digitalWrite(PIN_SEL1, HIGH);
digitalWrite(PIN_SEL2, LOW);
return true; // request handled properly

delay(val);
digitalWrite(PIN_SEL1, LOW);
digitalWrite(PIN_SEL2, LOW);
}

@nakamuramitsuhiro
Copy link

However, if return true; is placed before delay (val), it will not work after delay (val).(like a above sketch)
Please let me know if there is any good solution.

@kakopappa
Copy link
Author

kakopappa commented Jun 20, 2021 via email

@nakamuramitsuhiro
Copy link

I understand how to deal with it. Still, although it will be delayed if the curtain and drape are used continuously. I will fix it a little more.
Thank you very much.

@nakamuramitsuhiro
Copy link

Please tell us a little more about your PaSS solution.

Does the content of the program written to the ESP32 change individually during mass production?
APP_KEY
APP_SECRET
Device_ID1
Device_ID2

The following is what you taught me before


  1. Sinric Pro app for iOS / Android rebranded with your brand name / logo / change color. (Without any layout changes). The app supports device provisioning. You do not have to hardcode the app / security keys. It will be sent to We will provide you a example sketch for device provisioning and OTA once you signed-up to use PaSS solution.

@kakopappa
Copy link
Author

kakopappa commented Jun 22, 2021 via email

@nakamuramitsuhiro
Copy link

Thank you . I understand.

@nakamuramitsuhiro
Copy link

The function of our automatic curtain is
① Open ② Stop ③ Close
3 actions and
③ Setting of operation time (open / stop)
④ Timer setting (wake up at 7:00, etc.)

It's different from the blinds, can you give me a special treatment?

@kakopappa
Copy link
Author

  1. Open / Stop / Close - I can update the app to add a new screen for Curtain and show Open / Stop / Close buttons
  2. Open / Stop / Close commands must respond within 8 seconds back to Alexa. This is the Alexa rule, not ours. You should send the response back immediately and process the operation in the background.
  3. Timer setting (wake up at 7:00, etc.). Schedules will be available in the future version of the app. You can always use Alexa app as well for this

@nakamuramitsuhiro
Copy link

Hello!
I am sorry for late reply.
And thank you for telling me these situation.

@nakamuramitsuhiro
Copy link

By the way,
Could you tell me the situation of v2.13x?
has already been released?


Edit Name, WiFi within 14 days (26/June) (Current Sprint) (v2.13.x)

@kakopappa
Copy link
Author

image

image

We haven't released it yet. need to fix few bugs before release this to production.

@nakamuramitsuhiro
Copy link

Okay, Thankyouforyourinformation.

@kakopappa
Copy link
Author

Schedules added.

image

@nakamuramitsuhiro
Copy link

Hello!
Please help me about schedule feature.

I'd like to try the schedule feature, but I can't find it.
The version of the app is v2.13.2, can I use it?
I'm using it on Android.

@kakopappa
Copy link
Author

kakopappa commented Sep 14, 2021 via email

@nakamuramitsuhiro
Copy link

Uploading Screenshot_20210914_215506_pro.sinric.jpg…

@nakamuramitsuhiro
Copy link

Thank you for your help.
I could found out it.

@nakamuramitsuhiro
Copy link

Screenshot_20210915_092216_pro sinric
Good morning!

About schedule,
It seems have a bug at the action input box.

Although I set action with PC, App doesn't reflect action.

Do you still know this occur?

@kakopappa
Copy link
Author

kakopappa commented Sep 15, 2021 via email

@nakamuramitsuhiro
Copy link

device type is blind

@kakopappa
Copy link
Author

image

This is what i am seeing. Can you please confirm whether device type is Blinds?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment