Custom On Command for media_player: - platform: webostv

I am not sure if this is possible but I would like to be able to add a custom on command for my LG WebOS TV. I have added the media player to by configuration and that works fine once TV is on. Unfortunately, my TV doesn’t support wake on LAN so no use adding the mac: as this just gives me an on button that doesn; 't work. I have usually turn ON my TV using another raspberry pi connected via HDMI and HDMI CEC commands. This works perfectly. I know I can add a separate on switch using the below config which works fine but my question is, can I combine the 2 and add a custom ON command for the webostv media_player configuration? Basically add the power button back which adding mac: option adds but have it work by running a custom command?

switch:
   - platform: command_line
     switches:
      tv_rpi:
        command_on: ssh [email protected] "tvservice -o; echo on 0 | cec-client -s -d 1;tvservice -p"
        command_off: ssh [email protected] "tvservice -o; echo 'standby 0' | cec-client -s -d 1"
        command_state: ssh [email protected] "echo 'pow 0' | cec-client -s |grep 'power status:'"
        value_template: '{{ value == "power status: on" }}'

Paulio

Hi,
maybe with https://home-assistant.io/components/media_player.universal/ ?

@nxd4n Thank you so much, I finally got around to looking into this, It looked very complicated when I first looked at it and at the time when you replied I didn’t have time to look into it. Today after actually reading the universal media player setup page I found that the setup is very basic. I only had to add the one override command for power_on, the rest comes from the child entry. Then just hide the command line power_on switch I created and child media player and now everything is working perfectly just how I wanted it :smile: Thanks again.

Paulio

Hey @nxd4n, do you know is there a way to add channel up & down controls to the universal player? I don’t see an option for it but would think it should be possible. I have setup custom switches for now but would be good to hide them and add this to the media player.

No, I didn’t look further into it, I remapped nextTrack in media_player/braviatv.py to do a channel_up in place of media_next(). Dirty hack that will be overwritten at next update.

Paulo, can you share your configuration set up for this.?
Thank you

Hey @juan11perez, Yea sure. Bellow are the relevant bits I used for this. I just have an old Raspberry Pi 1 connected to my TV via HDMI cable to turn it on.

customize:
  switch.tv_rpi:
    hidden: true
  media_player.tv:
    hidden: true
	
	
media_player:
  - platform: webostv
    host: !secret tv_ip
    name: TV
    filename: webostv.conf
    customize:
      sources:
        - livetv
        - youtube
        - Plex

  - platform: universal
    name: Living Room TV
    children:
      - media_player.tv
    commands:
      turn_on:
        service: switch.turn_on
        data:
          entity_id: switch.tv_rpi

switch:
- platform: command_line
  switches:
    tv_rpi:
      friendly_name: TV Power On
      command_on: ssh [email protected] "tvservice -o; echo on 0 | cec-client -s -d 1"

Paulio

1 Like

Thank you Paulio.
So the Pi1 is tuning just the OS, Jessie?
And the ip in the command line switch is this Pi ip?

No worries, yes it is just used for Turning on the TV at this stage but you could use it for more if needed. Could put Kodi on it or something. I would prob use a Raspberry Pi Zero W if I was buying something for this but I had the old Pi laying around not being used.

Paulo, thank you very much.

Hi, I’ve tried almost everything I can think of, i’m unable to run the following commands as “homeassistant”

i switch to env, source bin/activate when running tvservice -o or tvservice -p i get the following error [E] Failed to initialize VCHI (ret=-1)

I’ve updated my /etc/sudoers to:
homeasssistant ALL = (root) NOPASSWD: /home/homeassistant/magic/magic_on.sh, /home/homeassistant/magic/magic_off.sh

Script:

#!/bin/bash
tvservice --preferred

Error:
(homeassistant) homeassistant@raspberrypi:~/magic $ bash ./magic_on.sh
[E] Failed to initialize VCHI (ret=-1)

All I would like to do is create a command_line switch in HA to turn off/on Magic Mirror Screen. Once it’s in HA I can create a script or scene to control it with Google Home.

Please Help :frowning:

Thanks Paulio! I used this to turn on a 2011 Samsung TV that didnt support a wake on lan function… I used the built in CEC switch in HASSio instead of the ssh command, but it works great!