Controling media player with standard remote

I’d like to share my simple project that I made to control my Chromecast Audio with standard IR remote from stereo it’s connected to.

I did it to ease changing songs for my family when I play music from Google Music on Chromecast Audio and they don’t have access to my phone cause I’m in the other part of house. The stereo itself cannot control chromecast because it’s connected to simple jack-jack cable.

Important thing is that I don’t know much about electronics, even less about arduino programming so I used prebuild, precompiled components.

What I used:

  • media player - I used Chromecast Audio connected to old Sony Stereo via Audio In
  • HA running on anything, recognizing your media player. My Chromecast is getting auto discovered so no problem there.
  • MQTT server which is listened by HA
  • ESP8266
  • ESPEasy software (my version is 120)
  • IR receiver - I used ready Ir component which I think is based on TSOP4838 (recognized by ESPEasy)
  • connection cables
  • remote control - it can be any remote but for my family’s convenience I use the one from Sony stereo to which my Chromecast Audio is connected.

Pictures of the hardware:

  • ESP 8266 - Lolin Board:
  • IR receiver - prebuild from YWRobot
  • whole set put together:

What I’ve done with it:

  • setup HA, media player, MQTT
  • flashed ESPEasy on ESP8266 board - standard precompiled file from ESPEasy project’s page
  • Connected ESP to Wifi and connect it to my MQTT server on Config page:
  • Connected IR remote to 3V, GND and data pin
  • configured IR on devices page of ESP:
  • Now was the harder part. I needed to get what codes are sent when pressed which buttons. Luckly ESPEasy shows values received by IR on it’s web page. So I’ve pointed remote to receiver, pressed desired button, refreshed the page and checked the code. It looked like that:

    In the example I pressed on/off button on remote so the code for my remote’s on/off is 2145523267.
  • When I got all the codes I wanted I wrote automation part for Home Assistant. In my config ESP sends MQTT message in format /ESPname/Name of Device/Value Name and the payload of the message is the IR code. It looks like that in MQTT reading software:

    So the automation part was quite simple now:

automation:
# Controling Chromecast Audio from remote

  • alias: ‘Song forward’
    trigger:
    platform: mqtt
    topic: “/Esp03/IRda/IR”
    payload: ‘2152563055’
    action:
    service: media_player.media_next_track
    entity_id: media_player.chromecastaudio
  • alias: ‘Song reverse’
    trigger:
    platform: mqtt
    topic: “/Esp03/IRda/IR”
    payload: ‘1788844172’
    action:
    service: media_player.media_previous_track
    entity_id: media_player.chromecastaudio
  • alias: ‘Song play’
    trigger:
    platform: mqtt
    topic: “/Esp03/IRda/IR”
    payload: ‘862875138’
    action:
    service: media_player.media_play
    entity_id: media_player.chromecastaudio
  • alias: ‘Song pause’
    trigger:
    platform: mqtt
    topic: “/Esp03/IRda/IR”
    payload: ‘1580485439’
    action:
    service: media_player.media_play_pause
    entity_id: media_player.chromecastaudio
  • restart HA and enjoy controling chromecast from remote.

In my set up I configured the on/off button to turn off Chromecast, I’ve put ESP with receiver behind stereo so when I turn off chromecast it also turns off the stereo.
It’s not visible at all and this IR receiver gets the Ir codes very well when I point at the stereo.
The only problem I have with the setup is changing song to previous one, it simply restarts it. Simlar to pressing once rev on remote to pressing it twice quickly.
I think it’s a problem with HA implementation of control for Chromecast rather that my setup because I also cannot do it from HA page.

If you have any ideas of adjusting the setup please let me know.

Hope my guide is clear and will work for you:)

7 Likes

Have been trying to apply this to my Chromecast 2. The Chromecast appears in Home Assistant and I can use the mouse to control it but my IR commands from my D1 Mini have no affect Possibly because the configuration.yaml entry is incorrect or Home Assistant isn’t getting the commands? I mainly want to play and pause. This is what I have in my configuration.yaml file.

automation:
# Controlling Chromecast from remote
- alias: 'play'
trigger:
platform: mqtt
topic: "/ChromecastIR/IRda/IR"
payload: '4007692820'
action:
service: media_player.media_play
entity_id: media_player.MyChromecast

You need to have MQTT set up.
MQTT server configured on some server(probably the same as HA), then in Home assistant you need to provide the details in configuration.yaml and in Esp Easy you need to put server details on config page. There is a screenshot above with my configuration details.

It’s all setup and Home Assistant is able to use mqtt with command line and the mqtt services area. Chrome Cast appears in Home Assistant by using
'media_player:

  • platform: cast

in my configuration.yaml file and I am able to interact with it. The Nodemcu says it is connected to my mqtt server which runs on my RPI3 with Home Assistant.

If I simply copy and paste your code, the Home Assistant gui won’t load and ‘hass’ doesn’t appear when I type ‘top’ at the console.

4 days at this!! Finally got it working. A lot of cross referencing with other examples for layout and indentation.

The following works with ir codes from a Sony iPod dock remote.

automation:
  - alias: 'Play_ChromeCast'
    trigger:
      platform: mqtt
      topic: "ChromecastIR/IRda/IR"
      payload: '4230927874'
    action:
      service: media_player.media_play
      entity_id: media_player.paulchromecast
   
  - alias: 'Pause_ChromeCast'
    trigger:
      platform: mqtt
      topic: "ChromecastIR/IRda/IR"
      payload: '830811195'
    action:
      service: media_player.media_pause
      entity_id: media_player.paulchromecast
      

  - alias: 'Stop_ChromeCast'
    trigger:
      platform: mqtt
      topic: "ChromecastIR/IRda/IR"
      payload: '3219004559'
    action:
      service: media_player.media_stop
      entity_id: media_player.paulchromecast
1 Like

You are correct. The indentations are not correct in my example.
I have no idea why I didn’t noticed that it didn’t paste indentations correctly. I will edit the example when I’ll have some time later on and access to source code.
Sorry that it caused you so much problems.

No worries. Your code and response helped me get there in the end and also made me aware of home assistant’s capabilities. I just started learning about home assistant via ‘Bruh Automation’.