Category: Home Automation

Philips hue API & Twitch Stream

I recently added a Philips hue Lightstrip to my hue collection with a specific intent. My son has started a twitch channel (please follow) and I wanted way to know when he is online using the Lightstrip so not to enter the room he streams from as I’d be in the camera shot and at the age of 14 your dad in your stream is no a good thing, apparently.

I came up with the following idea. Lights are green when he is on the computer but go red when he streams. So how do you make this happen.

Firstly I checked out IFTT but its just not good enough, sure you can change the light the you start streaming but there is nothing to change back the you stop streaming.

The answer was an addition to my Home Assistant instance.

Once twitch is configured in HA a simple automation can monitor the status of stream and change the lights from green to red and then red to green.

Next thought was turning the lights on and off and to do this called for using the Hue API. This is fairly easy to construct once you have your API key. Hue have a really simple guide on how to do this and also find the ID of the lights on your network you want to control.

So once we have our API key and the ID of our lights we can make a Powershell script to run on the PC used for twitch streaming as below:

1
$apicontent= '{"on":true, "sat":254, "bri":254,"hue":25535}'
1
Invoke-WebRequest -Method put -Uri http://192.168.X.XX/api/YOURAPIKEY/lights/10/state -Body $apicontent -UseBasicParsing

The first line controls the lights,

1
"on":true

 turns the light on following three parts set the lights temperature, brightness and colour, 25535 is green.

The second line does the web request and is were is you add your huebase station IP address, your api key and the light device ID, in this example it’s 10.

So now we can add this to our PC as .ps1 file I called mine hueon.ps1 and dropped it directly in C:/ root.
Next we need to create a batch file to call the powershell script as below:


1
2
@ECHO OFF
PowerShell.exe -Command "C:/hueon.ps1"

This can be saved anywhere you want I called mine hueon.bat and saved to my documents folder. If you run this your lights should come on. If they don’t check your the path is correct to the .ps1 and the API call is correct.

Now we need to call the batch file at logon to do that in the Windows search bar type

1
run

and then open 

1
gpedit.msc

 and go to:
User Configuration -> Windows Settings -> Scripts -> Logon -> Properties -> Add

Select you .bat file and you are done. When the PC logs in, the .bat will run the Powershell script and on come the lights.

If you want the lights to go off when you logout/shutdown your PC just repeat creating a .ps1 & .bat but change

1
"on":true

 to

1
"on":false

 in your API call and in gpedit.msc select logout and then you batch file.

So now we have:
PC boots and logs in lights come on and go green
If a twitch stream is started they go red
When the stream is stopped they go green
When the PC  is logged out or shutdown they go off

Upgrade node.js to 12.16.2 with n on hoobs

Recent changes to hoobs require that node.js is on at least 10.17.0 while most installs on raspberry Pi are “stuck” on 10.15.2 or 10.16.0


I found that simply running standard updates for the raspberry Pi would not result in node.js getting updated and was being told 10.16.0 was the latest version despite hoobs telling me 12.16.2 was the latest. The small orange circle with exclamation informs a update is available but there is no mechanism from the UI to update.

I managed to upgrade using n – https://github.com/tj/n this is a node.js version manager and makes the upgrade process so simple.

Open Terminal in the UI from the top right three dots.

I deleted all npm cache, not ideal but I was still getting issues and this resolved:

1
sudo npm cache clean -f


Then I updated & installed n:
1
sudo npm install -g n sudo n stable

Now simply run n and the version number required to update
1
sudo n 12.16.2
Finally restart hoobs and once back

node.js 12.16.2

note this is using hombridge with the homebridge-config-ui-x v4.16.0 UI and not the latest version of hoobs.

Hoobs – Adding AdGuard Home

Hoobs is a simple Homebridge implementation, takes minuets to get up and running on a Raspberry Pi.

But as its on a Raspberry Pi you can also run other applications, for example AdGuard Home. AdGuard is a DNS AdBlocker, you simply run, configure and then set up your router with DNS IP of your AdGuard install. Your network devices will eventually start using this as their DNS. Its similar to piHole but better 🙂

Simply open your Hoobs Homebridge site which is usually http://hoobs.local/ From the three vertical dots on the far right select Terminal and install AdGuard

My commands are bold and this shows full output:

hoobs@hoobs:/var/lib/homebridge $ cd $HOME
hoobs@hoobs:~ $ wget https://static.adguard.com/adguardhome/release/AdGuardHome_linux_arm.tar.gz
--2019-10-09 13:52:29-- https://static.adguard.com/adguardhome/release/AdGuardHome_linux_arm.tar.gz
Resolving static.adguard.com (static.adguard.com)... 104.20.31.130, 104.20.30.130, 2606:4700:10::6814:1e82, ...
Connecting to static.adguard.com (static.adguard.com)|104.20.31.130|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5280981 (5.0M) [application/octet-stream]
Saving to: ‘AdGuardHome_linux_arm.tar.gz’

AdGuardHome_linux_arm.tar.gz 100%[========================================================>] 5.04M 6.61MB/s in 0.8s

2019-10-09 13:52:35 (6.61 MB/s) - ‘AdGuardHome_linux_arm.tar.gz’ saved [5280981/5280981]

hoobs@hoobs:~ $ tar xvf AdGuardHome_linux_arm.tar.gz
AdGuardHome/
AdGuardHome/AdGuardHome
AdGuardHome/LICENSE.txt
AdGuardHome/README.md
hoobs@hoobs:~ $ cd AdGuardHome/
hoobs@hoobs:~/AdGuardHome $ sudo ./AdGuardHome -s install
2019/10/09 13:53:03 [info] Service control action: install
2019/10/09 13:53:05 [info] Action install has been done successfully on linux-systemd
2019/10/09 13:53:05 [info] Service has been started
2019/10/09 13:53:05 [info] Almost ready!
AdGuard Home is successfully installed and will automatically start on boot.
There are a few more things that must be configured before you can use it.
Click on the link below and follow the Installation Wizard steps to finish setup.
2019/10/09 13:53:05 [info] AdGuard Home is available on the following addresses:
2019/10/09 13:53:05 [info] Go to http://127.0.0.1:3000
2019/10/09 13:53:05 [info] Go to http://192.168.1.55:3000
hoobs@hoobs:~/AdGuardHome $

Thats’ it. AdGuard is now up and running at the IP address shown i the last output which is obviousy the same as your Hoobs IP. You then configure AdGuard via the web interface. The only setting to change is the interface port number as Hoobs is using 80 and 8080 so just pick something, I used 90. AdGuard will show in red if a conflict.

AdGuard is now running at http://192.168.1.55:90 or http://hoobs.local:90/

Hoobs AdGuard Install
Hoobs AdGuard Install

Echo Dot on the Ceiling

I’ve been using an Apple Airport Express for a number of years connected to a Marantz amplifier in the top of a cupboard which is then connected to some ceiling speakers for music via iTunes and more recently Spotify. Earlier this year I bought an Amazon Echo and found it much simpler to control Spotify, so I decided to ditch the Airport Express and replace with an Amazon Echo Dot and use it for voice control of music with the ceiling speakers. I also purchased another Belkin WeMo Switch Smart Plug to turn the amp on and off and a Dot flush ceiling mount kit.

Plan was, Dot to amp and power, amp to ceiling speakers (already in place), amp into Wemo socket. After about an hour or so of cutting and wiring I ended up with the flush ceiling mount in place, the Dot mounted and all wired back to the amp.

The ceiling was really easy to fit, just a case of finding a suitable spot and then cutting a hole. It fitted tightly into the ceiling and the kit comes with a 90degree 3.5mmm jack and also a very long USB power lead. All I had to add was a 3.5mm male jack to left/right phono to plug into the back of the Marantz amp. The Dot fits well into the mount and can’t fall as the wires keep it in place plus the kit comes with some stick pads for extra security, not that it really needs them.

Once all wired in and the Wemo plug setup the Marantz amp can be switched on and off with a simple “Alexa turn on Marantz” command and then Spotify played back with a simple “Alexa play“, so much easier than having to find my iPhone, launch Spotify, turn the amp on, play a track and then choose Airplay.

Recent Posts

Become a Brewdog Investor!

Instagram

Amazon

Archives

Categories

Meta

GiottoPress by Enrique Chavez