Shell Command with Input select State

Hello,

i have an problem with executing a shell command with a state of an input select.
This is my Command:

start_stream: ‘/home/homeassistant/.homeassistant/stream_start.sh {{ states(“input_select.stream_source”) }}’

On the Command line i would start it like: /home/homeassistant/.homeassistant/stream_start.sh “tvchannel”
This works perfectly.
When i change the command in the configuration.yaml into: " /home/homeassistant/.homeassistant/stream_start.sh prosieben" its working.

I followed this Instructions:
https://www.home-assistant.io/integrations/shell_command/

My input select is:

input_select:
stream_source:
name: Streaming-Quelle
options:
- daserste
- zdf
- sat1
- prosieben
- vox
- dmax
- kabel-1
- rtl
- rtl2

Greetings from Germany!

Are you seeing any errors in the log? You might try enabling debug:

logger:
  default: info
  logs:
    homeassistant.components.shell_command: debug

Restart, try the command, and check the full log for details (or look in home-assistant.log.)

hey, i tried it and got this output:

2019-12-15 23:16:08 INFO (MainThread) [homeassistant.helpers.script] Script start_stream: Running script
2019-12-15 23:16:08 INFO (MainThread) [homeassistant.helpers.script] Script start_stream: Executing step call service
2019-12-15 23:16:08 ERROR (MainThread) [homeassistant.components.script] Error executing script script.start_stream. Unknown error for call_service at pos 1:
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/script/init.py”, line 209, in async_turn_on
await self.script.async_run(kwargs.get(ATTR_VARIABLES), context)
File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/script.py”, line 190, in async_run
await self._handle_action(action, variables, context)
File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/script.py”, line 273, in _handle_action
await self._actions[_determine_action(action)](action, variables, context)
File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/script.py”, line 355, in _async_call_service
context=context,
File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/service.py”, line 97, in async_call_from_config
domain, service_name, service_data, blocking=blocking, context=context
File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/core.py”, line 1235, in async_call
await asyncio.shield(self._execute_service(handler, service_call))
File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/core.py”, line 1260, in _execute_service
await handler.func(service_call)
File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/shell_command/init.py”, line 78, in async_service_handler
process = await create_process
File “/usr/lib/python3.7/asyncio/subprocess.py”, line 217, in create_subprocess_exec
stderr=stderr, **kwds)
File “/usr/lib/python3.7/asyncio/base_events.py”, line 1533, in subprocess_exec
bufsize, **kwargs)
File “/usr/lib/python3.7/asyncio/unix_events.py”, line 190, in _make_subprocess_transport
**kwargs)
File “/usr/lib/python3.7/asyncio/base_subprocess.py”, line 37, in init
stderr=stderr, bufsize=bufsize, **kwargs)
File “/usr/lib/python3.7/asyncio/unix_events.py”, line 763, in _start
universal_newlines=False, bufsize=bufsize, **kwargs)
File “/usr/lib/python3.7/subprocess.py”, line 775, in init
restore_signals, start_new_session)
File “/usr/lib/python3.7/subprocess.py”, line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: ‘/home/homeassistant/.homeassistant/stream_start.sh’
2019-12-15 23:16:08 ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall script.start_stream (c:7108cd5926bb412eb3674de91b4d9eb5)>
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/core.py”, line 1243, in _safe_execute
await self._execute_service(handler, service_call)
File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/core.py”, line 1260, in _execute_service
await handler.func(service_call)
File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/script/init.py”, line 142, in service_handler
await script.async_turn_on(variables=service.data, context=service.context)
File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/script/init.py”, line 214, in async_turn_on
raise err
File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/script/init.py”, line 209, in async_turn_on
await self.script.async_run(kwargs.get(ATTR_VARIABLES), context)
File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/script.py”, line 190, in async_run
await self._handle_action(action, variables, context)
File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/script.py”, line 273, in _handle_action
await self._actions[_determine_action(action)](action, variables, context)
File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/script.py”, line 355, in _async_call_service
context=context,
File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/service.py”, line 97, in async_call_from_config
domain, service_name, service_data, blocking=blocking, context=context
File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/core.py”, line 1235, in async_call
await asyncio.shield(self._execute_service(handler, service_call))
File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/core.py”, line 1260, in _execute_service
await handler.func(service_call)
File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/shell_command/init.py”, line 78, in async_service_handler
process = await create_process
File “/usr/lib/python3.7/asyncio/subprocess.py”, line 217, in create_subprocess_exec
stderr=stderr, **kwds)
File “/usr/lib/python3.7/asyncio/base_events.py”, line 1533, in subprocess_exec
bufsize, **kwargs)
File “/usr/lib/python3.7/asyncio/unix_events.py”, line 190, in _make_subprocess_transport
**kwargs)
File “/usr/lib/python3.7/asyncio/base_subprocess.py”, line 37, in init
stderr=stderr, bufsize=bufsize, **kwargs)
File “/usr/lib/python3.7/asyncio/unix_events.py”, line 763, in _start
universal_newlines=False, bufsize=bufsize, **kwargs)
File “/usr/lib/python3.7/subprocess.py”, line 775, in init
restore_signals, start_new_session)
File “/usr/lib/python3.7/subprocess.py”, line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: ‘/home/homeassistant/.homeassistant/stream_start.sh’

Brief Googling would seem to imply you need to add the following “shebang” line at the top of stream_start.sh:

#!/usr/bin/env sh

If that doesn’t work then maybe try one of these:

#!/usr/sh
#!/usr/bash
#!/usr/bin/env bash
1 Like

Ohh yes that worked for me…
Thanks you so much !

Greetings :wink:

1 Like