BrettSheleski / SmartThingsPublic

36 stars 23 forks source link

New Tasmota SmartApp and Device Handlers #9

Open BrettSheleski opened 6 years ago

BrettSheleski commented 6 years ago

I've started implementation of a new SmartApp and necessary child Device Handlers.

See https://github.com/BrettSheleski/SmartThingsPublic/tree/master/smartapps/BrettSheleski/tasmota.src for more details.

BrettSheleski commented 6 years ago

I've created separate issues for testing with the Sonoff 4CH, Sonoff Basic, and Sonoff Touch modules. Please use them for communicating issues regarding those devices.

Sonoff Basic Testing Sonoff 4CH Testing Sonoff Touch Testing

I'm keeping the issue of updating the SmartThings device handler separate from the above as the problem is mainly the same across all devices. Please use the following Issue for communication regarding it. Updating Device Handler Status

This thread is getting quite long and will probably close the comments to promote using the other threads instead.

jymbob commented 6 years ago

The (prebuilt) firmware supplied along with that DTH does indeed appear to be triggering an update on a physical state change. I'm aware that MQTT is an option, but I think it leads to a cleaner solution overall if the devices can communicate their changes directly to SmartThings, rather than via a separate broker - I'm perfectly capable of setting up an MQTT broker, but my understanding is that the IP:Port NetworkDeviceId method manages to keep the processing local, whereas unless SmartThings integrates its own MQTT broker in a future update, that would have to go via an HTTP call which forces us out to the cloud. Happy to continue the discussion on the new issue, or elsewhere.

BrettSheleski commented 6 years ago

After Googling a bit, it looks like that prebuilt firmware seems to be ESPEasy (??) and is using Domoticz. I really don't know much about Domoticz, but it looks like you need to specify the SmartThings hub as the Domoticz server with port 39500. I don't see where to specify that in the Tasmota web interface (maybe I'm dumb).

It sounds like if you set the Network Device ID to the IP:Port then these Domoticz messages will make it to the SmartThings device handler's parse() method. If that's the case, then we may be onto something. If this can be confirmed (a simple testing device handler could be used for testing) this device handler could be updated pretty easily to support this.

jymbob commented 6 years ago

It may need an update to the Tasmota firmware - in the SmartLife firmware (which is a closed-source custom firmware, he recommends ESPEasy to flash it) there's a config option saved to the Sonoff to specify the local IP of your SmartThings hub. Without that it seems we won't get far.

jymbob commented 6 years ago

Thanks for the mention of ESPEasy and Domoticz - I'll have a dig around and see if that might work out as a better solution than Tasmota. This looks promising - I'll report back when I've had a play

BrettSheleski commented 6 years ago

I want to stick with the Tasmota firmware and avoid needing any customizations to it.

It should also be worth mentioning that you may be interested in the SmartThings MQTT Bridge. You could go this route instead. What I had thought of doing is create virtual devices in SmartThings for every MQTT device and rely on something like Node-Red to coordinate the messages between the SmartThings virtual devices and the "actual" MQTT devices. This should get around needing to create/manage any SmartThings device handlers.

jymbob commented 6 years ago

I absolutely understand. At the moment I'm not keen to run yet another service on my network to get the control I need, so I'm going to take a look at an ESPEasy solution. If I can't get that to work I may end up going down the MQTT route, so thanks for the heads up. I'll keep an eye out for what you're doing here too. Happy coding!

digiblur commented 6 years ago

@jymbob looks you are onto something. This was my initial intention, I have the ST MQTT Bridge running between ST and HomeAssistant, while it does work but it does have its issues and limitations mainly due to ST. I'd prefer to not run any of my Sonoffs through it.

Unfortunately the closed-source firmware for the Sonoffs designed for ST use doesn't have any MQTT support. It would be almost perfect if it did as it works pretty good with the ST system. Looking at the firmware screens it looks like it is based off an early Tasmota build/libraries then modified a good bit.

I've played around with many firmwares on my Sonoff Basics trying things out and such, since mine require the DOUT flashing method I found the NodeMCU app on my Windows laptop seems to work well with things.

tejeman commented 6 years ago

Hello!

First off thanks for taking your time in sonoff smartthings tasmota connection.

Secondly, there seem to be a problem in the smartapp code and i dont know if in anything else.(i got sonoff 4ch pro)

So i got all the device handlers running and created 1 device for each one of them, just in case (even you dont mention that is necessary to have them alll, i installed tasmota first, then tasmota power.

Then i added my device and entered the ip adress (i tried both my internal ip ex. 192.168.1.99 and my internal ip and the port sonoff usually works ex 192.168.1.99:80) I tried with this 2 configurations and it dosent work with any of them. With your old handlers it worked. But i cant use your old handlers because they dont give me the ON/OFF status and i need that.

Then i open smartthings app and i see the device i created but not another device with the "switch" suffix. (you wrote that it should create another device)

It didnt work.

THen i installed the smartapp correctly, i opened it on smartthings app and it lets me select the device i created earlier, i select it but then i dont have anyway to "enter" and save. I can only go back to the screen before and the configuration and selection does not save.

I hope you can help me.

Thanks and sorry for my english.

BrettSheleski commented 6 years ago

I just created another testing device to verify things are working, and things appear to be working for me. I do not have a 4CH, so I was only able to test with a Sonoff-Basic, but it should behave the same.

Simply enter your local IP address of the Sonoff device. In your case just enter 192.168.1.99. Do not include the port number. Do not manually create any Sonoff-Power devices.

After entering the IP address, the device will automatically spawn the four Tasmota-Power child devices for you. You should not have to do any configuration to them.

After doing so you should have 5 devices in SmartThings:

The SmartApp is a work in progress. At this point I'm not going to offer much for support for the SmartApp. It requires needing to do OAuth authentication. See here for more info: http://docs.smartthings.com/en/latest/smartapp-web-services-developers-guide/authorization.html.

After successfully getting an access token you'd need to make requests to https://[smart-app-base-url]/api/smartapps/installations/[smart-app-id]/status with the necessary header values.

Again, see http://docs.smartthings.com/en/latest/smartapp-web-services-developers-guide/authorization.html for more info.

BrettSheleski commented 6 years ago

I just got the SmartApp working to a point where I'm satisfied.

I ended up creating a separate repo for a helper tool to help with the SmartThings OAuth authorization in order to determine the needed Access Token and endpoint Url. See here: https://github.com/BrettSheleski/SmartThings-SmartApp-OAuth-Helper

I've updated the SmartApp documentation with help getting this working with an example Node-Red flow.

yannickchapados commented 4 years ago

@BrettSheleski, Hello Brett i am new into this level of flashing and modifying stuff, i bought a sonoff bridge in the hope to be able to control 4 roller blinds in smarthings, each blinds work with a rf remote with 3 button on each remote. so in total i would need to be able to program 3 button per blinds for a total of 12 buttons. i have flashed my sonoff bridge with tasmota firmware. install the device handler in smarthings and device. now i am confuse on what is the next step i would need to do and how to make the sonoff to learn the codes sent by the blind remotes. would you be able to give me on the next steps? InkedScreenshot 2019-10-30 at 11 22 47_LI

BrettSheleski commented 4 years ago

You'll need to also add the Tasmota-RF-Bridge-Button device handler (see https://github.com/BrettSheleski/SmartThingsPublic/blob/master/devicetypes/brettsheleski/tasmota-rf-bridge-button.src/tasmota-rf-bridge-button.groovy) to your SmartThings IDE.

The Tasmota device handler you define will then spawn 16 Tasmota-RF-Bridge-Button child devices where each child device corresponds to one of the 16 buttons found in the RF Bridge. From there you can configure each button to do something different from within SmartThings.

Here's a screenshot of what you should expect to see as a result.

Screenshot_20191030-103315

Notice the RF Bridge Device itself followed by a bunch of child devices spawned, one for each button on the bridge.

yannickchapados commented 4 years ago

wow thanks for the fast answer, i have one button showing up, is the child spawn need to be set in config or should appear by itself?

BrettSheleski commented 4 years ago

It will appear automatically after configuring the Tasmota device. Again, you will need to make sure you also add the Tasmota-RF-Bridge-Button device handler to your SmartThings IDE. If you to not have the aforementioned device handler available then it will not spawn the child devices.

yannickchapados commented 4 years ago

not sure what i am doing wrong as the spawn is not happening, direct inside the sonoff bridge configuration, we need to select the bridge as configuration the do we need to set all input or output as button? is setting a username and password is a must for it to work? In the smarthings ide, i have both device handler installed, the tasmota device handler and Tasmota-RF-Bridge-Button device handler. but in the devices, after adding the bridge as a device, do i need to add also the buttons as a device? or the button will be spawn from the bridge device automatically?

BrettSheleski commented 4 years ago

The child devices will get spawned by the Tasmota device. They should not be created manually.

Try removing and re-installing/configuring the Tasmota device then look at your list of devices in the SmartThings app.

yannickchapados commented 4 years ago

hello Brett, don't want bother you too much about my issues but still cant get it to work, could you quickly look at my screen shots to see if their is anything obvious that is wrong? view 1 view2

xHirscHx commented 4 years ago

Your update worked for me with the tasmota 7.1.2 spawned child devices, but its not reporting state correctly in the smarthings app. Also the new devices with the new device handler dont show up in your tasmota smart app anymore. is there an updated version of the smart app somewhere that im missing. ps thats for all your work. Tasmota update killed me twice now LOL.

update- so i switch just one of my devices back to the old device handle code and it showed up in tasmota smart app and now all of my devices are report the corect on/off state in smarthimgs ? weird but all take it.

xHirscHx commented 4 years ago

well had it all working great and now smarthings just released a update last night that broke Hue emulation with tasmota and custom module with your code not finding more then 1 child device. starting to hate ST. Might just go full on with hassio but love webcore and action tiles to much.