An Introduction to Home Assistant, the Open Source Home Automation Platform that Can Even Talk to iTunes

If you want to automate your smart home, you have plenty of options. Want to control your lighting and iTunes at the same time? Not so much. I did find a way to do it, though, all from a single location. It’s definitely an involved process setting it up, but it was worth it in the end. By the time you’re done with this article, you’ll have a solution that can not only manage your smart home devices, but also automatically dim your lights when you start watching a movie in iTunes. That’s right, I’m diving into Home Assistant, an open source home automation platform that can even talk to iTunes.


Before you dig into this, bear something in mind. You’ll need to have at least some Terminal skills, along with a bit of technical know-how to make this happen. I’ve tried to break everything down into easy-to-understand steps, but much of the configuration and operation of Home Assistant and the other services used aren’t for the faint of heart or the technologically impaired.


 Want to control your lighting and iTunes at the same time An Introduction to Home Assistant, the Open Source Home Automation Platform that Can Even Talk to iTunes

Home automation is fun, but the tipping point is when you can identify a real solution to a real problem — such as automatically dimming the lights when you start playing a movie in iTunes


The Stuff You Need to Automate Smart Lights With iTunes


To make all of this happen, you’ll need a few things. Smart home accessories, obviously, but also software. For the example we’re flying with, here’s what you need to have up and running. I’ll walk you through how to set all of this up, but go ahead and purchase and/or download what you can from the links provided.



  • A Mac or Hackintosh, with the latest version of iTunes. Preferably, you should set this up with a static IP address on your Wi-Fi router

  • A Philips Hue Starter Kit, with the bulbs in your entertainment room light fixtures

  • Homebrew, which you can install using my guide

  • Python 3, which you can install from Homebrew or using John Martellaro’s guide

  • Home Assistant, an open-source, community-supported home automation service

  • Maddox’s itunes-api, a non-Apple software service that monitors and controls iTunes


You should have your Philips Hue hub and bulbs already set up, and when you see fixture names, just substitute your own.


Next: Installing Home Assistant and itunes-api


Page 2 – Installing Home Assistant and itunes-api


Installing the Software


Now we’re ready to begin installing and setting everything up.


Installing Home Assistant


First, you’ll need to get Home Assistant, or Hass.io, installed. There are several ways to do this, including using a Raspberry Pi as your Hass.io server, but we’re going to focus on making all of this work straight from your Mac or Hackintosh. Once you’ve updated to Python 3, you can move forward.


From Terminal, issue these commands:


pip3 install homeassistant
hass --open-ui

This will install Home Assistant and its dependencies, then attempt to launch the service for the first time. You’re liable to see several errors fly across the Terminal screen, and that’s okay. Hass.io is doing its initial configuration. You can press Control-C a couple of times to end the process, then run it again to see it open up in your browser. Once you’re certain it’s launching, end the process by pressing Control-C until you see your prompt again.


Now, let’s make sure Hass.io will run automatically, and relaunch itself if there’s a problem. To do that, issue this command in Terminal:


hass --script macos install

By this time, it should have detected your Philips Hue hub on the network. Follow the prompts to link the Hue with Home Assistant.


Next, you will need to register your iTunes media player with Home Assistant. You can do that by following along with these steps in Terminal.


cd  /.homeassistant
nano configuration.yaml

Somewhere in that file, maybe after the sun: line within the configuration, add the declaration of your iTunes instance and where it can be found. Substitute your own IP address for mine.


media_player:
- platform: itunes
host: 192.168.3.100

Spacing is very important here, because of the way YAML configuration files work. The first line is not indented, the second line is indented two spaces, and the third line is indented four spaces.


We’re ready for the next phase, now.


Setting Up Maddox’s itunes-api Service


Next, you’ll need to set up the service that “listens” to iTunes, and allows Home Assistant to tell what the software is doing. That service is called Maddox’s itunes-api, so go download it from GitHub if you haven’t already. Once it’s finished downloading, you should unzip it and copy it somewhere safe. Then, open Terminal and cd to that location. From there, run these commands (the first is optional, but might be necessary).


brew install npm
script/bootstrap
script/install

If you get an error about npm not updating, follow the instructions to fix that. This usually involves either running the npm update command as root (using sudo) or changing permissions on a configuration file.


At this point, I recommend rebooting your Mac/Hackintosh. That seems to be the only sure-fire way to get the itunes-api service to run and stay running. You can check if the service is operational by opening a web browser and visiting http://localhost:8181. If you see a screen with API instructions, you’re golden.


Next: Making it Work and Testing Out Home Assistant


Page 3 – Making it Work and Testing Out Home Assistant


Getting Your Scenes and Automations Working


Okay, by this point, you should have Hass.io installed, along with the iTunes component and Maddox’s itunes-api. If you go to http://localhost:8123, you should now see a “widget” for iTunes on the main page of your Home Assistant’s web page. Time to set up some scenes for our lighting, and then automate them.


Setting the Scenes


Since Home Assistant now sets itself up to use split configuration files (you’ll notice files like groups.yaml and automations.yaml in your .homeassistant directory), we’ll follow that pattern.


Back in Terminal, make sure you’re still in /.homeassistant. From there, type nano scenes.yaml and enter the following text into the new file you’re creating. Make sure to replace my lighting names with your own.


- name: Entertainment Room Normal
entities:
light.ceiling_lamp:
state: on
transition: 2
brightness: 200
light.end_table_lamp:
state: on
transition: 2
brightness: 200
- name: Entertainment Room Dim
entities:
light.ceiling_lamp:
state: on
transition: 2
brightness: 25
light.end_table_lamp:
state: off
transition: 2

Again, watch the indentation. Each of the entities lines is indented two spaces, then you’ll see four spaces of indentation, followed by six. Save the file, and then add this to the end of configuration.yaml:


scene: !include scenes.yaml

At this point, I would restart Home Assistant and then test the scenes to make sure the brightness settings are what you’re looking for. To do that, issue these commands from Terminal.


hass --script macos uninstall
hass --script macos install

If they work the way you want, you’re ready for the next step. If not, tinker with them until you like the settings.


Automating the Lights


Now it’s time to make some magic happen. Edit the file automations.yaml, and delete the square brackets ([]) that might be there. Now type (or copy and paste) these parameters into the file:


- id: media_player_paused_stopped
  alias: 'Media Player Paused/Stopped'
  trigger:
  - entity_id: media_player.itunes
   platform: state
   from: 'playing'
   to: 'paused'
  - entity_id: media_player.itunes
   platform: state
   from: 'playing'
   to: 'idle'
  - entity_id: media_player.itunes
   platform: state
   from: 'playing'
   to: 'stopped'
  action:
   service: scene.turn_on
   entity_id: scene.entertainment_room_normal

- id: media_player_playing
  alias: 'Media Player Playing'
  trigger:
  - entity_id: media_player.itunes
   platform: state
   from: 'idle'
   to: 'playing'
  - entity_id: media_player.itunes
   platform: state
   from: 'paused'
   to: 'playing'
  - entity_id: media_player.itunes
   platform: state
   from: 'stopped'
   to: 'playing'
  action:
   service: scene.turn_on
   entity_id: scene.entertainment_room_dim

Save the file, restart Home Assistant again, and you should see your automations show up on Hass.io’s web page for you to enable or disable.


The Moment of Truth: Testing It All


Now’s what you’ve been working towards. It’s time to test your scenes and automations. Open iTunes, and start playing a movie or some music files. Within a few seconds, your lights should begin to dim. When you pause iTunes, everything should come back up again.


It may take a few seconds for Hass.io to realize you’ve begun playing some media, since it polls Maddox’s itunes-api every five seconds or so, but it’s often much faster than that.


If it doesn’t work, test your scenes and double-check the indentation in all of your files. If all else fails, you can always go to the forums for Home Automation and look for help. The Hass.io community is also very active on Discord Chat.


Just a Glimpse of the Possibilities


This is just one example of what you can do with Home Assistant. All told, there are currently almost 800 different components that work with Hass.io, including the USPS Sensor I recently mentioned.


0 Response to "An Introduction to Home Assistant, the Open Source Home Automation Platform that Can Even Talk to iTunes"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel