[OBSOLETE] Sonoff, Sonoff TH, S20, Dual, 4CH, POW, & Touch Device Handler & SmartApp ($5 & $10 Smart Switches)

Bizarre, I’ve not seen this with any of mine. I’ll have to remember this in case it happens to me. Well done for working it out though.

Where is the source? I’d like to add some functions

I uploaded the latest SOnoffPOW software to 2 of my POW’s and now they bricked; the web interface won’t load.
If i NMAP them, only port 3 is open which i can telnet to but don’t know what commands it accepts.

I have tried the 15 second reset, gone back to the SonOff AP and reconfigured the wifi and same thing.
Any ideas?

I only have Mac with me and no microsoft windows to connect via the TX/RX usb :confused:

Has anyone actually got the S20 working yet. I successfully flashed two but neither seems to work under this device handler. I have other Sonoff devices working here though. Any ideas?

Hello Guys,

I have a Sonoff T1 EU 2 gang switch. I was able to flash it with SonoffTouch.ino.generic.bin but I am not sure which device handler I should use. I tried sonoff-wifi-switch.groovy but this way only 1 gang is working. Could someone tell me what I should be using to make both gangs work?

Thanks.

HI There

try flashing it with the sonoff 4ch firmware i have a few working brilliantly.
just delete the unused/unassigned child devices.

Thanks for the info. Would that mean that if I flash with the dual firmware it will work kind of the same?

No not really. I think it has to do with the similar ESP controller being used in the 4ch and the multi touch.

Thanks. It works seamlessly. I tried tasmota as well but with this firmware status in SmartThings is updated almost immediately while the other has delay.

Sorry if this post is in the wrong place. This smartapp and steps ultimately led me to the below solution that worked. I needed to monitor a freezer with the sonoff TH devices which is a litte different than most cases here with controlling lights.
I was having a really hard time getting this smartapp and flashing with the TH firmware to work on both the TH10 and TH16. I was able to install tasmota though without any hiccups. The problem was that I didn’t want all the backend work and infrastructure to get this to show in smartthings using MQTT which was the preferred method. So, flashing with tasmota following their steps then using the below device handler I have the sonoff reporting through HTTP Get requests over the local network.

WARNINGS:

  • I am not a developer but I do dabble
  • This is definitively version 0.0.1 with hacked together code from nest and multiple other pieces. Most of this documented like crap in this device handler.
  • Currently designed for my specific use case of temperature monitoring
  • There are other pieces that I am working on and I dont even have this on git. Use this as a base if you want to do something similar. As I only need temps im polling every 15 minutes which is more than fine for what I need.
/**
 *  Generic HTTP Get 
 *
 *  Copyright 2018 Paul K based on enlighten by Ronald Gouldner
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
 *
 */
 
import java.text.SimpleDateFormat
import groovy.time.*

def devVer() { return "0.0.1" }
 
preferences {
    input("user_id", "text", title: "Username")
    input("user_pass", "text", title: "password - Long and random")
    input("command", "text", title: "Command to Send")
	input("remoteIP", "text", title: "Remote IP of the Device")
    input("remotePort", "text", title: "Remote Port of the Device")
    input("sensortype", "text", title: "Sensor Type as reported by device")
}
metadata {
	definition (name: "Generic HTTP Get Device", namespace: "k", author: "Paul K") {
	capability "Temperature Measurement"
	capability "Sensor"	
    capability "Refresh"
	capability "Polling"
    capability "Relative Humidity Measurement"
    capability "Thermostat"
        
    //attribute "temperature_today", "NUMBER"
    //attribute "Humidity_today", "NUMBER"	
	attribute "Temp_Type", "STRING"
	attribute "Sensor_Type", "STRING"
	attribute "Time", "STRING"
    attribute "softwareVer", "STRING"
	}

	simulator {
		// TODO: define status and reply messages here
	}

	tiles(scale: 2) {
            multiAttributeTile(name:"temperature", type: "thermostat", width: 6, height: 4){
			tileAttribute ("device.temperature", key: "PRIMARY_CONTROL") {
				attributeState("temperature", icon:"st.tesla.tesla-hvac", label:'${currentValue}\u00b0', unit:"F",
                backgroundColors:[
                    [value: 10, color: "#153591"],
                    [value: 15, color: "#1e9cbb"],
                    [value: 20, color: "#90d2a7"],
                    [value: 25, color: "#d04e00"],
                    [value: 32, color: "#bc2323"]
                ]
                	//DEFAULTS JUST IN CASE USE CASE IS NOT A FREEZER
                    //31	#153591	
					//44	#1e9cbb	
					//59	#90d2a7	
					//74	#44b621	
					//84	#f1d801	
					//95	#d04e00	
					//96	#bc2323
            )
			}
            tileAttribute ("device.humidity", key: "SECONDARY_CONTROL") {
				attributeState("humidity", label:'${currentValue}%', unit:"%", defaultState: true)}
		}
            standardTile("refresh", "device.temperature_today", inactiveLabel: false, decoration: "flat") {
                state "default", action:"polling.poll", icon:"st.secondary.refresh"
            }
			valueTile("softwareVer", "device.softwareVer", inactiveLabel: false, width: 3, height: 1, decoration: "flat", wordWrap: true) {
				state("default", label: 'Firmware:\nv${currentValue}')
            }
			valueTile("Time", "device.Time", width: 3, height: 1, decoration: "flat", wordWrap: true) {
				state("Time", label: 'Data Last Received:\n${currentValue}')
			}
            //htmlTile(name:"graphHTML", action: "graphHTML", width: 6, height: 13, whitelist: ["www.gstatic.com", "raw.githubusercontent.com", "cdn.rawgit.com"])
        main (["temperature"])
        details(["temperature","Time","softwareVer","refresh","graphHTML"])

	}
}

//mappings {
//	path("/graphHTML") { action: [GET: "getGraphHTML"] }
//}


// parse events into attributes
def parse(String description) {
	log.debug "Parsing '${description}'"

}
def poll() {
	log.debug "Executing 'poll'"
	refresh()	
}

def installed() {
	log.debug "Executing 'installed'"
	updated();
}

def updated() {
	log.debug "Executing 'updated'"
    log.debug "Firmware Version is now v${devVer()}"
    sendEvent(name: 'softwareVer', value: devVer(), descriptionText: "Firmware Version is now v${devVer()}", displayed: false, isStateChange: true)
    unschedule()
    runEvery15Minutes(sendHttp)
    runIn(2, sendHttp)
}

def refresh() {
	log.debug "Executing 'refresh'"
	sendHttp()

}

private String convertIPtoHex(ipAddress) { 
    String hex = ipAddress.tokenize( '.' ).collect {  String.format( '%02X', it.toInteger() ) }.join()
    return hex
}

private String convertPortToHex(port) {
	String hexport = port.toString().format( '%04X', port.toInteger() )
    return hexport
}

def sendHttp() {
	log.debug "Executing 'sendhttp'"
	def ip = "${settings.remoteIP}:${settings.remotePort}"
	def hosthex = convertIPtoHex(settings.remoteIP)
	def porthex = convertPortToHex(settings.remotePort)
	def deviceNetworkId = "${hosthex}:${porthex}"
	//log.debug "Network Device ID is: ${deviceNetworkId}"
	sendHubCommand(new physicalgraph.device.HubAction("""GET /cm?user=${settings.user_id}&password=${settings.user_pass}&cmnd=${settings.command} HTTP/1.1\r\nHOST: ${ip}\r\n\r\n""", physicalgraph.device.Protocol.LAN, "${deviceNetworkId}", [callback: "calledBackHandler"]))
}

def sensorjson(json1) {
	
	return json1
}

def getTimeZone() {
	def tz = null
	if(location?.timeZone) { tz = location?.timeZone }
	else { tz = state?.nestTimeZone ? TimeZone.getTimeZone(state?.nestTimeZone) : null }
	if(!tz) { Logger("getTimeZone: Hub or Nest TimeZone is not found ...", "warn") }
	return tz
}

void calledBackHandler(hubResponse) {
	def body = hubResponse.json
    
    //log.debug "body in calledBackHandler() is: ${body}"
    def formatVal = "MMM d, yyyy - HH:mm:ss"
    def tf = new SimpleDateFormat(formatVal)
    tf.setTimeZone(getTimeZone())
    def curConnFmt = tf.format(Date.parse("yyyy-MM-dd'T'HH:mm:ss", body.StatusSNS.Time))
    //log.debug "ORIGINAL TEMP: ${body.StatusSNS.SI7021.Temperature}"
    def temp = body.StatusSNS.SI7021.Temperature.toDouble()
    //DONT KNOW IF I CAN USE DOUBLE OR INT have both for now. Prefer Double if possible w/ creating alerts
   		temp = Math.round(temp.round(1)).toInteger()
    def hum = body.StatusSNS.SI7021.Humidity.toDouble()
    	hum = Math.round(hum.round(1)).toInteger()
     //log.debug "${temp}"   
    delayBetween([sendEvent(name: 'temperature', value: temp)
		,sendEvent(name: 'humidity', value: hum)
		,sendEvent(name: 'Temp_Type', value: body.StatusSNS.SI7021.TempUnit)
		,sendEvent(name: 'Time', value: curConnFmt?.toString(), isStateChange: true)
	])
    
}




Just wanted to say for anyone having issues with the custom firmware, sonoff connect and the TH device driver. The issue I was having was with an ‘unknown MAC’ address in the device driver, I added the device manually through the sonoff connect (multi vlan, lazy).
Issue I had was in the device type with a MAC that is never used, comment out line 147 and below solved the issue:

/*if (!state.mac || state.mac != descMap["mac"]) {
	log.debug "Mac address of device found ${descMap["mac"]}"
    updateDataValue("mac", descMap["mac"])
}*/

That made it all work perfectlyy

I cannot find my Sonoff Basics.

I have installed device handlers; [erocm123 : Sonoff Wifi Switch] and [erocm123 : Sonoff (Connect)], plus SmartAPP; [erocm123 : Sonoff (Connect)].

When trying to discover devices in the app, it does not find any.

I can connect to the devices running [Sonoff-Tasmota 6.3.0.2] via a web browser.

Any idea what I am missing?
Thanks

Does anyone have a much more detailed step by step instructions for this bit?

Now, with an FTDI adapter (SET AT 3.3V) connected to the switch (square pin = VCC, then TX, RX, GROUND - that order), plug the FTDI adapter into the USB port of your computer while holding down the button on the switch.

I get everything apart from this, which I am completely lost on…pictures of where on the FTDI adapter I need to connect to where on the Sonoff and when would help a lot!

Thanks

Does your FTDI not have labels on each pin? If so, it is easy, the square pin on the Sonoff is the VCC, the next pin is TX, next is RX and the last is Ground. Just connect those to the corresponding pins on the FTDI

If I get a chance I will try and get a photo of mine

Does anything work with this?

https://www.aliexpress.com/store/product/Sonoff-T1-UK-Plug-86-Type-Smart-Wall-Touch-Light-Switch-Toughened-Touch-Glass-Panel-Support/3063001_32825536717.html?spm=2114.12010615.8148356.51.7253537fv5uh3w

I haven’t bought anything yet. Do you suggest i buy something else?

@erocm1231

I have tested Sonoff T1 EU and it works just fine. I guess the UK version should be similar.

Help needed! Thank you!!
I have about 7 of these Sonoff basics, and plans to add more (IF I can fix this problem)
They keep disappearing. = (
At any given time around half of them are “Not available” in Smartthings classic, or “disconnected” in the Smartthings app… yet if I navigate to the IP of the sonoff in a web browser it works (i.e. http://192.168.0.38/).
I’m able to switch them on and off via a web browser / node.
So the problem isn’t the Wifi signal.

I can get them to become “available” again by doing the following:
opening the Sonoff (connect) smartapp and choosing “reset list of discovered devices”. While that is looking for devices, if I REBOOT the offending sonoff switch/es in question (through a web browser) after 30 seconds to a minute they will show up in Sonoff (connect) again and are immediately useable in Smartthings again… at this point it works perfectly until it breaks again. Could be minutes or hours. If I do nothing… it will eventually be available again… then it breaks again. I’m not sure if this is an issue with the device, the smartapp, the handler, or smartthings. At first glance it seems like the Sonoff (connect) smartapp is losing them for some reason. I’m fairly new to this stuff. Any insight would be truly appreciated. This is really frustrating and defeats the purpose of having these devices…
If I can’t fix this I will probably invest a lot more $$ in z-wave smart sockets. I hope to avoid that.
Thanks again!!!

They are flashed with this guy using Nodemcu flasher
https://github.com/erocm123/SmartThingsPublic/raw/master/devicetypes/erocm123/sonoff-wifi-switch.src/Sonoff.ino.generic.bin

The UK versions are straightforward and easier to flash.
I have the 2 and 3 gang versions.
I am using these with the 4ch Firmware and they work brilliantly.
Just delete the unused child devices.

Just wanted to clarify something simple so other people don’t research it for hours like I did. There is a new Sonoff basic board that does not work with ESPEasy (all the old ones did). It must be flashed with NodeMCU flasher as described in the first post. The new board is labeled with “Sonoff RF R2 POWER V1.0” and uses ESP 8285 and GPIO2 instead of the old ESP 8266 and GPIO14.

More Info at https://github.com/arendst/Sonoff-Tasmota/wiki/Sonoff-Basic#new-board-layout

3 Likes