dkerr64/homebridge-yolink

Add support for YoLink MultiOutlet

dkerr64 opened this issue · 32 comments

Describe the solution you'd like:

Add support for YoLink MultiOutlet

[20/08/2022, 17:07:46] [YoLink] YoLink device type: 'MultiOutlet' is not supported (YoLink Power Strip (xxx)) (initialize)
Please report all bugs at https://github.com/dkerr64/homebridge-yolink/issues
{"deviceId":"xxx","deviceUDID":"xxx","name":"YoLink Power Strip","token":"xxx","type":"MultiOutlet","parentDeviceId":null}

@hdinwiddie if you can please capture any other logs that reference this device please (e.g. use the YoLink app to turn on/off an outlet, that should trigger notifications on this plugin log.

David, I found my multi-outlet and plugged it in and it's showing fine in YoLink. I then restarted both Homebridge and your YoLink plugin a couple of times and am attaching the YoLink part here. I'm seeing NO red faults this morning, but the multi outlet is not picked up. This thing should end up with 5 switches...an all on/off (master), a switch for each of the four outlets, and a single switch for the four USB ports. Good luck and let me know if I can do anything else to help
homebridge.log(YoLink00821.txt
.

David, I found a way of saving the log file in color if it helps at all. If not, let me know and I'll continue to grab it as an ordinary text file. There were some "red" entries in there.
screencapture-homebridge-local-logs-2022-08-21-09_31_54-compressed.pdf

Thanks for both logs. The color version is helpful as it helps focus in on the important stuff... but the text version is good too as I can then copy/paste the JSON (data in the curly braces).

Its interesting that you get so many "device offline" for your hub. Suggests that this device really isn't connected to your YoLink account any more. Hub's are not interesting for Hombridge... they don't add anything. I would suggest going into the config file and adding a section for this specific device and then hiding it.

MQTT reconnect errors suggest a brief network hiccup, but it recovered. I have additional logging around MQTT because I want to learn how it copes with network problems. I do need to check that I am not registering for MQTT more than once though.

Here is the first interesting part from your log... info returned from the getState request.

{
	"state": ["open", "open", "open", "open", "open", "closed", "closed", "closed"],
	"delays": [{
		"ch": 1,
		"on": 0,
		"off": 0
	}, {
		"ch": 2,
		"on": 0,
		"off": 0
	}, {
		"ch": 3,
		"on": 0,
		"off": 0
	}, {
		"ch": 4,
		"on": 0,
		"off": 0
	}],
	"version": "0108",
	"tz": -4,
	"loraInfo": {
		"signal": -9,
		"gatewayId": "d88b4c16040002fc",
		"gateways": 2
	}
}

"open" means that the outlet of on, "closed" means off. But there are 8 members to the state array. This report shows 5 on, 3 off. A later log (in your color version, not the text) shows only the first on and all others off. I'm thinking I can always assume that the first entry represents the "master" switch.

Then there is an array for delay on/off times. There are only 4 in this. Which will represent the actual four outlets you have. In other words, if I wanted to automatically detect the number of outlets I need to do it based on the "delay" array not the "state" array. I'm not sure that automatically detecting number is a good idea, but would be a fallback to a configured number.

There is also (in the color version, so I can't copy/paste) in orange a MQTT: Outlet.powerReport message that I am not handling. This is coming from a different device, not your power strip. HomeKit does not officially support power meters. The Elgato Eve has added a custom service to support that and it is visible in their app only. Some plugins have implemented it. For now I think I will just gracefully ignore it.

I have a hub I use for demo purposes as I occasionally teach smart home classes for my large retirement community computer club (2500+ members) as I'm going to do this week. I was going to ask you if it would be possible to have the system able to stop looking so hard for devices that might be purposely offline for a period of time, especially plug-in devices. I know that time would be hard to define.

Yes. Is documented. You need to add a devices section to the config (can be done in the home bridge user interface).

"devices": [
                {
                    "deviceId": "<hub ID from log... 16 character long hexadecimal string>",
                    "config": {
                        "hide": "true",
                    }
                }
]

You can also do the opposite... ignore everything unless specifically listed in the config file. See docs.

I removed the "Classroom Hub" from YoLink as I'm not using it and can reinstall it if I do. I hid my primary hub from the configuration. I noticed the first pass after restarting the YoLink plugin it removed the Classroom Hub from cache and on the second restart there was no mention of it. Realistically there is nothing much gained by keeping items not used for a period of time in the YoLink app inventory especially if you're going to be using YoLink in Homebridge. I suppose the same is true for other plugins, but devices in other services aren't nearly as easy to uninstall/install as are YoLink devices.

David, this PDF should allow you to copy/paste. Would you try it? Is it helpful
HomeBridgeYoLink08222.pdf
?

@hdinwiddie please try version 1.1.3 that I just published. In theory it should work with your power strip, but as I don't have one I cannot test. The area most at risk of not working is turning outlet(s) on/off.

In Homebridge you should see multiple tiles, four "outlets" and one "switch" for the master on/off. In Apple Home you should, I think, see just one tile under which will be the four outlets and switch. I think Apple Home will give the option to show all as separate tiles. For now this is hard coded to 4 outlets but it is simple enough to change.

This is flagged as "experimental" so you will need to set that to true in the config, if you don't have that already.

@hdinwiddie Thank you for testing. So the first "outlet" is actually the USB ports. I'll change the label. For some reason I thought there was a master on/off.

Can you capture a full log please (with verbose on) and I'll see if I can figure out what is going on with the on/off setting. I'm in particular looking for the "SENDING" and "RECEIVED" logs as that shows me what is going to/from YoLink and should help me figure out why it works once and never again.

Thanks.

I'm sending you the text of the log that I quite long, but think I captured the multi-outlet device. My siren is turned off and I can turn it on to take another log (verbose) so that device doesn't take up so much of the lo
homebridgeyolink.log.txt
g

Ok, I turned the alarm back on to "clean up" the log. Here's the same thing, but without the alarm taking over..
homebridgeyolinkminusalarm.log.txt
.

@hdinwiddie Looking at the logs they seem to stop after startup... I don't see any logs of you trying to switch on and off any of the outlets? Can you try that please. I only need to see the logs from the point that you start that... all the startup stuff looks to be working as expected.

Thanks

David, here's a log where I captured the initial state and then cycled through each button, starting with the USB outlets. I hope it will show you what you're looking for. I cycled through them both directions
homebridgewhoingactivity.log.txt
.

Please try version 1.1.4 that I just published. I noticed one problem with my code when I was able to see the returned data from YoLink... but I'm not sure it it will help or not.

Thanks

David with your latest change the buttons all work fine in both the Homebridge devices and the Home app! That's awesome. In the middle of the night I realized and hadn't given you logs showing the outlet master being cycled on and off because it doesn't show and I was using the Home app to do the cycling. This morning I did it again, but operating the buttons from the YoLink app so you could see everything working. After things settled down I cycled ALL of the buttons. I started with everything on. I then cycled the master power about three times and then turned each outlet off from 1-4 and then the USB power. Afterwards I turned them back on again and ended up cycling the master power a couple of time. I really hope this is better for you. The USB power is working, but showing in Home as the master on/off slider although it operates only the USB outlets. I hope this makes sense and will make it easier for you. You awfully close!!! Thanks so much
homebridge0822a.log.txt

@hdinwiddie can you tell me how the master functions please... lets say I have two of four outlets turned on, then I master off so nothing is on. If I master on again do all outlets turn on, or does it restore to previous state where only two of the four are on?

For the USB... this can be represented as either a switch or a outlet. Right now I chose switch, mainly as a legacy of me thinking it was a master on/off. But I can easily change it to an outlet. And/or I could make it user configurable. Do you have an opinion? I am leaning towards making it an outlet like the rest mainly because it will help if YoLink come out with another multi-outlet where the first one is a regular outlet and not a USB. And at some point I can add a user setting to make it a choice.

That is a GREAT question and makes me realize why the master might be causing problems. Actually, it's not really a master, but a way of turning everything off and everything on. If you have a couple of outlets on and operate the master then they turn off...everything you have on turns off. When you turn it on, then there is no memory, but every outlet turns on. Furthermore, while it's "off" you can still turn on any outlet you want. So in essence it's just kind of a shortcut to turn off whatever you have on and then turn everything on later with that same switch. No wonder it's creating programming head-scratching. I think showing the USB as an outlet labeled USB Power or something like that would work best. I'm attaching another log where the only thing I'm actually operating is the All/On-All/Off switch and the USB Power switch...I'm not touching any of the four outlets. I hope it will make things clearer for you
homebridge.log.txt
.

Here's a screenshot from the YoLink app which shows what you see that way
IMG_1040 2
.

@hdinwiddie this really helps. There is no need for me to implement an all on / all off in this plugin as that can be done in Apple Home by creating a scene that does the same thing... link all outlets together and then operate all from one tile -- is a common thing.

@hdinwiddie can you please test 1.1.5 please. I have changed treatment of USB charting ports to be just any other outlet. USB will be identified as "Outlet 0" then the main power outlets as 1..4.

Thanks

I just tried it and what I'm seeing on my iPhone and my Macbook Pro is row of 5 power buttons which correctly operate all 4 outlet plus the USB ports, so that part is perfect...there are no labels on the buttons...there is also showing a power-slider which doesn't do anything that I can see.  That could just be eliminated if possible?
Screen Shot 2022-08-23 at 9 42 13 PM
\

I think the on/off slider is a hang over from last version where I use a "switch" to control the USBs. But I decided it was much cleaner to treat them the same. To remove the on/off slider I think you will have to remove the power strip from the Homebridge Cache. From Homebridge select the three dots at the top right, go into Homebridge Settings and scroll down to you see "Remove Single Cashed Accessory". Select that and then look for the power strip and remove it. Then restart.

DO NOT choose option that says remove all cached accessories... you have so many that if you do that you will likely create a LOT of work for yourself on the Apple Home side of things. Just remove this one.

image
image

I don't know why names are not appearing next to each outlet button. Are the names appearing on the Homebridge tiles accessory view? You may have to set name in Apple Home. As I don't have one of these I can't try myself.

IMHO you can stick a fork in this one, David. It works perfectly for me now. The cache suggestion totally worked. I have control of the naming of individual outlets in both Homebridge Accessories and in the Home app and see I can choose to show them as a group or as individual tiles. I also see that I can create an automation in Homekit using any single outlet, which is terrific! You did a really nice job for something with so many features that you don't have in your possession. Thank you!!
YoLinkMulti
!

Believed to be fully functional with no bugs.

There is no "master" on/off in the powerstrip... YoLink is implementing that feature in their app. I have observed Homebridge and HomeKit getting out-of-sync with some devices but have not been able to figure out why yet. I don't have their powerstrip yet so can't debug right now.