Problem with custom Driver

Hello everyone,
I just switched over to Hubitat from Smartthings and I haven't been happier. The powerful built in apps like Rule Machine and Motion Lighting I had no need to bring over any of my custom apps. However I am having a little issue with my device drivers for all of my Sonoff devices. I was happy that I only needed to change one word in three different areas for my device driver to work. The driver itself seems to work flawlessly, I am able to turn it on or off from with in devices, all of my automation work great, but now that I am trying to build my dashboard it's not working so hot. These are basic drivers for switch on/off capabilities, but when I push the button on the dashboard nothing happens, well it will turn off the device if it's on, but will not turn on. I am guessing I am missing something little. I have looked over the documentation, but it's not real helpful as of yet. My code is below, if anyone can help me figure out what I am doing wrong I would greatly appreciate it. I designed this to work in Smartthings so I haven't cleaned up the code yet.

Some general comments that may help on your driver:
Not causing an error in code: You do not need the "tiles" section. It is basically wasted code.

Potential error. In preferences, you have autoOff. It has a default value of 0. In Hubitat, default values mean just that (in SmartThings, it really didn't work until preferences were manually run). Are you turning immediately off after turning on? Test this by setting devaultValue to 10. Do not know.

Other items: In preferences, I believe that displayDuringSetup and required do not mean a whole lot in Hubitat. Will not cause error, just extra code (like the tiles).

Logs: Some logs around the failed event would provide some insight. before doing this, I would add a log line in the method action to capture what is actually being sent to the device.

Just some initial thoughts. Need logs to really understand.
Dave

Thanks for the reply. The 0 simply disables the auto off feature on the device itself. However I did change it like you suggested and it did not help. I think I should also mention that the dashboard doesn't show it as on when it is, I just happen to notice when the device was on that it turns off when pushed. The device it's self works fine when ran in the devices section of the hub. It's just from the dashboard it doesn't turn on or when it is on doesn't show the status. Works great within automation or from the device page.

I know I have some cleaning up to do with the code. I will try to get you some logs.

Please show a screen shot of the device current states, once after turning the device on via the driver, then another after turning it off...

Screenshot Switch ON

Screenshot Switch OFF

The switch on and off attribute values are uppercase.
These must be lowercase.

1 Like

Yes, I seen that too. I am changing them now as we speak.

1 Like

I know it had to be something dumb. Thank you! The device it self was reporting in uppercase so I had to cast it to lowercase and it's working fine now.

1 Like

I cleaned up some of the code as @djgutheinz suggested. If anyone can see anything that could use tweaking or unnecessary code please share. I have one more driver for power monitoring devices I need to change and cleanup then I will post for everyone to use.

@goug76 Hi
I found sonoff basic is pretty unstable when connecting via http. esp8266 is not powerful enough
When controlled via MQTT - stability is acceptable

1 Like

Really? I have been using these devices for years and they always been rock solid. Well when I first started out I was on OpenHAB using MQTT and the web server gave me issues when trying to connect via a browser, but I was mainly using MQTT with my home automation so that didn't bother me much. I switched to Smartthings about a year ago and been using them over HTTP without issue. I am not sure if it was an issue with the older firmware or that I totally revamped my network since then. Like any computer when leaving them on too long they get a little finicky, so in the driver I have them reboot them selves every Saturday morning.

Which leads me to another question if you would be so kind. Is there a way to programmatically reboot the hub? I like to reboot my equipment once a week to keep everything running as it should be and since this is home automation I want to automate it.

@goug76 which hub? Hubitat?

@podarok Hubitat. I just switch from Smartthings about a week ago.