Tag: Philips Hue

  • Turn lights on and off when Windows 10 is locked or unlocked

    Turn lights on and off when Windows 10 is locked or unlocked

    Like many, I have smart lighting throughout my house. This includes my office and desk. Behind my beautiful ultrawide monitor, I have a 3m Philips Hue strip which helps add some peripheral light and softens the glare when using the screen. I use scenes to adjust the level of white light towards early evening, but I’ll save that for another day. While I can manage the lights in the room based on motion, I wasn’t doing anything with my monitor lights as I might have been working, but the room could have had no movement. This would have resulted in the monitor lights turning off and would have been frustrating, so I decided to integrate whether my workstation is locked or unlocked or not with Home Assistant.

    My desk lights turning on when I unlock my Windows machine using Home Assistant

    Previously I had a PowerShell script that I could run that would hit the Hue API to toggle my lights on or off but since I have moved away from my Hue bridge this no longer works plus it wasn’t automated, but this was a good starting point. The sysadmin in me remembered there was a trigger in Task Scheduler that would be a task when the workstation was locked or unlocked, which gave me the trigger for my Home Assistant integration.

    Picture of the trigger screen in Task Scheduler showing the different triggers that are available.
    Workstation lock/unlock triggers in Task Scheduler

    The next part was talking to the Home Assistant to perform service calls such as light.turn_on or scene.turn_on. Fortunately, I know Home Assistant provides great extensibility and has a fantastic rest API, so that was Home Assistant. This just left the process to call the API. For this, I wanted to stick with PowerShell as it is very versatile and I use it all day long anyway.

    I had a prototype working very quick, but I wanted something more modular and parameter-based to use for other things. This is when I took found Flemming Sørvollen Skaret’s Home Assistant PowerShell Module. His PowerShell module is awesome and really handy. I was off and running with it within minutes. So I decided to leverage this module in my Task Scheduler automation. And that was that, but I still had to hook it all together.

    • 2 x Task Scheduler Tasks – triggered when the workstation is locked and unlocked
    • 1 x VBScript to launch our PowerShell script so it is hidden
    • 1 x Flemming’s Home-Assistant PowerShell Module
    • 1 x PowerShell script to call the Home Assistant API
    • 1 x Home Assistant long-live token
    • 1 x entity in Home Assistant (a light, scene or input_boolean for example)

    Task Scheduler

    First I created two tasks in Task Scheduler. One for when the workstation locks and the other for when it is unlocked. When these tasks are triggered, they call a VBScript with some parameters. Yes. An actual 1900’s VBScript in 2020. For the life of me, I could not stop or prevent the PowerShell console from flashing up. I’m a UX nerd, and this wasn’t acceptable for me. I spent way too long on trying to solve this before I reverted to this well-known workaround of using WScript to execute the PowerShell script silently. These have been exported from Task Scheduler and therefore can be imported straight back in obviously correcting usernames and paths.

    You will notice on line 46 above calls a common TaskSchedulerLauncher.vbs script along with the path to a ps1 file and the parameters to go with it wrapped in double-quotes.

    Are you using a battery-powered device?

    Geert van Horrik (@GeertvanHorrik) kindly pointed out that if you are using a battery-powered device like a laptop or a tablet you will need to change the conditions so the task runs when on battery power.

    Power settings for a task in Task Scheduler

    VBScript

    Having to use the VBScript is annoying but not as annoying as the PowerShell console flashing up each time I unlocked my workstation. It calls PowerShell.exe and our script while also setting the window style to be hidden.

    PowerShell

    In order to interact with the Home Assistant API you will need a long-lived token. You can create one in the Long-Lived Access Tokens on the profile page (http://localhost:8123/profile). Be sure to name it something sensible and meaningful.

    The token and information about my Home Assistant instance are stored as variables in the script. The service I want to call such as light.turn_on, scene.turn_on and input_boolean.turn_on and the entity_id (input_boolean.james_desk) are passed to this script as parameters.

    Additionally, as the PowerShell script contains the token to Home Assistant I store the script within my profile and limit the permissions to the file to just myself.

    Home Assistant

    I started off by just toggling the state of my monitor light but I shortly realised I could achieve more if I knew my workstation was unlocked so I created an input_boolean.

    I toggle the state of this each time my Windows 10 machine is locked and unlocked. This means I can do more than just turn my lights on or off. I use this input_boolean in my motion automation which prevents my room lights from turning off if my workstation is unlocked (no more crazy waves). It also stops my Dyson fan from oscillating and directs it towards my desk and changes the speeds if the temperature is above a threshold. I can also choose route TTS notifications through to my desk Sonos speakers or HTML5 notifications to just my workstation.

    Best of all with Windows Hello I just sit down at my desk, and Home Assistant handles everything else because it knows my workstation is unlocked and the chances are I’m working or tinkering with something at my desk.

    I’ve also used the same PowerShell method to create a set of quick actions that I can call from buttons on a Home Assistant Stream Deck board where I can call my favourite playlists and scenes. I’ve also created some TTS scripts to announce and nag when chores need to be done or when it is dinner time! I think I’ll save that for another post!

    I 💕 my Home Assistant

  • Philips Hue LED kit extension lead hack

    Philips Hue LED kit extension lead hack

    With most of the house HUE’d up, I thought I would add Hue lighting under the cupboards in our kitchen. I love cooking but am often frustrated because of the poor lighting on the work surface in the kitchen. The trouble is the Philips Hue LED kit is only available in two sizes, the 2m main kit and in 1m extensions. Our kitchen cupboards are split in two by our cooker hob extractor. This leaves me with cupboard lengths of 1.4m and 1.6m. I did some research but could not find an extension lead for the Philips Hue light strips so rather than shedding out on two kits, I decided to hack together a solution to create my own extension lead.

    Philips Hue lightstrip extension lead hack
    Philips Hue lightstrip extension lead hack

    Appreciating the risks and the potential cost of replacement involved if I failed, I took off and carefully hacked my own extension lead together. Below is a list of what you’ll need to do this yourself and the steps involved to make your own extension lead for your Hue light strips.

    What you’ll need to hack your own Hue light strip extension lead together

    • Philips Hue Personal Wireless Lighting 2 m Lightstrip Plus
    • Philips Hue Personal Wireless Lighting 1 m Lightstrip Plus Extension
    • Wire cutters and a good wire stripper
    • Heat shrink to protect any exposed cables once we finish
    • Soldering iron and solder to join the extension lead wires onto the Philips Hue light strip
    • The desired length of cable (this will be your extension) – I couldn’t find a wire with six cores so used two five metre lengths of four core wire. Far less attractive but good enough for the hack this time around
    • Optional connector terminals and a crimp tool (male/female spade terminals) – these allowed me to pass the extension lead through backs of my cupboards more easily
    • Optional staple gun to tack the leads to the cupboards.
    The tools you'll need to create the extension lead.
    The tools you’ll need to create the extension lead.

    The steps involved…

    1. Plan and test the placement of your light strip and where you will attach the extension lead.
    2. Work out the route of your extension lead – in my case I went through the backs of the cupboards and then up and over the top of my extraction fan. This required a few holes to be drilled into the cupboards.
    3. Prepare your extension lead. Strip and tin each of the wire with the soldering iron.
    4. Decide if you will include a connector to allow you to separate the extension lead from the light strip. If you are going to add one, cut, strip and crimp the wires with your connector – in my case I used a set of spade terminals.
    5. Grandad always said measure twice cut once – so run through your placement and cabling route once more.
    6. And don’t be silly – remember to power off the light strip before the next step!
    7. Cut the light strip at the nearest cut joint because this is where we will solder our extension lead wires onto.
    8. Carefully cut back some of the outer plastic on the light strip so that you can solder your wires onto the terminals. Make sure you don’t forget to include some heat shrink to protect these joints once you have terminated the wires.
    9. Test the lights work correctly before fitting in your desired place.
    10. Tip! If placing under cupboards, place the light strip at the back for the best effect.
    11. Optionally use a cable staple gun to tack the extension lead throughout its route to make it extra secure.

    Grandad always said, measure twice cut once.

    This slideshow requires JavaScript.

    Product improvement idea

    Philips could avoid this problem altogether and avoid any hacking at all. Firstly they should offer an official 6 core extension lead. Secondly, they could alter the cut joint they include at various points throughout the light strip. Making each cut joint made up of a male and female connector under the plastic. To extend the lightstrip you would then simply cut over the joint and use the official Philips Hue light strip extension lead. The extension lead would have a male and female connector at each end, allowing you to simply connect it to the section you have just cut.

    extensionlead

    That aside, kudos to the Philips team for creating amazing lights and for placing cut joints throughout the light strip. This made my hack so much easier to pull off.

    The Philips Hue light strip at it's brightest.
    The Philips Hue light strip at it’s brightest.

    I’m really impressed with the outcome of the Philips Hue LED light strips and my custom extension lead hack. I hope you find this article helpful and it inspires others to extend Hue light strips more easily. This post is part of my home automation series. If you liked this hack, be sure to check out some of my other home automation hacks.