LIFX Developer Zone

Controlling LIFX switch with code

Hi :wave:

My entire house is now using LIFX switches, some smart bulbs and some non-smart using the relays.

I have also got Flic buttons deployed in various places for ease of use.

While I can control LIFX bulbs (both lan and cloud) I cannot seem to work out how to use Flic to control a individual switch for a non LIFX light.

First question- anybody know how to do this out of the box?

If not I am considering how I could write a lightweight web service that I host on my media server. The flic allows you to call a custom url with parameters which could in turn hit the switch over the lan. Anyone done something similar or have any ideas? (Any pre built libraries that could be used with python etc As I am not a hardcore coder than will drop down to writing C!)

Side note: I don’t want to have to install homeassistant and node red etc if I can help it as it seems a little overkill for requirements, but open to hearing arguments for it! :slight_smile:

Thanks for reading!

It’s possible to do this with a Flic and Photons Interactor. Setup Interactor on a local Docker-enabled device and then sent REST commands at it from the Flic.

The Interactor command to SetRPower (Set Relay Power) is:

{
    "command": "set",
    "args": {
        "matcher": {
            "serial": "{{ serial }}"
        },
        "pkt_type": "SetRPower",
        "pkt_args": {
            "relay_index": {{ relay }}, # numbered from 0
            "level": {{ level }} # 0 = off; 65535 = on
        }
    }
}

And to obtain the current state:

{
    "command": "query",
    "args": {
        "matcher": {
            "serial": "{{ serial }}"
        },
        "pkt_type": "GetRPower",
        "pkt_args": {
            "relay_index": {{ relay }} # zero indexed
        }
    }
}

The response looks like this:

{
    "results": {
        "{{ serial }}": {
            "payload": {
                "level": 0,
                "relay_index": 1
            },
            "pkt_name": "StateRPower",
            "pkt_type": 818
        }
    }
}

Edited to remove the quotes around the numeric values in the SetRPower example.

Awesome - I will give this a go!

Just wanted to report back… used photons with node red container… took a bit of messing around as not used node red before but got it working. Thanks for the tip.

1 Like

You’re welcome. :slight_smile: