Send input to TV depending on Harmony Hub activity but only after start

Hi!

I have a Sony TV connected to a tplink smart plug (HS110) that automatically switchs off after the harmony hub sends PowerOff.

Problem is when i start an activity, i have three different activities, for the first time after Power Off State. The plug switchs on but i cant get the harmony hub to select the right input because the tv needs 27s to boot up. Delays on harmony hub doesnt work really good so i need to rely on HA to do it.

Actually i need this to only happen when starting an activity for the first time and not while switching between them. So when the switch powers on i need to check the activity that is on and add a delay and then send a command to the tv

- alias: Set TV Switch ON
  trigger:
    platform: state
    entity_id: remote.salita
    from: 'off'
    to: 'on'
  condition:
    condition: template
    value_template: "{{ states.remote.salita.attributes.current_activity != 'PowerOff' }}"
  action:
  - condition: state
    entity_id: switch.enchufesalon
    state: 'off'
  - service: switch.turn_on
    entity_id: switch.enchufesalon

This code works, but i cant get to go the second part of checking the activity and sending the command. Know that sending the command is

service: remote.send_command
    data_template:
      command: InputHdmi3
      device: 70049580
      entity_id: remote.salita

But im lost at how to code the conditions and ifs.

Your description is somewhat sparse on details regarding the command(s) to be sent after the 27 second delay. Is it always the same and if not where do you get the command from?

In general, multiple command paths requires you either to use multiple automations, or a single automation with a service_template to call multiple scripts, or a single automation calling a python_script that performs the logic and service calls. The only other path-logic tool you have is the condition: which is a simple proceed if true or stop if false, it can’t fork the code path like an if-then-else.

1 Like

Thank you for your advice! I got it working doing one automation for each Activity on my Hub

- alias: Set TV Switch ON XBOX
  trigger:
    platform: state
    entity_id: remote.salita
    from: 'off'
    to: 'on'
  condition:
    condition: template
    value_template: "{{ states.remote.salita.attributes.current_activity == 'Xbox' }}"
  action:
  - delay: 40
  - service: remote.send_command
    data_template:
      command: InputHdmi4
      device: 70049580
      entity_id: remote.salita

Thats the code for the automations, you just need to change the command on the end.

1 Like