Switch off all Lifx lights on network

I have 6 LIFX lights connected to same network - I want to switch off this lights from my code at one tap. In LIFX app, we can do that if we switch off All Lights, but can we know what packets should I send to achieve this. We tried to watch WireShark packets but there were only packets of GetService UDP call from the app.

Hi,

You’ll want to send a SetPower message https://lan.developer.lifx.com/docs/light-messages#section-setpower-117 with level = 0.

You can either broadcast it to the network or you can first broadcast a GetService to find your lights and then send the SetPower to each device individually.

If you have python3.6 or python3.7 installed you can do a

pip3 install lifx-photons-core

and then run
lifx lan:transform -- '{"power": "off"}'

and that will search for lights with a GetService and then send a SetPower to all the lights it finds. (or something similar to this https://github.com/delfick/photons-core/blob/master/examples/make_blue.py in code)

I’m sure it’s also not too difficult to do with https://github.com/mclarkk/lifxlan if you prefer that.

:slight_smile:

Hello,

We used both of the above libraries - they broadcast the packet on Network broadcast address like 192.168.1.255 which we can see in Wireshark, But the power off from LIFX app does not show any packet in Wireshark. The response of Broadcast port 192.168.1.255 degrades after 3-4 commands but it work very much fine in LIFX Android App. If you can provide us what packet is transmitted - I can try the same packet from my program. Basically, I want this to run in house which has around 60 LIFX lights.

The app keeps a database of visible lights by continually sending GetService messages and tracking the responses. Then when it needs to turn off the lights it sends unicasts directly to the bulbs with the SetPower message.

Depending where you are running Wireshark and your network configuration from you may not see the unicast packets.

We’ve coded exactly on those lines. The issue really is the response to the consumer wherein the each light takes its own time and they differ from one another thus giving us a popcorn effect in the end.

When we send the All On or All Off command from the LifeX App, the response seems to be instantaneous and with a minimal visible effect and feels like all the lights respond at once.

Is the light switch on to allow the bulb to be turned off and on in the app?

 from LifxLAN import *

 for light in LifxLAN().get_lights: 
    light.set_power(0)

If you have a group you want to single out

NAME = "Room 1"

LifxLAN(). get_devices_by_group(NAME).set_power(0)

Where NAME is the string you named your group.

1 Like