Rest API for media_player LG

I am struggling to turn on my LG TV with an external HTTP call. The LG TV turns on perfectly through the HA UI but I can not figure out what HTTP command is to send as I either get connection refused or method not allowed. I only have one device configured at this point and that is the LG TV as seen at the bottom of the configuration.yaml file. Any suggestions would be greatly appreciated. I’ve spent a lot of time in the forum and just can’t figure it out.

Some examples of the commands I’ve sent are as follows from my pc command line:

curl -k http://192.168.0.254:8123/api/services/media_player/turn_on?api_password=abcdef (response - Method not allowed)
curl -k http://192.168.0.254:8123/api/services/media_player/turn_on/?api_password=abcdef (response - Method not allowed)

Curl -k http://192.168.0.254:8123/api/?api_password=abcdef
this works and replies “API Running” so at least i’m connecting

curl -k http://192.168.0.254:8123/api/services/media_player/turn_on?api_password=abcdef{“entity_id”:“media_player.television”} (response - Method not allowed)

Partial configuration.yaml file

# Show links to resources in log and frontend
introduction:

# Enables the frontend
frontend:

# Enables configuration UI
config:

logger:
  default: error
   
http:
  api_password: abcdef
  
  # Uncomment this if you are using SSL/TLS, running in Docker container, etc.
  # base_url: example.duckdns.org:8123

# Checks for available updates
# Note: This component will send some information about your system to
# the developers to assist with development of Home Assistant.
# For more information, please see:
# https://home-assistant.io/blog/2016/10/25/explaining-the-updater/
updater:
  # Optional, allows Home Assistant developers to focus on popular components.
  # include_used_components: true

# Discover some devices automatically
# discovery:

# Allows you to issue voice commands from the frontend in enabled browsers
conversation:

# Enables support for tracking state changes over time
history:

# View all events in a logbook
logbook:

# Track the sun
sun:

# Weather prediction
sensor:
  - platform: yr

# Text to speech
tts:
  - platform: google

group: !include groups.yaml
automation: !include automations.yaml

# LG TV Webos 
media_player:
  - platform: webostv
    host: 192.168.0.216
    mac: C8:08:E9:CC:ED:00
    name: television
    filename: webostv.conf

I figured it out. Below works correctly. Now I’m trying to figure out how to change the source on the LG webostv

curl -X POST -H “x-ha-access: mypassword” -H “Content-Type: application/json” http://192.168.0.254:8123/api/services/media_player/turn_on

For anyone interested. The correct command format within vera luup is:
os.execute [[curl -X POST -H “x-ha-access: mypassword” -H “Content-Type: application/json” http://192.168.0.254:8123/api/services/media_player/turn_on]]

1 Like

Can I ask what you are trying to do? I saw that you mentioned you are able to use the Home Assistant UI - what are you using the rest commands for?

I’m very new to Home-Assistant and currently run almost all my automation through Vera and hamony hubs My plan is to pull all my networked components off of harmony control and really just starting with the LG tv. I already have my Vera with full Alexa connectivity so my plan to turn on the TV was to simply setup a scene within my vera hub to issue a rest command to the LG Webos component. I figured out how to do it and it works great. I’m now trying to figure out how to change the lg source and struggling to find any documentation as I’m basically guessing at this point the correct curl command.

If you have any suggestions I’d really appreciate it. I have a lot experience with Vera Luup coding using scenes and triggers so I need to see if maybe the best option would be to set up a scene in HA that would power on the TV and maybe change the input to say Netflix. I can do all this through the HA UI so I assume its possible through the API. Then I would issue an API command through Vera to execute the ha scene. I’m still learning.

Been looking for something just like this!

Could you direct me how an LG TV user would go about finding their:

LG TV IP_Address
Port number
x-ha-access: password?

I was able to build an apple siri Shortcut for a SONY TV but am looking at doing the same for LG TV’s but since i do not have one I need assistance on how direct LG users to find the information above on their own LG TV’s!

Thank you.