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();
}
@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