UselessMnemonic / OpenWiz

A C# library for remote controlling Wiz brand smart lights
MIT License
22 stars 3 forks source link

Does this still work? #5

Open isaacrlevin opened 1 year ago

isaacrlevin commented 1 year ago

@UselessMnemonic started seeing socket timeouts recently. Are you able to still communicate with lights on your network?

WhoDunDidIt commented 10 months ago

Still works for me, yep! I recently forked the repo to update it to support .NET 7 (recently = about 30 minutes ago), as this is going to be my standard library for handling the few Wiz lights I own.

isaacrlevin commented 9 months ago

@WhoDunDidIt do you have a repo I can take a look at?

WhoDunDidIt commented 9 months ago

@WhoDunDidIt do you have a repo I can take a look at?

Sure thing! https://github.com/WhoDunDidIt/OpenWiz

Note: I've since moved to use Home Assistant for all my lights, so I likely will not be doing much with this project any more.

isaacrlevin commented 9 months ago

Wow that was fast! I just cloned your code and am still getting a timeout receiving from the socket. Do you have some sample that works getting HomeIds?

WhoDunDidIt commented 9 months ago

HomeIds

Not sure what this is, as the library was only intended to work with Wiz compatible bulbs (typically from Walmart or Home Depot). However I stripped this out of the app I wrote that let me control my lights using a keyboard shortcut. I no longer use it, as I now have become addicted to Home Assistant and control my office lights via a motion sensor now.

However, the code should work just fine, as nothing would have changed with the bulb. I'd double check firewall settings, and ensure that the device you're running it on can talk to the bulb on whatever network it is on. If you have your bulbs in a different VLAN for example, that could cause issues.

private WizHandle _wiz;
private WizSocket _sock;
private readonly WizState _oldWizState;
public bool IsLightOn = false;

// Configure the connection to the bulb
_wiz = new("macaddress", IPAddress.Parse("ipaddress"));
_sock = new WizSocket();

// Capture and save current bulb state
_sock.SendTo(WizState.MakeGetPilot(), _wiz);
_oldWizState = _sock.ReceiveFrom(_wiz);

// Set the flag to the state of the light
IsLightOn = _oldWizState.Result.State.Value;

// <...>
// <...>
// <...>

// Set the state of the light based on the state of the flag (bool)
_sock.SendTo(new WizState()
{
    Method = WizMethod.setPilot,
    Params = new WizParams() { State = Settings.IsLightOn }
}, _wiz); ;
isaacrlevin commented 9 months ago

Ah so you know the Mac and Ip of the light.... I want to be able to detect the light on the network

WhoDunDidIt commented 9 months ago

I never played around with discovery, sorry :(