rgomezjnr / wizcon

Control Philips WiZ Connected smart light bulbs
https://pypi.org/project/wizcon/
MIT License
39 stars 7 forks source link

Enable Disable WiZ Motion Sensor #3

Closed djacobson closed 2 years ago

djacobson commented 3 years ago

I was wondering if it might be possible to Enable and Disable a WiZ Motion Sensor via wizcon? I see that it mostly uses pywizlight but have not found that setting there.

rgomezjnr commented 3 years ago

Hi djacobson,

I don't think wizcon and the pywizlight library support WiZ Motion Sensors, but you could try it. I'm not familiar with WiZ Motion Sensors but if they have an interface similar to the smart bulbs it might work.

Does the WiZ app actually let you enable and disable the motion sensor?

As a first step you could try to discover the motion sensor with pywizlight library to see if it's accessible. Maybe something like:

import asyncio

from pywizlight import discovery

async def main():
    """Sample code to work with bulbs."""
    # Discover all bulbs in the network via broadcast datagram (UDP)
    # function takes the discovery object and returns a list with wizlight objects.
    bulbs = await discovery.discover_lights(broadcast_space="192.168.1.255")
    # Print the IP address of the bulb on index 0
    print(f"Bulb IP address: {bulbs[0].ip}")

    wizlights = await discovery.find_wizlights(broadcast_address="255.255.255.255")
    print wizlights

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

It seems like you can toggle Philips Hue Motion Sensors, but perhaps not WiZ Motion Sensors? https://github.com/lukasroegner/homebridge-philips-hue#motion-sensors

  • Switch for enabling/disabling the motion sensor

If you really want this capability you could try developing your own system. These are a few projects that have done this with the Philips Hue bridge:

Related: Philips Wiz (not Hue) Bulbs: how can we advocate for an API - Hardware - Home Assistant Community (home-assistant.io) [Release] Philips Wiz Color Light Driver - Developers / Code Share - Hubitat

@sbidy and the pywizlight team are probably more knowledgeable about this than I am. Let me know if I can help you further.

Robert

djacobson commented 3 years ago

Thx for the awesome reference projects! I'll give your approach a try and post here. Yep, most of the manufacturers have different motion sensors for their wifi only (hub not required) product line. For Phillips, the WiZ wifi connected motion sensor is different than the Hue motion sensor, only works with WiZ devices. For Lutron, the Caseta motion sensor is different from the Lutron wall-mounted motion sensor. And then there's the Cync by GE (formerly C by GE) motion sensor, which, of course, works only with Cync bulbs / devices. These "kinda wifi but not 100%", mostly Bluetooth (BLE), "kinda smart but mostly dumb" motion sensors are relatively new products on the market. I think they're neat but still need to mature. Now, building my own with a Pi would IDEAL! :) Of course, a little more pricier than these products but, still, great project idea. :) Again, thanks for your insight! Feel free to close this issue.

rgomezjnr commented 3 years ago

Yeah sure thing let me know how it goes, I'm curious. I would think that the motion sensors use a similar API/interface as the smart bulbs. The motion sensors may not be controllable via pywizlight since the PilotBuilder and wizlight classes are specific for smart light bulbs but they may be discoverable which would be a good indicator that they could be controlled with additional code and knowing the motion sensor interface. It might also be possible to interact with the sensors using UDP messages, see pywizlight's sendUDPMessage method.

sbidy commented 3 years ago

I don't have a WiZ motion sensor for a test, but I'm sure that the sensor is also providing a UDP interface. Maybe make a nc call to it 😃 .

The main difference between the WiZ plug and the WiZ light is, that you have to listen for a UDP message from the sensor in case of a motion detection/state change. But this should be possible via the “registration” function, but to integrate this "always listen" mode to HASS can become a horror 😉.

At the end I think a kind of “bridge service” between the WiZ Sensor and HASS makes this easier. Like the Hue Bridge or other,

rgomezjnr commented 3 years ago

Thanks for the input @sbidy. netcat is a great suggestion.

djacobson commented 3 years ago

So, honestly, I'm not sure if... when I specify Active and Inactive time periods for the WiZ motion sensor in the app, whether it's actually sending any kind of command or config change to the motion sensor; or whether it's just telling all of the associated devices / bulbs in that room to just ignore BLE commands from the motion sensor during that time. ? If so, it would support the theory that these motion sensors are really dumb devices and can not be communicated with... BUT, if that is the case, how does one send the "ignore BLE" command to the bulbs then... ? Just speculating...

djacobson commented 3 years ago

Also, the reason I love the DIY Pi motion sensor project idea is that it could potentially do just about anything and across manufacturers, like turn on/off ceiling fans+lights, etc. ... not just the matching manufacturer as is the case with most of these motion sensor products.

rgomezjnr commented 3 years ago

Were you able to try using netcat or discover the motion sensor using pywizlight?

when I specify Active and Inactive time periods for the WiZ motion sensor in the app

So are you simply looking for another method besides the WiZ app to enable and disable the sensor? Do you want to schedule the sensor AND manually enable/disable it? The WiZ app doesn't allow this?

Yes, creating your own motion sensing project would be ideal so you have the most control and flexibility.

Besides that, you might be better off with the Philips Hue bridge and the Hue motion sensors:

https://www.home-assistant.io/integrations/hue/

The Philips Hue integration allows you to control and monitor the lights and motion sensors connected to your Hue bridge.

and

It seems like you can toggle Philips Hue Motion Sensors, but perhaps not WiZ Motion Sensors? https://github.com/lukasroegner/homebridge-philips-hue#motion-sensors

Switch for enabling/disabling the motion sensor

djacobson commented 3 years ago

So are you simply looking for another method besides the WiZ app to enable and disable the sensor? Do you want to schedule the sensor AND manually enable/disable it? The WiZ app doesn't allow this?

Yes, the WiZ app does allow the user to enable+disable and schedule the motion sensor (or sensor functionality). I was just curious HOW it achieved that, by either config'ing the motion sensor, or by config'ing the bulbs in the associated room. ? I think netcat might help show that? I suspect I'll need to inspect the port on a test bulb as well as the motion sensor.

The Philips Hue integration allows you to control and monitor the lights and motion sensors connected to your Hue bridge.

Right now, I'm not interested in adding a Hue bridge (yet another hub in my house) but, I see the benefit. I'm just interested in the purely wifi WiZ products right now and improving cool tools like wizcon. :)

It seems like you can toggle Philips Hue Motion Sensors, but perhaps not WiZ Motion Sensors?

Hmm. But, the WiZ app achieves this with WiZ motion sensors just fine somehow. That's why I'm curious about how it does it (without a bridge). I'm suspecting it configs the WiZ smart bulb associated with the sensor to ignore it rather than changing the sensor. If that is the case, being able to change that setting on the smart bulbs (BLE ignore I suspect) would be a pssoble cool API addition. ...just a thought.

rgomezjnr commented 3 years ago

I'm suspecting it configs the WiZ smart bulb associated with the sensor to ignore it rather than changing the sensor.

That would be interesting. Unfortunately we don't have any public API or protocol documentation that I know of, so we're relying on you to experiment and learn what you can since you have the hardware.

You could also try using Wireshark to inspect the packets to and from the motion sensor or smart bulb in order to reverse engineer the protocol.

If the system does indeed use BLE you could use a Bluetooth sniffer like Adafruit's Bluefruit LE Sniffer - Bluetooth Low Energy (BLE 4.0) - nRF51822 [Firmware Version 2].

motion-sensor-device.js might be a good reference for understanding the WiZ implementation of motion sensors if it shares any similarities with the Hue Bridge system. @lukasroegner do you have any feedback on WiZ vs Hue Bridge motion sensors?

lukasroegner commented 3 years ago

I'm sorry, I haven't worked with WiZ. As you can see in the file that @rgomezjnr referenced, the Hue API supports enabling/disabling sensors of type ZLLPresence.

rgomezjnr commented 3 years ago

Thanks for the input @lukasroegner. I know there are probably implementation differences between the Philips Hue and Wiz devices. Would you and @djacobson be willing to work together on researching and understanding the protocol or API for Wiz motion sensors? What was the development / reverse engineering process like for homebridge-philips-hue ?

I wouldn't mind adding support to wizcon for Wiz motion sensors as @djacobson is requesting. I would probably need a library to interact with the device similar to pywizlight.

rgomezjnr commented 3 years ago

FYI another good resource may be housewiz. @pascal-fb-martin do you have any experience with Wiz motion sensors or do you know if housewiz can be extended to support Wiz motion sensors?

djacobson commented 3 years ago

Just sharing some evolving thoughts on this...

To clarify and review, this thread is referring to the following WiZ motion sensor product: https://www.wizconnected.com/en-US/consumer/products/046677603472/

NOT this Hue motion sensor product, which I believe requires a Hue hub/bridge: https://www.philips-hue.com/en-us/p/hue-motion-sensor/046677473389

...although the two might have similarities, I suspect a user might have to config and control the Hue version via the Hue hub API? I don't know.

But, back to the WiZ sensor... these wifi-only motion sensors might be a little more limited in features than their hub counterparts, i.e.: one might only be able to enable/disable them in a "room". Where other motion sensors can be scheduled, assigned to specific devices in a room, etc. I don't see that with the WiZ sensor... BUT, that would be one of the cool things of at least being able to programmatically enable/disable it... one could then custom schedule that themselves via a Homekit script, cron job, etc.

One odd think I noticed simply trying to understand what the WiZ motion sensor was in fact capable of... on Phillip's WiZ web page (https://www.wizconnected.com/en-US/consumer/products/046677603472/), their motion sensor feature description says:

"Set the sensor to trigger different light modes during different times of the day in the WiZ app (e.g. warm white in the evening or nightlight after bedtime)."

I'm thinking this is NOT a motion sensor feature specifically, even though it seems to be implied by being on the motion sensor feature page. After looking closely at the WiZ iOS app, I'm thinking this is referring to the "Rhythms" WiZ bulbs scene and scheduling feature... the motion sensor simply turns devices on or off, the devices have independently set their colors.

So, again, what would be the motivation to programmatically interface with the WiZ motion sensor. Again, I think to simply enable and disable it on auto-command, at any desired time. I'm starting to think that's about all the sensor is capable of.

CORRECTION: The settings on the WiZ motion sensor in the WiZ app are Motion Detected: Action (ON or OFF, or a color scene), Motion NOT Detected: Action (ON or OFF, or a color scene), Delay (min), Advanced Settings: Detection delay (Enabled or Disabled). I don't see a place where I can schedule Enable and Disable of the motion sensor.

pascal-fb-martin commented 3 years ago

FYI another good resource may be housewiz. @pascal-fb-martin do you have any experience with Wiz motion sensors or do you know if housewiz can be extended to support Wiz motion sensors?

Sorry, I just found out these existed (and are available at my local Home Depot). From the description, I inferred that you can configure it to control another Wiz device (or multiple Wiz devices). I have a future plan of using this type of device by configuring it to point to..an application that simulates a Wiz device. Then I can do whatever I want with the sensor report, including controlling other types of devices (and brands).

My understanding is that Hue and Wiz are from independent origins, and have no compatibility whatsoever.

pascal-fb-martin commented 3 years ago

About housewiz: this program is designed to be a "micro service" that does only one thing (control Wiz devices on and off). It does not run in a vacuum: I have a suite of other services that collaborate with each other. For example houselights is capable of scheduling lights on and off by talking to specialized micro services through a shared web API, for example Orvibo smart plugs, Wiz or (hopefully soon) TP-Link Kasa switches. This way I can modify one protocol implementation without impacting the others (not even stop and restart). You can see this micro service approach as a more modern take on the driver or plugin concepts. This came after some frustration adding protocols to my monolithic home server, which I slowly retire, feature by feature.

So any future support for Wiz sensors will probably come as a separate micro service. It is possible for one program to implement and advertise multiple web APIs, so it might still make it into housewiz..

djacobson commented 3 years ago

@pascal-fb-martin Just an FYI if you experiment with the WiZ motion sensor... I tried using it with the WiZ smart plug, to power on/off a regular lamp, and (I think) I discovered a bug in the WiZ smart plug firmware where, when it was powered on and off by the motion sensor, it would eventually disconnect from WiFi (although still work with the BLE on/off commands from the WiZ motion sensor). I got rid of the smart plug and went to a WiZ smart bulb an everything works fine and reliable with the motion sensor (telling me the issue was with the WiZ smart plug). Anyways, I tried to report it to Phillips WiZ tech support, and they tried to take me down a long rabbit-hole of testing my wifi network (there's nothing wrong with my wifi, lol). Just an FYI, I thought it would have been neat to have both a WiZ bulb and smart plug working with the WiZ motion sensor, just for kicks, but, oh well. :) I kind of wonder about the quality of those smart plugs anyways... how many companies offer them now? ...I've lost track.

pascal-fb-martin commented 3 years ago

BLE? Humm, I did not notice the "works even when WiFi is down". That's a bummer: BLE does not have the same range, and is not as convenient as, WiFi. It might still be possible to query its status through WiFi, so a bit of polling could work, but possibly at the cost of depleting the battery. Too bad.

Thanks for the smart plug tip. I hope this is because the product is new, but it does not bod well for the switches and dimmers they pre-announced.

djacobson commented 3 years ago

I'm not aware of any 100% wifi motion sensors except for DIY Pi projects. I don't count the classic motion sensors that are a permanent part of a wall switch. I have used this one (Phillips WiZ), the Lutron Caseta wireless motion sensor, and the Cync by GE wireless motion sensor. They all do either BLE or some other proprietary protocol to trigger on/off the "assigned" devices in close proximity. I suppose old disconnected motion sensors (that were not wired directly to a switch) might have used RF? But, at least some of these new'ish wireless motion sensors appear to be somewhat configurable via wifi (except for that GE Cync one... it is weird; you have to config it using Bluetooth from their phone app, and it use BLE with their bulbs... I returned it and the bulb after discovering the first bug in their scheduler and getting spooked by all the negative comments online). Anyways, even though these wireless motion sensors are obviously cheap devices, I like that they have been freed from being wired directly to a wall switch, and can trigger multiple devices (mostly smart bulbs) in a close area (room).

djacobson commented 3 years ago

Just to reiterate some of the motivation to programmatically interface with this WiZ motion sensor, use-cases like described below are common and scheduling is a feature IMHP the manufacturers don't seem to give much importance to in their app(s)...

Reddit user [West_Emu_1777], for a Caseta motion sensor: "I have the caseta and motion sensor in my kitchen. The motion sensor is configured to turn on the kitchen lights at 30% power for the evening, to not auto turn on in the day but to auto turn off after five mins anytime of the day or evening. With me so far? Now, for the caseta switch itself, you can also schedule a time it turns on and at what percent and another time to turn off."