X10

From MythTV Official Wiki
Jump to: navigation, search

This article is to provide information on how to integrate X10 lighting controls into MythTV. This is based on Fm radio but I wanted to post details on how to make it work for x10 too.

I only have a cm11a. I cannot speak to other setups, but please feel free to edit this page to include information for others.


Important.png Note: this is NOT a plug-in and is basically a hack but when completed it looks just like a plug-in.


Contents

Article from 10,000 feet

What this article is...

This article IS about:

  • Setting up X10 to be controlled by a CM11A and the drivers from WiSH (http://wish.sourceforge.net)
  • How-To use programs that other people wrote (and are not affiliated with MythTV)
  • How-To integrate everything with the default MythTV menu theme

What this article is not...

This article IS NOT:

  • How-To perfectly integrate with your particular MythTV GUI (we only cover the default menu theme)
  • An X10 Plug-in for MythTV
  • An X10 how-to

What is required

Only a working installation of MythTV is required Also you must be able to control X10 equipment with WiSH drivers

Hacking it together

OK, now we are going to write a couple of über-simple shell scripts that we will use to make MythTV work with your CM11A. You will notice that these are simple, novice scripts that are pretty crude. This hasn't been called it a "hack" for nothing.

Create files

We need to create a couple of files so find a nice place you can create and execute them from. Personally, I put them in ~/.mythtv

# vi x10lights
#!/bin/bash
# Control for X10 lights in Myth

if [ "$1" = "tv" ]; then
        # 1st we give an aon then turn off the lights we dont want 
	/usr/bin/nbecho aon > /dev/x10/m 
	/usr/bin/nbecho null > /dev/x10/m10 
	/usr/bin/nbecho null > /dev/x10/m11 
	/usr/bin/nbecho null > /dev/x10/m12  
	/usr/bin/nbecho null > /dev/x10/m14 
	/usr/bin/nbecho null > /dev/x10/m15 
	/usr/bin/nbecho null > /dev/x10/m16 
	/usr/bin/nbecho 0 > /dev/x10/m


elif [ "$1" = "movie" ]; then
        # 1at we give aon then turn off all the lights except one and dim that one to about 50% 
	/usr/bin/nbecho aon > /dev/x10/m 
	/usr/bin/nbecho null > /dev/x10/m10 
	/usr/bin/nbecho null > /dev/x10/m11 
	/usr/bin/nbecho null > /dev/x10/m12 
	/usr/bin/nbecho null > /dev/x10/m13 
	/usr/bin/nbecho null > /dev/x10/m14  
	/usr/bin/nbecho null > /dev/x10/m15 
	/usr/bin/nbecho null > /dev/x10/m16 
	/usr/bin/nbecho 0 > /dev/x10/m 
	/usr/bin/nbecho null > /dev/x10/m9 
	/usr/bin/nbecho dim > /dev/x10/m 
	/usr/bin/nbecho dim > /dev/x10/m 
	/usr/bin/nbecho dim > /dev/x10/m 
	/usr/bin/nbecho dim > /dev/x10/m 
	/usr/bin/nbecho dim > /dev/x10/m 
	/usr/bin/nbecho dim > /dev/x10/m 
	/usr/bin/nbecho dim > /dev/x10/m 
	/usr/bin/nbecho dim > /dev/x10/m 
	/usr/bin/nbecho dim > /dev/x10/m 
	/usr/bin/nbecho dim > /dev/x10/m

elif [ "$1" = "aon" ]; then
        # turn all lights on in house code M
        /usr/bin/nbecho aon > /dev/x10/m

elif [ "$1" = "aoff" ]; then
        # turn all lights on in house code M
        /usr/bin/nbecho aoff > /dev/x10/m

else
        exit 1
fi
exit 0

You are going to want to change this for the types of controls you want. I use house code M and really just control lighting. You might have other stuff you want to do. I'd love to see some examples of what others are doing posted here.

Now you will want to make this executable:

# chmod a+x x10lights*

Test scripts

Now, pull up a command window and run one of the commands we just "made"

$ ./x10lights aoff

Did all of your lights turn off? If not you need to debug this before moving on.

Setting up the MythTV GUI

At this point, you should be able to control your X10 devices from the command line with no user intervention... that's 1/2 the battle. Now, we are going to hack a couple of buttons onto the default menu theme.


Important.png Note: If you are currently running MythTV version 0.20 or higher chances are that you're using the default menu theme. No, not the actual MythTV theme, just the menu theme. To check out which one you're using do this in Myth: Utilities / Setup (or Setup) -> Setup -> Appearance -> and at the bottom of the first options page you will see the menu themes selection box, we will be hacking into "Default" so make sure it's set to that one. If you use classic or DVR you can change some of the commands below so that your work is being done on that particular theme (just add /themes/classic or /themes/DVR respectively to the "cd" commands below).

Backup the default theme

# cd /usr/share/mythtv
# tar cfvz default_backup.tar.gz *.xml

I use the v option because it's an easy way to verify (VIA verbose) what files were put into the tar ball.

Hack the default theme

I'm only going to show you the 2 required changes to get this hack to work.

I added the following to my mainmenu.xml file.

# cd /usr/share/mythtv
# vi mainmenu.xml
   <button>
      <type>MENU_HOME_CONTROL</type>
      <text>Home Control</text>
      <action>MENU home_control.xml</action>
   </button>

Then, I created the home_control.xml file (be sure to add all of the stations you want access to):

# vi home_control.xml
<mythmenu name="X10MENU">

   <button>
      <type>LIGHTS</type>
      <text>Lights to TV Mode</text>
      <action>EXEC ~/.mythtv/x10lights tv</action>
   </button>

   <button>
      <type>LIGHTS</type>
      <text>Lights to Movie Mode</text>
      <action>EXEC ~/.mythtv/x10lights movie</action>
   </button>

   <button>
      <type>LIGHTS</type>
      <text>All Lights On</text>
      <action>EXEC ~/.mythtv/x10lights aon</action>
   </button>

   <button>
      <type>LIGHTS</type>
      <text>All Light Off</text>
      <action>EXEC ~/.mythtv/x10lights aoff</action>
   </button>

</mythmenu>

Tag definitions

OK, now the tag definitions for the above xml file

  • "button" tells the theme to paint a button on the screen
  • "type" tells the theme what image to use for the button
  • "text" tells MythTV what button text to put on the screen
  • "action" tells MythTV what to do when you select the button

Additional Setup and Usage Notes

  1. X10 is very flexible and can do lots of things. I just use it to control some lights. You will have to modify the example file to make it do what you want.

Screen shots

Personal tools
Namespaces
Variants
Actions
Wiki Navigation
Official Resources
Toolbox
Print/export