Control LIFX WiFi light bulbs from Google Apps Script

LIFX

Here is a simple apps script to control LIFX WiFi light bulbs. It turns on the bulbs in the morning until a little after sunrise and then again in the evening before sunset until a configurable time. As a bonus it will also rotate between some seasonal colors in the evening on several holidays.

To get this up and running you need a LIFX access token (from here) and a selector. If you have a group of lights called bob this would be group:bob. It could also be a single bulb ID like id:d3b2f2d97452 (more details here). There are some other settings you probably want to change: Latitude and Longitude (if you don't live in San Francisco for some reason), OnHour and OffHour for the time to switch on before sunrise and off after sunset, DaytimeOffsetMins is the minutes to wait after sunrise before switching off and before sunset for switching on, and then finally default color, brightness and fade time.

In Google Drive create a new apps script project and copy in the following code:

Configure the settings at the top in the code editor. Switch to settings (cog at the bottom of the right hand menu) and make sure the script time zone is correct for your location. Back in the code editor run the function nightSchedule() to check that everything is working as expected. This will print the calculated times and then switch the light on or off. Once you're happy with this, go to the Triggers page (clock icon) and set nightSchedule() to run as often as you like (I use every minute).

The current design of the script will update the bulb(s) every time you run it (so if you manually toggle on during the day the script will turn the light off the next time it runs). It would be possible to store the current state in script settings if you want it to behave differently. You could also add or remove holidays and colors to use to celebrate them. If you have other ideas or enhancements please leave a comment below.

Thanks to LIFX for a well documented and easy to use API. Also to sunrise-sunset.org for making a free API that provides sunrise and sunset times for any location.

For many years I had a similar setup using a Philips Hue and IFTTT. Philips pulled support for their proprietary hub and I wasn't about to buy a new one and the IFTTT triggers didn't provide a lot of control over the exact time to switch a bulb on or off. LIFX plus apps script is a much better solution. And it's at least half way towards the build-it-myself smart home philosophy I swore to a couple of years ago.

Add your comment...

More Google Apps Script Projects

(All Etc Posts)

(Published to the Fediverse as: Control LIFX WiFi light bulbs from Google Apps Script #software #appsscript #drive #philips How to use Google Apps Script to control LIFX WiFi light bulbs and switch lighting on in the morning and evening around sunrise and sunset (plus special color programs for holidays). )

Leaving the Nest

Updated on Saturday, May 15, 2021

NOPE

I migrated from Nest to Google Home today to save a few bucks and while eventually inevitable it was a really dumb move.

The first thing is that it doesn't work with your Google Workspace / G Suite account because of course it doesn't. So you need an unpaid Google account to move to. Luckily I already have one from that time that G Suite didn't support Google Fi. Interestingly while Google Home won't work with your paid account it has no problem reaching over to grab credit card information from it.

The next thing is goodbye Works with Nest, hello Works with Hey Google. So there goes my IFTTT integration. Because I can't use my main Google account it's kind of useless to me that this might work with Google Assistant. There is still Alexa integration though so I can play my Nest stream on the Echo Show once a year or so as a connected home party trick.

Having not read the changed terms of service I downloaded the Google Home app which a few minutes in I've take to calling Google Nope.

Nest Protect is not supported! This is my favorite smart home device just because when the battery runs out it can tell you which one to change. It's worth almost any amount of money to not spend several hours figuring out where in the house the omnidirectional smoke detector chirp is coming from. But for some reason Google Home doesn't integrate with Google Nest Protect so you need to keep the Nest app as well. Understandable, they only have several tens of thousands of engineers.

So they nailed the camera experience at least, right? Nope. In Nest there are about a hundred settings to play with. In Google Home you can change the name of the camera. In Nest you can scroll through all of your recorded history. In Google Home, despite specifically paying for the plan with 10 days of history you can't. It has a pre-Alpha feel to it. Good for a 'hey, we got the skeleton of an app thrown together' kind of internal demo but it feels like they probably should have added the things you've paid for before shipping it to anyone, let alone bribing them to go through a feature shredding 'migration' process.

My smart home ambitions are not that great. I had a nice little setup that switched some lights on and off around dawn and dusk, but Philips end-of-lifed the bridge and I'm not about to buy a new one. I had some fun making dropcam timelapses but Google broke the public cam URL. And thank goodness I didn't get the alarm system.

Lesson (eventually) learned. The only new smart home devices I'll install are the ones that I build myself.

Add your comment...

Related Posts

You Might Also Like

(All Etc Posts)

(Published to the Fediverse as: Leaving the Nest #etc #google #nest #philips The pain of migrating from Nest to Google Home which is not fully baked and does not support Workspace accounts. )

Securing the Internet of Things

Updated on Wednesday, February 22, 2017

Securing the Internet of Things

We can’t trust manufactures to build secure connected devices and so routers need to be updated to solve this problem once per network.

The distributed denial of service (DDOS) attack on Friday, October 21 was apparently caused by dodgy webcams. But next time it will be Nest or Alexa or Hue - not picking on Google, Amazon or Philips specifically here, those just happen to be the IOT devices currently plugged into my home network. My washing machine and drier would be as well but fortunately LG’s dismal app has saved me from myself by not working for toffee. Oh, I have some DropCams too. And my car is connected. The next attack will probably just come from me.

My fix: update routers to sandbox these devices. A Nest thermostat can only talk to nest.com. If it wants to DDOS Reddit too bad, no connection allowed no matter how badly the device is compromised.

When a new device is connected the router looks it up (MAC address registry?) and then puts it in the appropriate sandbox.

If Nest needs to connect to weather.gov to check the forecast then Google would need to proxy this via nest.com. If the device goes bad it’s only got one domain to attack (so there’s a pretty good incentive for the manufacturer to make sure it doesn’t).

The only downside is new routers or new router firmware. Given the current state of IOT I’d buy one.

As usual if any of my billionaire investor readers are interested get in touch.

Add your comment...

Related Posts

You Might Also Like

(All Marketing Posts)

(Published to the Fediverse as: Securing the Internet of Things #marketing #iot #google #philips #lg #amazon A proposal to secure the internet of things via sandboxing to manufacturer owned URL by MAC address. No more DDOS from toasters. )