SmartThingsPublic icon indicating copy to clipboard operation
SmartThingsPublic copied to clipboard

Sonoff basic with GPIO14

Open marknguy opened this issue 7 years ago • 11 comments

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:

  • GPIO14 set to Switch2
  • point to my MQTT broker (doesn't use broker, but this prevents Sonoff from tying GPIO14 to relay) Go into Console and made these changes:
  • Pulsetime 4
  • Sleep 60 (this saves power)
  • SwitchMode2 2 (when GPIO14 is open, then reed switch is off, then garage door is open)
  • SwitchTopic2 alarm (for MQTT) Modify Brett's device handler code:
  • modify the tile icon to use st.doors.garage.garage-closed and st.doors.garage.garage-open
  • modify refresh() and poll() to sendCommand("Status", "10")
  • modify parse() with (resultJson?.StatusSNS?.Switch2 in [1, "ON"]) and (resultJson?.StatusSNS?.Switch2 in [0, "OFF"]) Connect reed switch to GPIO14 and ground on the Sonoff Connect Sonoff to garage door.

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.

marknguy avatar Jan 21 '18 16:01 marknguy

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.

BrettSheleski avatar Jan 22 '18 01:01 BrettSheleski

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"?

marknguy avatar Jan 23 '18 20:01 marknguy

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 avatar Jan 23 '18 23:01 BrettSheleski

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.

BrettSheleski avatar Jan 23 '18 23:01 BrettSheleski

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.

marknguy avatar Jan 24 '18 01:01 marknguy

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.

BrettSheleski avatar Jan 24 '18 02:01 BrettSheleski

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

marknguy avatar Jan 24 '18 03:01 marknguy

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

zybeon avatar Feb 26 '18 21:02 zybeon

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

BrettSheleski avatar Feb 26 '18 21:02 BrettSheleski

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!

zybeon avatar Feb 26 '18 21:02 zybeon

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)

BrettSheleski avatar Feb 26 '18 22:02 BrettSheleski