Wemo switch and insight smart plug


#41

Your driver has been great for my Wemo light switch. But I've started automating some stuff and I noticed a problem. If you change the switch from the wall or Alexa, the state doesn't get updated with Hubitat. Then when you try to toggle the switch in automations it doesn't work. The log has "SetBinaryStateResponse = Error" in at. I suppose because without the state update hubitat is trying to turn it off when it already is, and vice versa.


#42

Try hitting 'Refresh' for one of your WeMo switches in Hubitat, then update the switch manually or with Alexa. It looks like the switches aren't refreshing their event subscriptions, so they'll receive events for a while after you hit 'Refresh', but they'll eventually stop.


#43

I pushed updated drivers to GitHub that refresh their event subscriptions at the interval specified in the WeMo Connect app settings (5 minutes by default). Let's see how that does.


#44

Even with the new driver update, I was still having trouble with the status notification stopping. After watching the logs for a bit, I noticed the wemo stopped updating when the resubscribe function ran. (Stopped reporting at 5min. If I changed the refresh to 1 min in app then it stopped at 1 minute, etc.)

I made the following changes to the resubscribe function, and everything has worked for ~12hrs.

def resubscribe() {
    log.debug 'resubscribe()'
    def sid = getDeviceDataByName('subscriptionId')
    new hubitat.device.HubAction(
        method: 'SUBSCRIBE',
        path: '/upnp/event/basicevent1',
        headers: [
            HOST: getHostAddress(),
            CALLBACK: "<http://${getCallBackAddress()}/>",
			CONNECTION: 'Keep-Alive',
            NT: 'upnp:event',
            TIMEOUT: "Second-${getSubscriptionTimeout()}"
        ]
    )
}

Warning, I don't know anything about UPnP. So this is probably wrong and bad. But it's worked for me so far.


#45

Unfortunate. Mine worked for the first day or two, but some time in since then it stopped. I didn't exactly leave the driver a huge window for resubscribing (about 10 seconds), so that could have been the issue.

So, your solution is kind of kill-it-with-fire; instead of resubscribing you're just creating a new subscription every time. That will certainly work, but it runs the risk of having multiple overlapping subscriptions for a short period.

I'm going to try shrinking the resubscribe timeout and see if that's more stable.


#46

Jason(@jason0x43). I guess I've found the problem with Wemo Insight not showing up. In the WemoConnect log I see the following error: com.hubitat.app.exception.UnknownDeviceTypeException: Device type 'WeMo Insight Switch' in namespace 'jason0x43' not found on line 236 (updated)"


#47

Also did you find a solution to the resubscription problem?


#48

The driver name for the Insight was "Wemo Insight Switch" while the app expected "WeMo Insight Switch" (capital M). I pushed out an update to the Connect app that uses the proper driver name. Give that a shot.


#49

I hadn't looked into that in a while, but I think I see a problem. If it's left alone, the resubscription logic does what it should. However, every time an event comes in it's resetting the subscription timer, so if you, say, turn on a light a couple of times it could cause the resubscription request to be delayed until the subscription had expired. I'll work on that.


#50

Thanks, Jason
Insight switch is visible now in the list of devices.
I've also observed couple of small problems during my test on Device page:

  1. If Refresh or Poll command is run then the following parsing error is showing up in the log:
    errorjava.lang.NumberFormatException: For input string: "3311291.000000" on line 258 (parse)
  2. The Current States value never changes for Insight Switch, regardless the event changing the status. It always shows OFF. However it works fine for Switch or Light Switch.

#51

Odd. That looks like a valid number.

Do you ever see "Notify: BinaryState = " messages in the log?


#52

Question for you. When the Wemo devices are first added to the app they all stay in UNKNOWN status when they are selected in the dropdown box , so it requires to subscribe them manually in their respective device page one by one. Is it done intentionally and if yes can it be automated somehow? I have 22 Wemo devices and it's pretty time consuming to subscribe them individually after each hub update when the subscription is lost.


#53

Just tested. It's very strange. I guess it suppose to start with 1 for ON, but it starts with 8

When press switch ON: BinaryState = 8|1531510633|34|12069|16091|1209600|14|14575|2865815|3859213
When press switch OFF: BinaryState =
0|1531510633|41|12076|16098|1209600|14|14585|2865815|3859213


#54

Hi Jason (@jason0x43)

First, thanks for porting the code; it is much appreciated.

I have either found a bug, or an outright failure, so lets go with the lesser of the evils - a bug, I hope!

I have 3 Wemo Switches, and 1 Wemo Insight Switch. After successfully adding all apps & drivers, the Connect app finds all 4 devices, and add all 4 devices properly to my device list.

With reference to the attached image below, when issuing the on/off commands for the Wemo Switches, the Current State is successfully changed/updated. When doing the same action for the Wemo Insight Switch, the State is NOT updated.

Please note that in all cases the commands are actually successfully executed, to wit ALL the respective switches switch on and off.

Any ideas?

Thanks in advance
J


#55

Hmmm...it sounds like the Insight driver isn't processing received events, probably because its data format differs from the other WeMo devices and I normalized it too much. I'll review it and push out an update today.


#56

I pushed an update that:

  1. Reworks the subscription logic to be more robust
  2. Handles the unique "binary state" of the Insight switch (which actually has at least 3 values - 0 = off, 1 = on, 8 = standby)

Give that a try.


#57

Thanks a lot, Jason.

  1. Initial subscription logic is working perfectly.

There is a small bug. When On or Off buttons pressed the device doesn't respond.

The log error in Connect app
java.lang.NullPointerException: Cannot invoke method getDataValue() on null object on line 106 (childSetBinaryState)

on this line

def ip = device.getDataValue('ip')

  1. The logic for Insight switch is somewhere not correct, because the status shown on the device page always shows ON and never OFF.

Here are the logs for OFF and ON commands:

OFF:
dev:2592018-07-15 21:46:42.803:traceNotify: BinaryState = 0|1531705601|58|247|16625|1209600|21|0|70793|3930006
dev:2592018-07-15 21:46:42.781:traceparse()

ON:
dev:2592018-07-15 21:45:48.985:tracesubscribeIfNecessary
dev:2592018-07-15 21:45:42.431:traceNotify: BinaryState = 1|1531705542|0|189|16568|1209600|26|13740|56265|3915478
dev:2592018-07-15 21:45:42.389:traceparse()
dev:2592018-07-15 21:45:39.571:traceparse()
dev:2592018-07-15 21:45:39.061:traceNotify: BinaryState = 8|1531705536|7|189|16567|1209600|43|9710|56265|3915478
dev:2592018-07-15 21:45:39.040:traceScheduling resubscription in 270 s
dev:2592018-07-15 21:45:39.037:traceparse()
dev:2592018-07-15 21:45:39.035:traceUpdating subscriptionId to f106ef52-1dd1-11b2-a749-e9f04a95098e
dev:2592018-07-15 21:45:39.021:traceparse()
dev:2592018-07-15 21:45:38.975:debugresubscribe()
dev:2592018-07-15 21:45:38.094:traceNotify: BinaryState = 8|1531705536|7|189|16567|1209600|43|6460|56265|3915478
dev:2592018-07-15 21:45:38.053:traceparse()


#58

Ah, I see what's wrong there. I did some refactoring, and then focused on whether I was receiving updates or not when I was testing. I didn't actually try the on/off commands from Hubitat. I'll have a fix for that out shortly.

It's tricky to make a driver for a device I don't have. :slight_smile:

I pushed up a new version that fixes the command bug and should handle the multi-parameter state values used by the Insight.


#59

Jason (@jason0x43), so far, looks like you fixed my issue... Will advise if I find anything remiss.

Thanks
J


#60

I've just set up 2 wemo switches with your code, many thanks for the code. It seems to work fine from the device page in Hubitat and the can be discovered by Alexa, however, they both appear as a bulb in the Alexa app. The description is "Lux Light" Type "Light" colour capabilities "None". If I tap the control in the switch as intended, but this isn't user intuitive.

Is there anyway to change this? Is it something anyone else has seen?

Thanks