Harmony remote switch status & execution issue

I have a switch that is currently working to execute an activity.
I want the switch to be set to on or off based on the current state of the activity. Then I want to use the switch to execute the activity if the switch if off and turn off the activity if the switch is on.

Currently when the switch is set to ‘on’ the activity is executed. When I set the switch to ‘off’ the activity is not turned off. I tried the -1 and activity number. Neither work.

Not sure what I am missing from the code below in configuration.yaml.

  - platform: template
switches:
  living_room_fire_tv:
    friendly_name: Fire TV
    value_template: "{{ is_state_attr('remote.living_room', 'current_activity', '27952609') }}"
    turn_on:
      service: remote.turn_on
      data:
        entity_id: remote.living_room
        activity: 27952609
    turn_off:
      service: remote.turn_on
      data:
        entity_id: remote.living_room
        activity: -1

Why not use remote.turn_off ?

I tried the remote.turn_off. It did not work. All of the examples I found by Googling have the remote.turn_on.

Strange, I use the turn off every day, no issue here, it just turns off the active activity

I can try and switch it again to the remote.turn_off.

Do you see any other issues with the code?

This is what I use and it’s working perfectly:

- platform: template
  switches:
    harmony_tv:
      friendly_name: 'TV'
      value_template: "{{ is_state_attr('remote.harmony_hub', 'current_activity', 'TV') }}"
      turn_on:
        service: remote.turn_on
        entity_id: remote.harmony_hub
        data:
          activity: TV
      turn_off:
        service: remote.turn_off
        entity_id: remote.harmony_hub
      icon_template: mdi:television-classic

I’m at a loss here… I have the code below and I can get the activity to execute and turn on the switch. When I turn the switch to off, nothing happens.

  - platform: template
switches:
  living_room_fire_tv:
    friendly_name: Fire TV
    value_template: "{{ is_state_attr('remote.living_room', 'current_activity', '27952609') }}"
    turn_on:
      service: remote.turn_on
      entity_id: remote.living_room
      data:
        activity: 27952609
    turn_off:
      service: remote.turn_off
      entity_id: remote.living_room

I also noticed in testing this that if the switch is ‘on’ and I refresh HA, the switch gets set back to the ‘off’ position.

i always use this is in my scripts/automations

  - service: remote.turn_off
    data:
      entity_id: remote.harmony

I set the remote to be hidden so that it would continue to auto discover but not show the default remotes status on the home page. Could this be causing an issue?

remote.living_room:
hidden: true

Figured out my issue. On the value_template I was using the activity ID instead of the activity name. Once I switched it, the whole thing worked as I wanted it to.

Thanks for pointing out the remote.turn_off.