delfick / photons

Python3.6+ asyncio framework for interacting with LIFX devices
https://photons.delfick.com
MIT License
71 stars 6 forks source link

Issue Getting Data From Mini Style Bulbs #119

Open xeroiv opened 1 year ago

xeroiv commented 1 year ago

I have a variety of LIFX devices in my home and am trying to log the wifi signal strength from them over time. I have found that all the DeviceMessages that I send to mini style bulbs (color or dd) always time out. My code has no issue getting responses from the BR30 style bulbs or the LIFX Z controllers. Is there anything special that I need to configure in order to receive messages from these devices? They are online and responding to UDP requests from my Loxone miniserver. Here is a snippet of the code that I was using to test receiving the messages back.

async def my_getpower(target, object):
    reference = HardCodedSerials(object)
    async with target.session() as sender:
        try:
            get_power = DeviceMessages.GetWifiInfo()
            get_label = DeviceMessages.GetLabel()

            async for pkt in sender([get_power, get_label], reference):
                if pkt | DeviceMessages.StateWifiInfo:
                    print(f"Device {pkt.serial} has power level of {pkt.signal}")
                elif pkt | DeviceMessages.StateLabel:
                    print(f"Device {pkt.serial} has a label of {pkt.label}")
        except:
            print(f"No Response from {object}")
delfick commented 1 year ago

I'm unsure why the minis would ignore that packet. I'd suggest contacting their support team and seeing if they can ask an engineer for you.

Though I will say the signal strength information is largely useless.

also, a couple notes on your code sample,

you likely want something more like

async def getpower(target, reference):
    def error_catcher(error):
        print(
            f"Failed to get information from a device: {type(error).__name__}: {error}"
        )

    async with target.session() as sender:
        msgs = [DeviceMessages.GetWifiInfo(), DeviceMessages.GetLabel()]

        async for pkt in sender(msgs, reference, error_catcher=error_catcher):
            if pkt | DeviceMessages.StateWifiInfo:
                print(f"Device {pkt.serial} has power level of {pkt.signal}")
            elif pkt | DeviceMessages.StateLabel:
                print(f"Device {pkt.serial} has a label of {pkt.label}")

which logs something like

12:52:16 ERROR   photons_transport.comms Didn't find some devices       missing=['d073d5443322']
Failed to get information from a device: FailedToFindDevice: "Couldn't find a device"   serial=d073d5443322
Failed to get information from a device: FailedToFindDevice: "Couldn't find a device"   serial=d073d5443322
delfick commented 1 year ago

(HardCodedSerials caches the ip addresses of the serials it's aware of but if you're not using outside of one sender object and you already have a string or a list of strings, then you might as well just pass those into the sender directly as that has it's own cache anyways)

xeroiv commented 1 year ago

Thanks for the tips on how to better implement the code. I'm fairly new into python so my original snippet was probably quite sloppy. The reason I am grab the wifi signal strength is so that I can log it over time with influxdb and test out some different wifi configs with my unifi setup. I have some rogue bulbs that play nice one day but then go unresponsive for days at a time. So I am moving my unifi access points around and playing with some of the settings to see if I can get a more reliable setup. I will see if the engineers at Lifx can offer any insight, but given that this is third party to them I thought I'd ask here first.

delfick commented 1 year ago

Yeah, reasonable. I'm unsure if the data those packets return will be useful in either case, but I could be wrong

Djelibeybi commented 12 months ago

Note that Home Assistant has an RSSI sensor (which is disabled by default) for LIFX bulbs. I have it enabled across my entire fleet that contains ~40 Mini Color bulbs and they all respond fine. Also using UniFi networking, so I understand your frustration dialling this in.

My advice is to create an SSID specifically for your LIFX bulbs with everything except DTIM period and minimum data rate disabled. Here is my config which has been pretty stable for about a year now:

Screenshot 2023-07-26 at 11 05 06 am

And here's a graph of RSSI for my office ceiling light for the last 24 hours:

Screenshot 2023-07-26 at 11 07 10 am

The dip is when I reconfigured a different SSID and the UAP-AC-IW that's in my office restarted so the bulb reconnected to another AP for a while.