[Release] Tasmota Sonoff Hubitat Driver & Device Support

@ericm, the driver I've downloaded doesn't seen to be working with Tasmota Version 6.5.0(sonoff) Build 2019-05-29T11:39:28,

I've adapted part of the driver changing some commands as for example "/on" to "/cm?cmnd=Power%20On" and now it looks to be working for a switch. But others features doesn't seeing to be working.

Do we have to update the driver to this firmware version, os is there a "better" firmware version that fits this driver ?

Thanks.

For the basic, you should be able to use the S20 driver. Sorry, I haven't had time to create the driver for the basic module but the S20 is about the same.

S20 Driver

@luis.c.amaral Are you also using a Sonoff Basic? You can also try using the S20 driver.

Edit: Oops, I just realized the driver links were for the SmartThings versions. This has been fixed.

Thanks @ericm, I did figured out how to adapt the drivers for the basic and everything is working fine with automation rules and Google Home Assistant.

Now I am playing with an Acemax powerstrip that I could flash tasmota on it and trying to understand how to update the child devices with the status and how to turn off all the relays simultaneously.

All this is new for me as I've just started my adventures with hubitat a week ago. Trying to get up to speed on my spare time.

Thank you for replying back,
Luis

1 Like

Do you have to use your Sonoff Connect software in order to use your firmware? Because I was able to patch together a driver that accepts reports from your firmware so local changes are captured without having to use the connect. Has really impacted the size of my system log events.

What are the chances of this working on these devices: AWP02L-N. I used this walkthrough and it works great, but the current other drivers aren’t real two-way with Hubitat. Since these don’t have easily accessible headers I guess we’d have to sacrifice one to find out if this would work?

I posted this over on the SONOFF Connect thread but figured I would ask here as well. Has anyone figured out how to connect the iFan03 or SONOFF Mini to Hubitat yet?

I try to flash couple of switch that are running tasmota 6.5 and it fail.

Upload Failed

Upload buffer miscompare

Were you doing it over OTA or a serial adapter? If OTA, did you first flash the Minimal firmware? The firmware is too large to flash from one version to the other. So, they developed the minimal file that just does OTA and takes up less space.

If serial, did you boot to flash mode?

OTA, I did the sonoff.bin. So i need to do the sonoff-minimal.bin and then i should be able to flash the Hubitat sonoff.bin ? i will try that.

Thanks

@Ryan780 quick question what driver should i use for a basic light switch ?

1 Like

You have to use the driver linked above.

I install all the drivers and the discovery not finding anything. i do have the firmeware install and the Hue Bridge is enable, i have the static ip of my hub set up but not discovery

1 Like

Ahh so we need to download and install this minimal version via OTA THEN come back and is tall this version via OTA? Releases · arendst/Sonoff-Tasmota · GitHub

Yes. Otherwise it will not update the firmware OTA because there isn't enough space of the sonoff for the active firmware and the new firmware.

So here's what I did to get this working on generic wifi plugs that are compatible with Sonoff/Tasmota:

  1. Bought these on Amazon. They are AWP02L-N plugs. $16 bucks for 2 isn't bad. No idea how long they will be compatible with Tuya-convert, but the ones I received within the past month are. (FYI, still working as of 8/3/2019 from items received from Amazon).
  2. Followed this guide to use Tuya-Convert to install Tasmota on them.
  3. Did file-based update to Tasmota-minimal.
  4. Did file-based update to above firmware.
  5. This reset the device, so had to connect to sonoff-xxx wifi device and reconfigure wifi settings. Then go to Configuration -> Configuration Other and copy/paste template data and click Activate. Also turn on "SmartThings/Hubitat" and "Hue Bridge". And then go into Console and do this to turn off the LED SetOption31 1
  6. This driver ([Release] Tasmota Sonoff Hubitat Driver & Device Support - #30 by Ryan780) works but
    Sonoff Connect did not. See also this new thread and related drivers that work great with the new and old tasmota versions: [DEPRECATED] Tasmota 7.x/8.x firmware for Hubitat + Tuya, Sonoff and other drivers - #131 by markus

FYI, these CYYLTD Mini Wifi Socket devices are also cheap and work fine and they have a USB port with 2.1A: https://www.amazon.com/gp/product/B078H4SNST

Same setup as above using Tuya-convert; here is the template data:

{"NAME":"CYYLTD BIFANS J23","GPIO":[56,0,0,0,0,0,0,0,21,17,0,0,0],"FLAG":1,"BASE":18}

These plugs also work: https://www.amazon.com/dp/B074576LSB

EDIT: 03JAN20 And these work and have Hubitat-compatible energy monitoring: https://www.amazon.com/dp/B07HBTSG76 and use this template: https://templates.blakadder.com/awp04l.html

2 Likes

Any ideas why my devices show up as question marks in the Dashboard? I tried template switch and template outlet.

They are showing up as ?? when using the Switch template? What driver are they assigned to? Can you give a screenshot of your dashboard setup?

Here you go. They are setup as "Sonoff Wifi Switches" (which is the S20 driver renamed per my post above). The buttons work great in the view to turn the outlet on/off, but it's almost like the dashboard doesn't know the status, so it always turns it off (I'm also still on 2.1.1.122 in case that matters).

The other thing I noticed is there are a ton of events in the logs for the device. It's like they are super chatty:

Let me know if I can give any additional information.

It has to be something with the driver your are using. This is the one that I am using for my basics and it works perfectly. Although, you have to set the Network ID yourself manually. It has to be the MAC address of your sonoff for local changes on the Sonoff to work correctly.

Just save the driver, create a virtual device and pick this driver, setting the correct Network ID. Then set the preferences and it should work and report local changes in the device. Should work for all single switch sonoff tasmota devices.

// Original driver developed by Brett Sheleski.
// Ported to Hubitat and updated to include switchNumber by ryan780.
metadata {
definition(name: "Sonoff-Tasmota RPC", namespace: "ryan780", author: "ryan780") {
capability "Actuator"
capability "Switch"
capability "Momentary"
capability "Polling"
capability "Refresh"
}

preferences {		
	section("Sonoff Host") {
    input(name: "ipAddress", type: "string", title: "IP Address", displayDuringSetup: true, required: true)
	input(name: "port", type: "number", title: "Port", displayDuringSetup: true, required: true, defaultValue: 80)
    input(name: "switchNumber", type: "number", title: "Switch Number", displayDuringSetup: true, required: false, defaultValue: null)
	}

	section("Authentication") {
		input(name: "username", type: "string", title: "Username", displayDuringSetup: false, required: false)
		input(name: "password", type: "password", title: "Password (sent cleartext)", displayDuringSetup: false, required: false)
	}
	section("Logging"){
		input(name: "logEnable", type: "bool", title: "Debug Logging", required: false, defaultValue: false)
    }
}
}
 

def parse(String description) {
def message = parseLanMessage(description)

// parse result from current and legacy formats
def resultJson = {}
if (message?.json) {
	// current json data format
	resultJson = message.json
if (logEnable) log.debug resultJson
}
else {
	// legacy Content-Type: text/plain
	// with json embedded in body text
	def STATUS_PREFIX = "STATUS = "
	def RESULT_PREFIX = "RESULT = "
	if (message?.body?.startsWith(STATUS_PREFIX)) {
		resultJson = new groovy.json.JsonSlurper().parseText(message.body.substring(STATUS_PREFIX.length()))
	}
	else if (message?.body?.startsWith(RESULT_PREFIX)) {
		resultJson = new groovy.json.JsonSlurper().parseText(message.body.substring(RESULT_PREFIX.length()))
	}
	/* else if (message?.header?.contains("HTTP/1.1 200 OK")) {
		if (logEnable) log.debug $message?.header
	}*/
}

// consume and set switch state
if ((resultJson?."POWER$switchNumber" in ["ON", 1, "1"])) {
	setSwitchState(true)
}
else if ((resultJson?."POWER$switchNumber" in ["OFF", 0, "0"])) {
	setSwitchState(false)
}
else if ((resultJson?."POWER" in ["ON", 1, "1"])) {
	setSwitchState(true)
}
else if ((resultJson?."POWER" in ["OFF", 0, "0"])) {
	setSwitchState(false)
}
else {
//	log.error "can not parse result with header: $message.header"
//	log.error "...and raw body: $message.body"
}
}

def setSwitchState(Boolean on) {
if (logEnable) log.info "switch is " + (on ? "ON" : "OFF")
sendEvent(name: "switch", value: on ? "on" : "off")
}

def push() {
sendCommand("Power$switchNumber", "Toggle")
}

def on() {
sendCommand("Power$switchNumber", "On")
}

def off() {
sendCommand("Power$switchNumber", "Off")
}

def poll() {
sendCommand("Power$switchNumber", null)
}

def refresh() {
sendCommand("Power$switchNumber", null)
}

private def sendCommand(String command, String payload) {
if (logEnable) log.debug "sendCommand(${command}:${payload}) to device at $ipAddress:$port"

if (!ipAddress || !port) {
	log.warn "aborting. ip address or port of device not set"
	return null;
}
def hosthex = convertIPtoHex(ipAddress)
def porthex = convertPortToHex(port)

def path = "/cm"
if (payload){
	path += "?cmnd=${command}%20${payload}"
}
else{
	path += "?cmnd=${command}"
}

if (username){
	path += "&user=${username}"
	if (password){
		path += "&password=${password}"
	}
}

def result = new hubitat.device.HubAction(
	method: "GET",
	path: path,
	headers: [
		HOST: "${ipAddress}:${port}"
	]
)
return result
}

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
}
3 Likes

Bingo. That worked. Thanks!

1 Like