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

trying to read garage door state #37

Closed h16bill closed 4 years ago

h16bill commented 4 years ago

I need to read a switch (actually hall effect sensor) to determine if the the garage door is open or closed. I didn't see a way to do this using the garage door interface. I tried adding a switchContact device and it seems to work but I do not know how to get Alexa to tell me the state of the switch. When I check the Alexa app it just shows the switch power state which I think is seperate from the actual switch reading. garageForUpload.txt

sivar2311 commented 4 years ago

Use the sendDoorStateEvent(bool mode) function provided by SinricProGarageDoor class mode = false means open, true means closed.

Currently this device type is supported by amazon in alexa app only in the US.

h16bill commented 4 years ago

I made that change and that seems to send the state but Alexa still won't tell me if the door is open or closed. Alexa "is the garage door open" she says "checking", and then "I don't know about the garage door".

After telling Alexa to close the door, the serial monitor says the door is closed regardless of the switch. The doorState is coming with the onDoorState callback in response to asking Alexa to open/close the door.

The Alexa app shows the garage door but no open or closed state that I can see. Is there a different way to ask Alexa if the door is open? Without the door open status this is of limited use.

sivar2311 commented 4 years ago

I made that change and that seems to send the state but Alexa still won't tell me if the door is open or closed. Alexa "is the garage door open" she says "checking", and then "I don't know about the garage door".

I think this isn't supported by amazon right now

After telling Alexa to close the door, the serial monitor says the door is closed regardless of the switch. The doorState is coming with the onDoorState callback in response to asking Alexa to open/close the door.

This is because your code doesn't check the door state in the callback:

bool onDoorState(const String& deviceId, bool &doorState) {
  digitalWrite(relayPin, LOW);
  delay(750);
  digitalWrite(relayPin, HIGH);
  Serial.printf("Garagedoor is %s now.\r\n", doorState?"closed":"open");
  return true;
}

After sending your relay commands (digitalWrite low/high) you should check your sensor. Depending on what your sensor is, set the doorState variable to return current state.

Assume your hallSensor is LOW on OPEN and HIGH on CLOSE position:

bool onDoorState(const String& deviceId, bool &doorState) {
  digitalWrite(relayPin, LOW);
  delay(750);
  digitalWrite(relayPin, HIGH);
  // get and return current door state (doorState variable is a reference you can write to, to return current door State)
  doorState = digitalRead(hallPin);
  Serial.printf("Garagedoor is %s now.\r\n", doorState?"closed":"open");
  return true;
}

The Alexa app shows the garage door but no open or closed state that I can see. Is there a different way to ask Alexa if the door is open? Without the door open status this is of limited use.

That's what i am saying about "only US". Do you have an US alexa account?

h16bill commented 4 years ago

Yes, i have a US account. I see the callback passes doorState by pointer. So I can change that in the callback and it gets returned. Unless I hold that call it won't reflect the change. So it takes the opener about 45 seconds to close. Then the handleDoorClosedSensor procedure will call sendDoorStateEvent to update the door state. So the app won't show the state. Is there any way to ask Alexa for the door state?

Just tried the TemperatureSensor device. The name is sensor. The app shows just temperature, no humidity. If I ask Alexa what the sensor temperature is, she tells me. If I ask what the sensor humidity is she says that isn't supported yet.

sivar2311 commented 4 years ago

Ok, that's few things together in one ... Before Alexa GarageDoor device was available, we used a SmartLock device for this. I can send you the SinricPro sketch for this. (I think GarageDoor is not completly done yet by amazon / alexa).

45 seconds are way to long. Alexa needs a response within 8 seconds. So you have to update the state later. (Checking your hall sensor periodicly...if state have changed, send Event to SinricPro. This will update the state in the alexa app).

Is there any way to ask Alexa for the door state?

Only if this is provided by amazon / alexa. Seems it is not implemented yet.

If I ask what the sensor humidity is she says that isn't supported yet.

Alexa doesnt support humidity sensor. This is a SinricPro only feature. You can see the humidity in dashboard.

Edit: Link to garage door opener by using a SinricPro Lock: https://gist.github.com/sivar2311/d7132e4f61d913d30264bcea7200de7d This sketch using 2 reed switches as endstop for the garage door.

Edit2: See this sketch in action: https://www.youtube.com/watch?v=MEldgAsJpIQ&list=PLBBwDRJllVpoS3serHjl-XEoWkIrUsJjG

h16bill commented 4 years ago

That is a nice example. Thank you. So it looks like Alexa only knows locked and unlocked states for this one. Not open and closed.

sivar2311 commented 4 years ago

Yes, because it's using a "Lock".

The "Garage door" device was introduced later by amazon. And i think it is not fully functional yet. That might be the reason this is available only in the US. If i add such device to my german account, i only see the minimum setup page in alexa app :(

h16bill commented 4 years ago

Thank you for all your help. Maybe if I get ambitious I will go through AWS and try implementing it. thanks Bill