I'm a long time user (and believer) in Windows Media Center as the primary method to consume Cable TV. Coupled with a cable card tuner such as the SiliconDust HDHomeRun PRIME you can create a fantastic, flexible user and stable Cable TV experience with Windows 7 and Windows Media Center. As long as Microsoft still provides Electronic Program Guide data and the FCC requires cable operators to provide CableCARD I'll stick with this setup.

The Problem

Due to occasional guide data quality issues with Rovi and the once in awhile guide data outage every now and then a scheduled recording won't record leading to impending trouble I get in with my significant other. I wanted a more proactive approach to being aware if something has started recording when we expected it to.

Home Assistant?

Home Assistant is used for all of my home related automation and notification needs. There is currently still no component for Windows Media Center (Feature request here) but I still wanted to try and find a way to use Home Assistant so I use whatever I do in other ways. Right now I wanted to get a notification when WMC started a recording on my Phone with the title of what it was.

(I can actually control Windows Media Center via the Harmony Remote platform which works well, but there's still no WMC status)

I came across a neat PowerShell script at O'Brian Labs that created a recording indicator light using the ThingM Blink(1). I thought this might be a good start to find out recording status, but it didn't pull the title of the show being recorded. Bookmarked this for the future! This could be useful later for a Home Assistant sensor to count tuner status.

I did some more digging and finally came across jpalo's MCSA or Media Center Status Application which is intended to post WMC information to Social Media. The Developer was also nice to provide a feature to also write the status data to an XML file. This was the magical a-ha moment for me. If Home Assistant can read this XML file, I can finally have Home Assistant act upon status from Windows Media Center

The Setup

Setup MCSA per the usual, using the XML method as the primary status update method. For me I set it up to only post new recordings (however you can also have it post what you are currently watching as well).

I have a dedicated Home Theater PC running Windows 7 and WMC. So we have to have a method in which Home Assistant can access this XML file. I went with the REST component method and setup a web server on the HTPC. I didn't install Microsoft IIS (although I could have), I went with Fenix, but you can use any web server for Windows. Point the web server root to the directory where you have MCSA writing the status XML file and verify you can reach this XML file in a browser from another computer.

Note! One challenge I found is that MCSA did not persist the current recording in the XML file. It only writes it to the file for a few moments and then clears the file out. This was not the behavior that I would have liked (as it would be nice if Home Assistant would show what is recording for the duration) but it worked out as Home Assistant will find each new recording even if all 3 tuners start up.

I found that Home Assistant's REST component didn't like to deal with XML and XPath, so I went with the Command Line Sensor component and with cURL, grep, and sed. Setup a sensor like so:

sensor: - platform: command_line name: Currently Recording command: 'curl --silent http://HTPC-IP-OR-Hostname:8080/status.xml | egrep "<value>.*</value>" | sed -e "s/<value>\(.*\)<\/value>/\1/"|tr "|" " "' scan_interval: 10

As you can see we are curl'ing the XML file from the command line of the Home Assistant server and use grep to pull out the value of the Recording and return it to Home Assistant. I also have Home Assistant checking every 10 seconds for a new value written to the XML file so the notification is fairly quick once the recording starts.

It ends up looking like this inside of the Front End:



Not that exciting, I know. Each colored sliver in the state history are previous recording events from MCSA. Since the sensor returns empty after the command after MCSA clears out the XML file, this is unfortunately how your state history looks for this component. Not a problem though, I know have the recording title in Home Assistant within 5 minutes of the recording starting on Windows Media Center. We can now create a notification from it.

Automations

automation: - alias: WMC Recording Alert trigger: platform: state entity_id: sensor.currently_recording condition: condition: and conditions: #Prevent alerts from when MCSA clears the XML file - condition: template value_template: '{% if states.sensor.currently_recording.state != "" %} True {% else %} False {% endif %}' #Notify only during awake hours - condition: time after: '07:00:00' before: '22:00:00' action: - service: notify.ios_my_iPhone data: message: "Recording Started: {{ states.sensor.currently_recording.state }}"

This uses the iOS Notification component and when you start a recording within a few moments, you should get an alert like this:



Now we'll always know when things start recording on our HTPC and I can keep track of the important shows that are critical to record and ensure they started when we expect them to!

The great thing about having this in Home Assistant is now we can use the Recording title in other ways, how about a Text to Speech notification? Swap out the iOS notification with this action:

action: - service: tts.google_say data_template: entity_id: - media_player.first_floor_speaker message: "{{ states.sensor.currently_recording.state }} just started recording."

Now you'll get a nice voice announcement when a recording starts!

This one is definitely a kludge, but it's been very reliable and we're now able to plan around missed recordings (or quickly go in and record something if the guide data is incorrect). I hope this helps anyone using Home Assistant and Windows Media Center and I hope it inspires other ways to integrate Windows Media Center into Home Assistant.

Check out my other posts on Home Automation and other Smart Home technologies here!