Ingredients
- HomeKit Bridge (you could do this on Alexa-Hue Bridge also if you prefer)
- iTach I/R Wifi Device
- Cynical Cache (with all my TV remote codes as action groups in Indigo)
- Device Extensions (this is optional as only my current dev build can do what I'm using it for)
- Indigo variables
- Indigo action groups
Serving Size
This will feed a lot of geeks for a good long time.
Cooking Time
Learning IR codes is the longest part and probably takes 15 minutes to get it done, the scripts and testing took me about an hour today. We'll say cooking time is about 1 hour 15 minutes.
Directions
Power
Power can be tricky because my Sharp Aquos TV doesn't feedback, so I never really know if the TV is on or off, so I have to do my best to keep it updated. I got the wife to start asking Alexa (now Siri) a long time ago to turn on the TV so she's pretty used to saying "Hey Siri, turn on the TV". In addition to the action that sends my remote codes to the iTach I tacked on a little script to update a variable that basically says "if the variable is True, the TV is on so another power command turns it off" and vice-versa:
- Code: Select all
# Update the variable to reflect the current TV state
var = indigo.variables[1877112539] # "tvOn"
varvalue = var.getValue(bool)
if varvalue:
var.value = "false"
else:
var.value = "true"
var.replaceOnServer()
Volume
I have a new Device Extensions device that allows me to control my volume by voice just like a lamp. "Hey Siri, set TV to 35%". I won't go into details until Device Extensions releases with this cool new toy. It's not important for this case study anyway, but I wanted to throw this in there to show that there's little that you cannot do with voice commands.
Playing Xbox (Action Group Script)
My wife loves to play Civilization on Xbox when she wants something mindless. She's pretty good at it too! That being said, our old Marantz remote has the macros to turn on the TV, set it to the Xbox input and then she can play. But this puts the TV power outside of my control, I fixed that today.
What I needed to have is a script that would turn on the TV if it was off, wait for a bit for it to be able to change inputs, then send the input change. This required threading my script so I could have unlimited time to get the job done via this script that does that and then also puts into a variable that the TV is in Game Mode, I can use this in other scripts to trigger different actions:
- Code: Select all
import time
import thread
def runAction():
var = indigo.variables[1877112539] # "tvOn"
tv = indigo.actionGroups[1077979551] # "IR - Sharp Aquos - Power"
varvalue = var.getValue(bool)
# If the TV is off then turn it on and switch inputs
if not varvalue:
indigo.actionGroup.execute(tv.id)
time.sleep(30)
indigo.actionGroup.execute(1986130616) # Input
time.sleep(5) # Give it time
indigo.actionGroup.execute(1070194149) # Up
time.sleep(3)
indigo.actionGroup.execute(1910590700) # Enter
mode = indigo.variables[594459756] # "tvMode"
mode.value = "game"
mode.replaceOnServer()
thread.start_new_thread(runAction, ())
Notice that this works if the TV is on or off (can't confuse the wife with "you must have the TV on, stand on one foot, utter a special chant and...).
Watching TV (Action Group Script)
This works the same as the Xbox script:
- Code: Select all
import time
import thread
def runAction():
var = indigo.variables[1877112539] # "tvOn"
tv = indigo.actionGroups[1077979551] # "IR - Sharp Aquos - Power"
varvalue = var.getValue(bool)
# If the TV is off then turn it on and switch inputs
if not varvalue:
indigo.actionGroup.execute(tv.id)
time.sleep(30)
indigo.actionGroup.execute(1986130616) # Input
time.sleep(5) # Give it time
indigo.actionGroup.execute(1630437213) # Down
time.sleep(3)
indigo.actionGroup.execute(1910590700) # Enter
mode = indigo.variables[594459756] # "tvMode"
mode.value = "tv"
mode.replaceOnServer()
thread.start_new_thread(runAction, ())
Getting it To HomeKit
This was easy, just add my two action groups to a HomeKit server and the switches were in HomeKit waiting for me.
Voice Control
This is the fun part, getting all this done with voice commands. I simply set up two scenes called "Watch TV" and "Play Xbox" and linked those scenes to turning on the appropriate action group light switches that are in HomeKit. So, no matter if the TV is on or off I can just simply say:
Hey Siri, play Xbox
Hey Siri, watch TV
Dealing With Failure
As we all know, our complicated home automation stuff doesn't always work. In addition to these I have a script and HomeKit scene called "Fix the TV" that will reset my TV variable to false (off) and the tv mode to "TV", so the worst case is that I have to manually adjust the input of the TV and turn it off manually to match Indigo and then everything is right again. I've never had to do that with turning the TV on or off and don't anticipate having to use it for these new actions either. About the only time I would need this is if someone uses the remote control to do everything instead of voice or if there was a power outage that turned off my TV. Even if the wife forgets then it's not a big deal because my "bedtime" script that runs each night will reset the TV power to off anyway, so it's always going to be good the next day.
And, yes, you could easily do the same thing with Alexa too using this same basic case study .