BrettSheleski / SmartThingsPublic

36 stars 23 forks source link

Sonoff basic with GPIO14 #3

Open marknguy opened 6 years ago

marknguy commented 6 years ago

Hello,

I'm trying to turn a Sonoff Basic into a garage door controller. Here's what I did so far and and I just wanted to share. I'm sure this could be improved upon for all to benefit.

Modified Sonoff Basic into a dry contact Flash Sonoff with Tasmoto (v 5.11.1) Go into Web GUI and made these configuration changes:

Seems to work well. To determine if the garage door is open, I have to go into details of the device and click the refresh button.

It would be nice if the toggle switch icon did not stay ON since I only want a momentary button.

BrettSheleski commented 6 years ago

This is good info, thanks for sharing.

I actually have a Sonoff 1 channel relay setup for controlling my garage door opener using the unmodified device handler. I set the pulsetime to 2 (200 milliseconds) instead of 4 (400 milliseconds) and everything seems to work.

I intend on writing a new device handler and/or SmartApp to combine separate momentary pushbutton devices and door sensor devices to a single actual "proper" garage door opener device.

I also intend on developing a set of replacement device handlers for this device handler. The thought is that the user would specify the IP address of the Sonoff device in one SmartThings device. This device would not actually be a useful device by the user. Instead, it would make an HTTP request to the Sonoff and determine its module type. Depending on that the SmartThings device handler would spawn potentially numerous child devices that the user would end up actually using. Also, it could read the configuration of the GPIO to spawn additional devices to be used by the user. This is not 100% thought out, but I think it will work out well.

marknguy commented 6 years ago

Do you know if it's possible to "poll" before you issue the "toggle"? And based on whether the door was open or closed, it would use the icon "st.doors.garage.garage-closing" or "st.doors.garage.garage-opening"?

BrettSheleski commented 6 years ago

You'd need a separate sensor to determine the state of the door. Especially since the door can also be triggered via the in-car remote as well as the on-wall button.

As I've stated before. I'm working on making a device handler and/or SmartApp for this situation where you have a momentary device (eg: a Sonoff running Tasmota) and contact sensor device. You'd be able to combine the two to create a "proper" garage door device. I just gotta find the time to develop it.

BrettSheleski commented 6 years ago

Sorry, I think I misread what you had posted.

If you're just worried about displaying the correct icon you could modify the poll method to check the current state and modify the icon accordingly.

It sounds like you might want to add the garage door opener capability to the device handler and therefore you'd have the proper state values to use.

marknguy commented 6 years ago

Sorry, I probably was not clear. With the changes I made, the poll() retrieves the status of the sensor on GPIO14 (which is a reed switch connected to the garage door). The door opener is the built-in relay on the sonoff (modified so the mains are not connected so the relay acts as a dry contact switch).

So I'm looking for a way to do this when the garage is activated: (note SwitchState=ON when door is closed, OFF when door is open)

if SwitchState="OFF", then On() and use the st.doors.garage.garage-closing icon. Pause for 15 seconds, then change the icon to st.doors.garage.garage-closed.

if SwitchState="ON", then On() and use the st.doors.garage.garage-opening icon. Pause for 15 seconds, then change the icon to st.doors.garage.garage-open.

BrettSheleski commented 6 years ago

I'd recommend removing the switch capability and implement the Garage Door Control capability instead.

See https://smartthings.developer.samsung.com/develop/api-ref/capabilities.html

This would mean removing the on() and off() methods and instead implement open() and close() in their place

This would also remove the on and off attributes, but instead you could use the open, closed, opening, and closing attributes. Then you could just tie the tile image to the appropriate state of the garage door control capability.

Fork my repo, I may submit a pull request with something you could try.

marknguy commented 6 years ago

Oh ok, thanks for pointer. I'll give that a shot later this week. I'm busy with work until this weekend.

zybeon commented 6 years ago

Very interested in this. Any updates? I have a two car garage so it would probably take a little more work for me.

BrettSheleski commented 6 years ago

I've been developing a new implementation of SmartThings device handlers for devices running the Tasmota firmware.

Check out https://github.com/BrettSheleski/SmartThingsPublic/tree/master/devicetypes/BrettSheleski/tasmota.src

The device handler should be working already. I'll upload a readme.md file for it some day soon

zybeon commented 6 years ago

Nice, I started using the basic one over a week ago. I didn't notice the one you posted. Looking over it quickly reminds me of the ST-Anything (https://github.com/DanielOgorchock/ST_Anything/) that I have been using. Though the AT-Anything has some delays so I have switched to using Tasmota and your devicetype as it is quicker to respond.

Any speed tricks you have would be beneficial as well.

I'll take a look tonght and see what I can come up with. Thanks!

BrettSheleski commented 6 years ago

The device handler by itself works pretty well. What it does is spawns child device (s) depending on the module type of the Tasmota device. If it's a Sonoff basic, then it creates a single Switch device. If it's a Sonoff Duo it creates 2 switch child devices. If it's a 4CH, it spawns 4 switch child devices, etc.

I realize there's an issue with updating the status of the SmartThings app after the device is triggered by other means (not using the SmartThings app). Therefore I'm working on a SmartThings SmartApp to expose an http endpoint that can be called to update statuses.

Anyway, I'll make a write-up documenting how to use the new 'Tasmota' device handler. Feel free to test away.

BTW, I don't have access to all Sonoff devices, therefore I'm hoping others will contribute to this set of handlers. I'm also looking to implement reading the gpio configuration as well which would potentially spawn even more child devices within SmartThings (depending on how configured)