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
236 stars 125 forks source link

How to change switch command words from on/off to open/close with alexa? #74

Closed andydb1 closed 4 years ago

andydb1 commented 4 years ago

Hi, I'm new to Sinric/Arduino and ESP8266s (the last programming I did was on a ZX81 back in the 1980s) I've managed to change the code of your "Simple example for how to use multiple SinricPro Switch device" sketch so that "On" command cycles relay A and "Off"command cycles relay B. Thus I can control an Electric curtain with Alexa. But I would like to use the commends "Open" and "Close" but cant figure out where these are defined as the control words for "switch" . Can you explain how to do this ( as simply as possible)? Thanks

(FYI When I first started this, I defined the Pins for the signals to the relays in the "Void Setup" with "pinMode(Pin1, OUTPUT);" but I found that on power-up or reset a brief signal was set to the pin/relay. This would have resulted in an unwanted signal to the curtain controller. I found the way to stop the signal was to move the pinMode command to the "bool onPowerState1" logic at the start ff your "* Simple example for how to use multiple SinricPro Switch device:" sketch. I dont know if this is proper coding but it stopped the bad signals.)

sivar2311 commented 4 years ago

Hi andyb1!

You cannot change the command word. These are predefined by alexa and are linked to the respective device types. But you can use a door device (supports the commmands "lock" and "unlock" or a garage door device (supports the commands "open" and "close").

The pinMode() function initializes the given PIN and the call of this function belongs to the setup() function. Otherwise the PIN will be reinitialized each time.

Immediately after calling the function you should set the PIN with your desired "start value":

void setup() {
  ...
  pinMode(Pin1, OUTPUT);
  digitalWrite(Pin1, LOW); // or HIGH...whatever you want 
  ...
}

Which ESP8266 module do you use and what have you defined as Pin1? Please note that some pins have special functions. On a NodeMCU board I recommend to use D5 to D8 (GPIO 14,12,13,15). GPIO 1 is used for serial communication. So if you have Pin1 defined as 1 you use GPIO 1 and it will collide with the output on the serial monitor.

andydb1 commented 4 years ago

Hi sivar2311, Thanks for your advice and comments. I had previously tried the Garage door sketch but with little response. My board is a LOLIN D1 Mini. As suggested I have now set it up on pins D6 and D7.

Garrage Door base code: So, following your advice I have revised that code but unfortunately I still have no voice control using the Garage Door based code. It is controllable from the Sinric Pro website/dashboard and Sinrice Pro App but not via either Alexa voice nor the Alexa app. I have tried renaming the device in the app and the dashboard and it is still not Aleaxa controlable.

Switch base code: Device named Test: Alexa does voice control the device using ON and OFF commands whatever the device is named and controllable by the Alexa App, Sinric Pro App and dashboard. By voice Alexa does execute the On/Off command but says says "Sorry Test is not responding" but does execute the command to the board. Having made your adjustments it is also responding to voice commands Open and Close ( but says "sorry curtain is not responding")

Switch based code (device named curtain) I've made your adjustments into the sketch using the Switch code, (naming the device Curtain) and now it is now responding to voice commands "Open" and "Close" (but says "sorry curtain is not responding").

So t is working now but I'm possibly more confused.

sivar2311 commented 4 years ago

The garagedoor device is limited to specific locations (by amazon). Here in germany i can't use the garagedoor device, but in the US it should work.

The message "The device is not responding" is caused by a general problem. The investigation is ongoing. It is a coincidence that this problem occurs simultaneously with yours.

andydb1 commented 4 years ago

Thanks - Now working fine based on the Switch example and responding to "open" and "close". (This is with a Gen 3 Alexa in England).

kakopappa commented 4 years ago

"Sorry device is not responding" issue has been resolved.

andydb1 commented 4 years ago

Just a brief update- my device is now working using the basic Sinric Pro switch with voice commands "Open" and "Close", device named "Curtain", and Alexa responds OK. in the Alexa app On = Open and Off = Close. So it appears that Alex evolved during my testing