Case Study: TV by Voice

User avatar
Colorado4Wheeler
Posts: 2794
Joined: Mon Jul 20, 2009 10:48 am
Location: Colorado

Case Study: TV by Voice

Post by Colorado4Wheeler »

I've been controlling my TV by voice for a while but today I decided to play around with it a bit more and thought it might be nice to share what I did and how I got there. Just about anything I do anymore that requires me to push a button I'm trying to integrate into voice instead.

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 ;).
new2me07
Posts: 84
Joined: Fri Apr 07, 2017 9:40 pm

Re: Case Study: TV by Voice

Post by new2me07 »

On TVs that don't remember their state when mains in disconnected I use the power monitoring properties of applicable devices to determine their real state. Ive used this method on my washing machine as well to get a notification that its done.

I'm so torn between TV set ups. Apple TV is great and pretty much what we solely use for the past year but I miss my PIP automatic camera call up I hacked together on WMC and robust network control. I feel like its the final frontier in terms of automation. You'd think apple would create a TV device for apple TVs and use HDMI CEC control to get volume and power control for the device into HomeKit. I hear they are hiring I know at least 100 people who would give you an awesome reference. Thanks for all the great work.
User avatar
Colorado4Wheeler
Posts: 2794
Joined: Mon Jul 20, 2009 10:48 am
Location: Colorado

Re: Case Study: TV by Voice

Post by Colorado4Wheeler »

new2me07 wrote:On TVs that don't remember their state when mains in disconnected I use the power monitoring properties of applicable devices to determine their real state.
I do that if I can but most of my TV's don't report anything. I could easily throw on some of the Dome outlet devices to see what the power draw is (and now that I think of it I like that idea for $30) but so far it works pretty well. Some of my TV's stop pinging when they go offline, that has made it pretty easy, others I just have to hope it's in alignment but know that it'll reset at midnight anyway.
new2me07 wrote:I miss my PIP automatic camera call up
I would expect that will be in a future update as Apple TV becomes more critical - as it will since Apple is producing their own movies and TV shows they will want to make the ATV a pretty core piece of equipment IMO. That being said, have you investigated if your TV itself does PIP? Mine do and I used to have my Roku or even another ATV on a different input so I could do just that - but since my HomeKit shows me my cameras as well as my SecuritySpy apps on all my iOS devices I found I didn't need it anymore and stopped doing it.

I'm hoping to develop HKB to the point of doing photo/video notifications that I know are possible but just out of reach at the current stage of the plugins development.
new2me07 wrote:You'd think apple would create a TV device for apple TVs and use HDMI CEC control to get volume and power control for the device into HomeKit
I bet that's coming too. Heck, I'm just happy it's on the ATV so I have one tiny remote for everything.
My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here
User avatar
RogueProeliator
Posts: 2538
Joined: Tue Nov 13, 2012 3:54 pm
Location: Baton Rouge, LA

Re: Case Study: TV by Voice

Post by RogueProeliator »

Power can be tricky because my Sharp Aquos TV doesn't feedback
Yours didn't have an Ethernet interface on it for IP control?
User avatar
Colorado4Wheeler
Posts: 2794
Joined: Mon Jul 20, 2009 10:48 am
Location: Colorado

Re: Case Study: TV by Voice

Post by Colorado4Wheeler »

RogueProeliator wrote:Yours didn't have an Ethernet interface on it for IP control?
It's connected to Ethernet but I've not really looked into controlling it via IP. I looked at an API a while ago but it looked like more work than it was worth, perhaps that has changed.
My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here
User avatar
RogueProeliator
Posts: 2538
Joined: Tue Nov 13, 2012 3:54 pm
Location: Baton Rouge, LA

Re: Case Study: TV by Voice

Post by RogueProeliator »

It's connected to Ethernet but I've not really looked into controlling it via IP. I looked at an API a while ago but it looked like more work than it was worth, perhaps that has changed.
I don't think I ever published to the Plugin Store but it's been around quite a while:

http://forums.indigodomo.com/viewtopic.php?f=64&t=10981

Not sure of your model, but it controls nearly all of Aquos that have been tried... and it does have most of the states including power (and can control power). You may have yours setup enough you don't want to bother, but might give you an option to read power even if you left your existing control in place.

Adam
User avatar
Colorado4Wheeler
Posts: 2794
Joined: Mon Jul 20, 2009 10:48 am
Location: Colorado

Re: Case Study: TV by Voice

Post by Colorado4Wheeler »

RogueProeliator wrote:Not sure of your model, but it controls nearly all of Aquos that have been tried... and it does have most of the states including power
OOOOOOOOOOOOH! Thanks Adam!
My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here
User avatar
Colorado4Wheeler
Posts: 2794
Joined: Mon Jul 20, 2009 10:48 am
Location: Colorado

Re: Case Study: TV by Voice

Post by Colorado4Wheeler »

Sadly, that plugin doesn't seem to like my TV :(
My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here
User avatar
RogueProeliator
Posts: 2538
Joined: Tue Nov 13, 2012 3:54 pm
Location: Baton Rouge, LA

Re: Case Study: TV by Voice

Post by RogueProeliator »

Sadly, that plugin doesn't seem to like my TV
What model do you have? Most of the Aquos use the same protocol but there may be a few which do not conform...

Adam
User avatar
Colorado4Wheeler
Posts: 2794
Joined: Mon Jul 20, 2009 10:48 am
Location: Colorado

Re: Case Study: TV by Voice

Post by Colorado4Wheeler »

The U1101191
My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here
User avatar
RogueProeliator
Posts: 2538
Joined: Tue Nov 13, 2012 3:54 pm
Location: Baton Rouge, LA

Re: Case Study: TV by Voice

Post by RogueProeliator »

The U1101191
According to the docs, that unit should be controllable by the plugin... up to you if you want us to investigate or just let it go for now.
User avatar
Colorado4Wheeler
Posts: 2794
Joined: Mon Jul 20, 2009 10:48 am
Location: Colorado

Re: Case Study: TV by Voice

Post by Colorado4Wheeler »

RogueProeliator wrote:up to you if you want us to investigate or just let it go for now
I would be open to investigating it, I think it would only serve to enhance my automation. What can I do to be helpful in this regard?
My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here
Ramias
Posts: 272
Joined: Tue Nov 24, 2015 5:21 pm

Re: Case Study: TV by Voice

Post by Ramias »

I can’t wake my Samsung over Ethernet but I wake it via hdmi cec on the receiver.

The Samsung does not respond to ping when off so I use fingscan to set a variable when it is on and long it every few seconds to confirm state.

So now I can turn on via network with the receiver (thus voice commands etc) or if I turn tv on via remote, Indigo finds out and turns the receiver on.
User avatar
RogueProeliator
Posts: 2538
Joined: Tue Nov 13, 2012 3:54 pm
Location: Baton Rouge, LA

Re: Case Study: TV by Voice

Post by RogueProeliator »

I would be open to investigating it, I think it would only serve to enhance my automation. What can I do to be helpful in this regard?
Are you using a username/password on the TV? The API for control is pretty defined, but there is no official login - the plugin has to wait for a login prompt telnet-style. This is the most likely point of failure/something having changed. If you would, turn on high debug for the plugin and restart it so we can capture the connection attempt. Warning, this may put your username/password in plain text if you copy it in here, so be sure to blank that out.

Adam
User avatar
Colorado4Wheeler
Posts: 2794
Joined: Mon Jul 20, 2009 10:48 am
Location: Colorado

Re: Case Study: TV by Voice

Post by Colorado4Wheeler »

I didn't add a user/pass because I don't think my TV asked me to ever provide one, if it did then I don't remember what I would have put there.
My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here
Post Reply

Return to “HomeKit Bridge”