BrettSheleski / SmartThingsPublic

36 stars 23 forks source link

SmartThings status updating Tasmota device handler #13

Open BrettSheleski opened 6 years ago

BrettSheleski commented 6 years ago

Please use this thread for discussion regarding updating the SmartThings device handler(s) status in the case when the Tasmota device is triggered from outside the SmartThings App.

tonyfitzs commented 6 years ago

Hi Brett, not sure if this is the right place to write this or not but given based on my interpretation this issue relates to “status updating Tasmota device handler” it does seem reasonable. I am trying to get a Sonoff basic working with Smarthings, I have spent many hours on it with very little success, and I am about ready to through the smarthings controller away and build something else (just kidding…sort of). Anyway, I have managed to flash the Sonoff and that all works exactly as I want it too. I have also followed to the letter the instructions found on this page https://github.com/BrettSheleski/SmartThingsPublic/tree/master/devicetypes/BrettSheleski/tasmota.src, and i cant get it to work correctly. I think there must be some information missing because I can’t work out how to build a relationship between the Tasmota Device Handler and the Tasmota-Power Device Handler

The instructions seem to end after you have added a Device (which appears to relate only to the Tasmota Device Handler). Anyway, I wonder if you can help with what appears to be the missing piece of information. In case there is no missing information, and it just works via magic, then can you have a look at the screenshots below because nothing appears to be working. The first screenshot is of the Device Handler in the app on my phone. The information is not being populated with anything

tasmota device handler

The second screenshot is of the Tasmota-Power Device Handler. This doesn’t do anything at all. It just shows as constantly being on.

tasmota-power device handler

BrettSheleski commented 6 years ago

It looks like the device handler is not able to talk to your Sonoff. I'm guessing the IP address is not set properly for the Tasmota device. You'll need to go to the SmartThings IDE, go to My Devices, click on your Tasmota device, in the Preferences section, click the edit link, and make sure to set the IP address to the IP of your Sonoff.

You should not manually add any other device other than the Tasmota device. The Tasmota device handler will spawn child devices depending on the configuration of the device itself.

tonyfitzs commented 6 years ago

Hi Brett, thanks for the speedy reply, I really appreciate it. Below is a screenshot of the device handler settings, I have not put a username and password in because I have no idea what username and password it is looking for.

tasmota device handler ip settings

Below is a screenshot of the webpage that is on the other end of the screenshot. So unless im missing something, I think this is what it is supposed to be.

tasmota-power device handler

From: Brett Sheleski notifications@github.com Sent: Thursday, 19 April 2018 11:09 PM To: BrettSheleski/SmartThingsPublic SmartThingsPublic@noreply.github.com Cc: Tony Fitzsimmons tony@fitzsimmons.com.au; Comment comment@noreply.github.com Subject: Re: [BrettSheleski/SmartThingsPublic] SmartThings status updating Tasmota device handler (#13)

It looks like the device handler is not able to talk to your Sonoff. I'm guessing the IP address is not set properly for the Tasmota device. You'll need to go to the SmartThings IDE, go to My Devices, click on your Tasmota device, in the Preferences section, click the edit link, and make sure to set the IP address to the IP of your Sonoff.

You should not manually add any other device other than the Tasmota device. The Tasmota device handler will spawn child devices depending on the configuration of the device itself.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/BrettSheleski/SmartThingsPublic/issues/13#issuecomment-382728141, or mute the threadhttps://github.com/notifications/unsubscribe-auth/Agn3lR9EG_wDUPRlFKh9fWal9VJ2HPhTks5tqIxmgaJpZM4SojgS.

tonyfitzs commented 6 years ago

Brett I am still not having any success with this, are you able to help further, please.

BrettSheleski commented 6 years ago

The screenshot shows the http:// prefix. Only put the IP address of the Sonoff without any prefix. (10.110.20.156)

See what happens after doing that.

tonyfitzs commented 6 years ago

Hi Brett, so we have a bit of a result.... I did as you suggested and removed the header from the IP address. the TASMOTA app is now getting information from the device.

sonoff handler screenshot

this is a great start.

but the Tasmota Power Handler still isn't working correctly, it is always on. do I have to have the Tasmota setup in a special mode somehow? the instructions for the power handler are pretty vague. I have set the properties for the power device handler as follows.

image

I appreciate your help a lot.

BrettSheleski commented 6 years ago

Once you configure the single Tasmota device, you should not have to configure any other devices. The Tasmota device will, in your case, spawn a single Tasmota-Power child device since the Sonoff is configured as a Sonoff-Basic (Module 1). The most you should really do with any child device is rename it to your liking.

If you press the refresh button on the Tasmota device it should update the status of itself and all child devices.

In your case I believe the Power Channel of the Tasmota-Power child device should be set to 1. Again, this should be set for you automatically. I would recommend deleting your Tasmota device and any Tasmota-Power child devices (but keep the Device Handler code) and starting over if you're having problems.

Currently, the status of the device (including any child devices) will not update when changed outside the SmartThings app. Meaning if you somehow toggle the state of the Sonoff by other means (the Tasmota web interface, MQTT, etc.) the status reported by SmartThings will not automatically update. This is a limitation of how SmartThings works.

I have been developing a SmartThings SmartApp to address this limitation. The goal of the SmartApp is to provide an HTTP endpoint one can call after the Sonoff device is triggered. One way of getting this working is to create a flow in Node-Red which would listen to the MQTT traffic for state-change, and make an HTTP call to the SmartApp providing it with the current state information. This is a work-in-progress though.

tonyfitzs commented 6 years ago

Thank you, Brett, after I posted my last post to you I managed to get it working. what I discovered is that the Handler doesn't automatically spawn the switch which was what caused the confusion. what I had to do is go to the Device Handler in edit mode then open the simulator and simulate an action. as soon as I did that it spawns the switch.

Now all I have to do is figure out how to get Smarthings to set up the second switch because in my case I am using the Sonoff with a second relay so while its a basic it kind of behaves like a duo.

what I might do if this is of any help to you, is I will do some more testing and tighten up the wording a little for your tutorial and repost it for guys like me who aren't really programmers.

BrettSheleski commented 6 years ago

Do you have a gpio pin setup to control another relay (and configured via the Tasmota web interface)? If so, I intended on supporting such situations.

Give me a screenshot of what http://ip-of-sonoff/md shows if you don't mind.

Also, feel free to make a pull request containing any additional documentation you feel may be helpful.

tonyfitzs commented 6 years ago

thanks very much, Brett, I would like to help you out if I can, one of my skills is the development of help text, I do it as part of my job. based on my present experience I can re-word the current help document so it's more clear and then send it back to you if that would be helpful.

image

BrettSheleski commented 6 years ago

Nice. Btw, you shouldn't have to go to the Simulator in the IDE. If that's the case, that should be fixed.

It looks like I should be able to support relays attached to GPIO's relatively easily. I may be able to make some code changes to accommodate this.

BrettSheleski commented 6 years ago

I was able to implement relay devices configured on GPIO pins (see commit https://github.com/BrettSheleski/SmartThingsPublic/commit/4f56a96d645a3f64493a56b7d676b2a4beb9cf6c).

The code is stubbed out to support other devices attached to GPIO pins, but not implemented (yet).

You'll need to update your Device Handler code from this repo. It should then create an additional Tasmota-Power child device for you automatically.

tonyfitzs commented 6 years ago

Thanks Brett. I will give this a try, I do have the other question. You mentioned the other day that you are working how to update Smarthings by creating a flow in Node-Red which would listen to the MQTT traffic. this got me thinking, if Smartthings is able to get updates from Node-Red then presumably it can send messages to Node-Red. wouldn't it make a lot more sense (and be a lot easier to get working) to just use a Smarthings Node Red integration to drive Tasmota? you could then simply configure the Tasmota device as an MQTT device and smart things would be able to send a turn on turn off command via Node Red.

I have node-red running in my environment and I use it for unrelated stuff to home automation. if I knew how to tell smartthings to send it a message and vice-versa I would love to give this a try. so if I may ask. how are you configuring Smarthings to listen to Node red? and is it even posible to send a message to Node red if you press a button in smartthings.

warm regards.

BrettSheleski commented 6 years ago

I'm not aware of any SmartThings nodes for Node-Red. I'm just doing raw http requests in Node-Red.

However, you're on the right track regarding Node-Red. Check out https://github.com/stjohnjohnson/smartthings-mqtt-bridge. It's a solution to access SmartThings devices via mqtt. I've thought about going down that route but decided against it for now at least.

What you could do is create virtual devices for all your actual things in SmartThings and the configure Node-Red to "translate" decice-specific mqtt messages to the format the mqtt bridge is expecting.

tonyfitzs commented 6 years ago

Thanks, Brett, I have just installed the new code and it is instaling but it is not able to control the device. also I can 100% confirm that the Tasmotoa Handler doesn't do anything at all until you run the simulator. I have been able to reproduce this by uninstalling it completely then reinstalling it from scratch. I made sure that the IP address and username etc where all set correctly and then hit refresh in the smart things app 5 or 6 times with no effect. as soon as I ran the simulator and selected the Tasmota handler as the device in the simulator the two switches where spawned. I am now going to try something completely different to see if the approach is any easier, I will use Web Services in smarthings to create and end point and a pull point and then use Node Red to integrate to the Sonoff using MQTT. it may spectacularly fail but its worth a try. I will let you know how it goes.

stolek5 commented 6 years ago

I have exaclty the same issue like @tonyfitzs But I'm using my GPIO14 with wired magnetic sensor connected. The build is similar to this instructable http://www.instructables.com/id/Sonoff-Garage-Door-Opener/

I would like to be able to use it as momentary switch with door open/close status, something similar like Mimolite

Device Handler for Mimolite is here: https://github.com/fortrezz/smartthings Documentation: http://www.homecontrols.com/homecontrols/products/pdfs/FZ-FortrezZ/FZMIMO2US-Guide-with-SmartThings.pdf

it is possible to modify DeviceHandler or SmartApp to have that feature ?

sonoff dh

or even to controll two garage doors

two mimolite

tonyfitzs commented 6 years ago

Hi @stolek5, I gave up on using both the handler that Brett had created and the one that Ryen so passionately supports because I could not get either of them to work correctly. I am using the Tasmotta Firmware because non of the others out there come remotely close to it regarding its flexibility, anyone who argues differently doesn't know what they are talking about.

But this doesn't help you with your situation. There are a couple of options for you right now. 1. you can use HomeAssistant to control the Tasmota devices via MQTT and then use IFTTT to integrate between Smarthings and home assistant. This is a very long winded approach but that is precisely how I got my garage door opener working using a Sonoff SV and Tasmotta which is what you are after. There is a bunch of tutorials out there that explain how to do this with HomeAssitiant, there is also a couple which show you how to build a garage door opener based on proximity, but that's problematic if you use MQTT and a Tasmotta as the condition sensor to test proximity. I'm happy to explain this further but this thread isn't the right forum.

The other option is a lot more elegant and is the approach I am now pursuing. Once I have got it all working, I will be posting a detailed set of how too's starting with setting up a Raspberry Pi to act as the integration controller, this tutorial is badly needed because there is a lot of miss information and unclear instructions that currently exist. But, unfortunately, that will not happen today.

My current approach is to use Node-Red as the integration controller as it supports both RESTful and MQTT out of the box. You then have a number of options. You can use IFTTT to integrate between NodeRed and Smarthings, or you can Build a set of handlers that will integrate directly with Node-Red. I will be doing the latter as this will provide a lot more flexibility and can be built without any reliance on an external system such as IFTTT.

I'm happy to share what I have learned so far, in fact, what I might do is set up a contribution thread on Github so that others can join in the fun and we can get it to work together. The only problem with Threads like that is they become very convoluted very quickly.

The current issue I am having with my setup is making Node-Red act as a secure endpoint for an HTTP restful packet. I had only just figured this out yesterday. I haven't even started on building the handlers yet but given there is already a detailed tutorial on creating an inbound and outbound RESTful integration to Smarthings; I'm confident this won't take me to long. I should point out I'm not a programmer, I'm an Integration Architect.

BrettSheleski commented 6 years ago

What I do for controlling my garage door is have a Sonoff 1ch set with a pulse time of 0.2s. Then utilize the button functionality to turn on the relay (which turns itself off after 0.2 seconds, simulating a person pressing the manual button on the wall). I also have a Monoprice z wave garage door sensor which reports the state of the garage door (open or closed).

I haven't fully tested it yet (my Monoprice module died on me) but I have a SmartApp and yet another device handler (see here: https://github.com/BrettSheleski/SmartThingsPublic/blob/master/smartapps/BrettSheleski/byo-garage-door-opener.src/byo-garage-door-opener.groovy and https://github.com/BrettSheleski/SmartThingsPublic/blob/master/devicetypes/BrettSheleski/byo-garage-door-opener.src/byo-garage-door-opener.groovy) which takes any button device and any contact sensor device and creates a garage door device with it.

What I would do is get a Wemos d1 mini and connect it to 2 relays and 2 reed switches. The Tasmota device handler would need to be updated to detect the relays connected to gpio and create switch devices for each (may already be done, can't remember). Do the same with the reed switch, but generate child contact sensor devices instead (definitely not done, but shouldn't be tough).

With the 5 SmartThings devices (1 master, and 4 child devices for each gpio module) one could use my BYO Garage Door SmartApp and device handler to create two garage door SmartThings devices.

econejo commented 5 years ago

Hi Brett, first of all thanks by this very good project. I'm a little fresh with groovy but working a while with Smartthings. Successfully using your handlers for Sonoff dual R2 with Smartthings Hub V2. But, facing problems to make it work at the new Connected Home hubs. It seems there is some key difference between the hubs firmwares (V2 = 22.14 and ConnectHome = 20.53 both the latest ones) that is preventing to spawn the child devices (tasmota-power). Do you have any hint on how to overcome it?

BrettSheleski commented 5 years ago

I just have a SmartThings Hub V2. I honestly haven't heard of this Connected Home hub that you mentioned.

From the sound of it, it's a SmartThings-compatible device and should just work.

I'd suggest firing up the simulator in the SmartThings IDE and see if it tells you anything.

econejo commented 5 years ago

Sorry by taking so long to reply. Seens it is now renamed to Smartthings WiFi: https://www.samsung.com/us/smart-home/smartthings-wifi/

I still fighting with it, but not able to get connected. I'll inform any progress...