Script to turn on Roku TV and go to a channel

First script, and I am struggling.

I want to turn my TV on (if not on, then on, if on, then next) if possible. I would then like it to go to a specific channel. I found out via a query the number of the app. This is what I have, but I don’t think any of it is right.

'1567648505536':
  alias: Watch Camera
  sequence:
  - data: 
    service: remote.turn_on
    entity_id: remote.living_room_tv
  - data:
    entity_id: media_player.living_room_tv
    source: 143924
    service: media_player.select_source


in lovelace, my mediaplayer card will turn on my TV, so I tried this, but still it doesn’t turn tv on (nor change the source).

'1567648505536':
  alias: Watch Camera
  sequence:
  - service: media_player.turn_on
    data:
      entity_id: media_player.living_room_tv
  - service: media_player.select_source
    data:
      entity_id: media_player.living_room_tv
      source: 143924

tried something new…still no go. Am I getting close?

'1567648505536':
  alias: Watch Camera
  sequence:
  - service: media_player.turn_on
    entity_id: media_player.living_room_tv
  - delay:
    seconds: 5
  - service: media_player.select_source
    data:
      entity_id: media_player.living_room_tv
      source: 143924
    

what does “states” show when on the channel?
This look correct but I never use for channel, only source like Plex, netflix. I will try to connect TV later and check.

well, I finally got it working. After the update to 98.3, I noticed it said I had an issue in script. I checked, and it told me to delete the delay. So the “working” script is as follows, but now if the TV is on, it will turn it off. Getting close! Would a state statement work?

  alias: Watch Camera
  sequence:
  - service: media_player.turn_on
    data:
      entity_id: media_player.living_room_tv
  - service: media_player.select_source
    data:
      entity_id: media_player.living_room_tv
      source: 143924

After reading more of the docs and looking at examples, this is my working script. Now I can tell Alexa to turn on Camera, and bam, camera is displayed on my living room TV. Wife is very happy.

'1567648505536':
  alias: Camera
  sequence:
  - service: media_player.select_source
    data:
      entity_id: media_player.living_room_tv
      source: 143924
  - delay: '00:00:01'
  - service: remote.send_command
    data:
      entity_id: remote.living_room_tv
      command:
        - right
  - condition: state
    entity_id: media_player.living_room_tv
    state: 'off'
  - service: media_player.turn_on
    data:
      entity_id: media_player.living_room_tv
  - delay: '00:00:03'
  - service: media_player.select_source
    data:
      entity_id: media_player.living_room_tv
      source: 143924
  - delay: '00:00:01'
  - service: remote.send_command
    data:
      entity_id: remote.living_room_tv
      command:
        - right
    

That was short lived. If TV is off, it turns TV on, but does not switch source. I tried upping the delay, but not go. This is what I get in log.

2019-09-05 11:06:11 ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall script.1567648505536 (c:7a54659cac2e4584abd7a9550d94013f)>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1243, in _safe_execute
    await self._execute_service(handler, service_call)
  File "/usr/src/homeassistant/homeassistant/core.py", line 1260, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 142, in service_handler
    await script.async_turn_on(variables=service.data, context=service.context)
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 214, in async_turn_on
    raise err
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 209, in async_turn_on
    await self.script.async_run(kwargs.get(ATTR_VARIABLES), context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 151, in async_run
    await self._handle_action(action, variables, context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 235, in _handle_action
    await self._actions[_determine_action(action)](action, variables, context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 318, in _async_call_service
    context=context,
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 98, in async_call_from_config
    domain, service_name, service_data, blocking=blocking, context=context
  File "/usr/src/homeassistant/homeassistant/core.py", line 1235, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/usr/src/homeassistant/homeassistant/core.py", line 1260, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 210, in handle_service
    self._platforms.values(), func, call, service_name, required_features
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 349, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 371, in _handle_service_platform_call
    await getattr(entity, func)(**data)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/roku/media_player.py", line 220, in select_source
    channel.launch()
  File "/usr/local/lib/python3.7/site-packages/roku/core.py", line 99, in launch
    self.roku.launch(self)
  File "/usr/local/lib/python3.7/site-packages/roku/core.py", line 305, in launch
    return self._post('/launch/%s' % app.id, params=params)
  File "/usr/local/lib/python3.7/site-packages/roku/core.py", line 212, in _post
    return self._call('POST', path, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/roku/core.py", line 229, in _call
    raise RokuException(resp.content)
roku.core.RokuException: b''