Release: Sonoff Tasmota Switch Driver

I actually pointed it towards the rbg bulb I just flashed to see if I could at least turn it on and off. It worked great. I understand the switch number, which might suit my needs perfectly.

Since this has a username and password, is it using MQTT?

Thanks!

Not MQTT just using the HTTP interface, but you can configure the device to require a username and password over HTTP for restricted access.

I believe that feature is disabled by default, so you should be able to leave those fields blank.

1 Like

Thanks for the clarification.

I look forward to using this!

Hi Noob here; I've got a few SONOFF Basics - Flashed with Tasmota - working for various devices - they are switching correctly but showing no statuses. The driver I have contains this:

// 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 {
	log.error "can not parse result with header: $message.header"
	log.error "...and raw body: $message.body"
}

Is this the correct one? I am getting the same Log as darrenspence showed earlier.

Is it something I didn't do when flashing the units with tasmota?

Any help would be gratefully received as Alexa is bugging me by telling me its not responding.... when it has!

Can you try removing $switchnumber from those 2 lines, it seems like the single switch ones don't use that.

Edit: Scratch that, it actually needs to be removed from the Parse section of the code. I can look at it tomorrow if you can't get it working tonight.

I added the following lines at line 72. Fixes the issue completely.

else if ((resultJson?."POWER" in ["ON", 1, "1"])) {
setSwitchState(true)
}
else if ((resultJson?."POWER" in ["OFF", 0, "0"])) {
setSwitchState(false)
}

Thanks both of you.
corerootedxb - that worked for ON but doesn't set the state to off for OFF??? I'm confused as the code looks the same. This is what the code looks like now:

// 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"
}

}

BTW - Why all the double brackets in the "else if" statements?

Hmmm, take a look at what the Sonoff is sending back when the off command gets received. This is what shows up in my logs:

I fixed it hastily and never went back to clean up the changes I made. I literally just did a copy and paste, got it working and moved on. I gots other crap to break, erm, I mean fix!!! :wink:

[Edit: If it's just a Sonoff Basic, you can remove all references to $switchNumber and it should work just the same. I left it in my copy of the driver as I AM planning on getting some 4 gang controllers eventually.]

Shows this:

Hmmmm, that's weird. Nothing is really standing out to me in your code. Could you copy the original driver again, make your changes and then redeploy it? Maybe there's a weird character of something in there we aren't seeing.

Spot on - you're a star!

BTW - I wasn't having a go when talking about the double brackets - just thought it might be a strange syntax thing..... I'm just trying to get to grips with the coding.

1 Like

No worries!!! I was being a smartass :wink:

Glad you got it sorted though. LOVE LOVE LOVE my Sonoffs.

I actually noticed last night that my switch never shows status. Has somebody forked the original for trying to fix the status?

If it's a Sonoff Basic, the code above should resolve that. I never forked it, just made my edits for the Basic and moved on.

There's also the Poll() command that you could use that is supposed to pull back the current status of the switch.

1 Like

So I've updated the code to what @thorpe.jez calls out.
I still see no status.

chrome_GiSvJRI6qb

Strange the logs show it's on and off...

The driver doesn't automatically poll the switches for status. If you're interested in status updates, you need to use something like Hubi-Poll or RM to periodically poll the devices.

What kind of Sonoffs are those? Basics?

Here's mine. They are Basics.

image

It's a random outdoor 3-relay switch.
I'll try Hubi-Poll again.

It's strange that Sharptools.io just doesn't see a status. It's been great with all of my other devices.

1 Like

Maybe it's the lack of username and password.
Let me check that.

OK fun fact.
I think it might just be a Sharptools.io issue.
The Hubitat dashboard shows status properly.

1 Like