I use the following command to turn off all media devices.
curl -X POST -H "x-ha-access: " -H "Content-Type: application/json" -d '{}' http://192.168.0.20:8123/api/services/media_player/turn_off
However this does not always work. I have found out that it only works when my TV is on.
When I run this command when my TV is off I get the error below.
curl -X POST -H "x-ha-access: " -H "Content-Type: application/json" -d '{"entity_id": "media_player.tv_samsung"}' http://192.168.0.20:8123/api/services/media_player/turn_off
The following ERROR is written to log.
2017-08-17 14:55:35 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/lib/python3.6/asyncio/tasks.py", line 181, in _step
result = coro.throw(exc)
File "/usr/lib/python3.6/site-packages/homeassistant/core.py", line 1025, in _event_to_service_call
yield from service_handler.func(service_call)
File "/usr/lib/python3.6/site-packages/homeassistant/components/media_player/__init__.py", line 408, in async_service_handler
yield from getattr(player, method['method'])(**params)
File "/usr/lib/python3.6/asyncio/futures.py", line 331, in __iter__
yield self # This tells Task to wait for completion.
File "/usr/lib/python3.6/asyncio/tasks.py", line 244, in _wakeup
future.result()
File "/usr/lib/python3.6/asyncio/futures.py", line 244, in result
raise self._exception
File "/usr/lib/python3.6/concurrent/futures/thread.py", line 55, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/lib/python3.6/site-packages/homeassistant/components/media_player/samsungtv.py", line 179, in turn_off
self.get_remote().close()
File "/usr/lib/python3.6/site-packages/homeassistant/components/media_player/samsungtv.py", line 127, in get_remote
self._remote = self._remote_class(self._config)
File "/usr/lib/python3.6/site-packages/samsungctl/remote.py", line 10, in __init__
self.remote = RemoteWebsocket(config)
File "/usr/lib/python3.6/site-packages/samsungctl/remote_websocket.py", line 23, in __init__
self._serialize_string(config["name"])))
File "/usr/lib/python3.6/site-packages/websocket/_core.py", line 216, in connect
options.pop('socket', None))
File "/usr/lib/python3.6/site-packages/websocket/_http.py", line 67, in connect
sock = _open_socket(addrinfo_list, options.sockopt, options.timeout)
File "/usr/lib/python3.6/site-packages/websocket/_http.py", line 109, in _open_socket
sock.connect(address)
OSError: [Errno 113] Host is unreachable