Template Switch Turning ON on reboot

I have a basic Template Switch that basically turns my LG TV on:

- platform: template
  switches:
    tv_tiago_lgtv:
      friendly_name: 'TV Tiago'
      value_template: "{{ is_state('media_player.tv_tiago', 'on') }}"
      turn_on:
        service: wake_on_lan.send_magic_packet
        data:
          mac: 58:FD:B1:A2:80:5C
          broadcast_address: 255.255.255.255
      turn_off:
        service: media_player.turn_off
        data:
          entity_id: media_player.tv_tiago
      icon_template: >-
          {% if is_state('media_player.tv_tiago', 'on') %}
            mdi:television-classic
          {% else %}
            mdi:television-classic-off
          {% endif %}

I also have the Web OS integration with the same WOL:

webostv:
  host: 192.168.1.202
  name: TV Tiago
  turn_on_action:
    service: wake_on_lan.send_magic_packet
    data:
      mac: 58:FD:B1:A2:80:5C
      broadcast_address: 255.255.255.255
  customize:
    sources:

Everything works as intended except that everytime I restart Home Assistant, my TV turns on.

Any ideas on how to prevent this?

This only shouldn’t trigger your TV on.
Looks for automations doing something with switch.tv_tiago_lgtv

There are none.

I have a couple of scripts that trigger it (they basically set the TV to a specific image mode, the soundbar to a specific mode and the lights on the room depending on what I callout to Google Assistant) but these aren’t being run as the soundbar and lights remain the same.

Could it be HDMI-CEC triggering it?

Unlikely. The only thing connected to the TV is a Mi Box. It does have HDMI-CEC enabled but the Mi Box itself isn’t integrated into HA (and it’s not turning on when the TV turns on).

From the soundbar?

Easy to test. Unplug it and restart Home Assistant.

Also check your Home Assistant logbook. You may see a context message like, “TV Tiago turned on by…”

The soundbar is dumb, controlled by an IrDA connected to home assistant.

Where can I find the logbook?

1 Like

In the side menu:

Says media_player.TV turned on. No further info.

Happens every single time I reboot the host.

It’s definitely the template switch turning it on when HA starts up.

- platform: template
  switches:
    tv_tiago_lgtv:
      friendly_name: 'TV Tiago'
      value_template: "{{ is_state('media_player.tv_tiago', 'on') }}"
      turn_on:
        service: wake_on_lan.send_magic_packet
        data:
          mac: 58:FD:B1:A2:80:5C
          broadcast_address: 255.255.255.255
      turn_off:
        service: media_player.turn_off
        data:
          entity_id: media_player.tv_tiago
      icon_template: >-
          {% if is_state('media_player.tv_tiago', 'on') %}
            mdi:television-classic
          {% else %}
            mdi:television-classic-off
          {% endif %}

I’ve commented all this code out, restarted and the TV didn’t turn on. I’ve looked at the log book and there are no errors by any kind of automation trying to turn on the now non-existent switch.

the turn_on and turn_off services are only executed through a script, automation, scene, service call, or the UI.

A restart will not affect this at all unless you’re calling a service through the list described above.

The state of the switch will not trigger itself.

You are most definitely triggering this through one of those means on startup.

Post every script, automation, scene that uses switch.tv_tiago_lgtv.

I’m not.

I have two scripts that trigger it but they aren’t connected to any automation. They are only invoked through Google Assistant and that’s not interfering since all the other actions in the script aren’t happening.

It’s literally when I reboot host that the TV comes on, 100% of the time. I have no automation that triggers on boot so there’s no valid reason for it.

You’re implying this is a bug, however I use template switches everywhere and this issue does not occur for me. Zero service calls are performed on restart or reloading of templates. Not to mention, I’ve worked on that section of code and I can tell you without doubt: Your template switch configuration will not trigger the service call on restart.

So you aren’t looking in the correct spot.

The only way we can help is if we see your configuration.

Yeah, nevermind me. I had a leftover test automation buried deep that was the root of the issue.

For wasting your time and thanks for pointing me in the right direction.