Call service from switch - WOL turn TV on/off

HI there,

HA newbie here!

I’m trying to control my philips tv on/off setting with HA. I have now managed to create an “on” switch with a WOL config. Now, I am trying to configure the “turn_off” part of the switch.
My TV has an option for turning off from HA, by using a service call.

This works fine as automation, but when I add this to the switches.yaml like so:

- platform: wake_on_lan
  name: "TV"
  mac: "xx-xx-xx-xx-xx-xx"
  host: 192.168.x.x
  turn_off:
  service: media_player.turn_off
  target:
  entity_id: media_player.55pus6804_12

My config is deemed incorrect:

Invalid config for [switch.wake_on_lan]: [service] is an invalid option for [switch.wake_on_lan]. Check: switch.wake_on_lan->service. (See ?, line ?)

I’ve tried moving the turn off commands into a script and calling the script, but as you’re also calling a service to call a script, this also fails.

Any ideas how to do this?

Kind Regards,

Eduard

Your indentation is wrong. Try:

- platform: wake_on_lan
  name: "TV"
  mac: "xx-xx-xx-xx-xx-xx"
  host: 192.168.x.x
  turn_off:
    service: media_player.turn_off
    target:
      entity_id: media_player.55pus6804_12
1 Like

Yes! This works!
Still sometimes forgetting the indentations; I mostly assume that when visual studio code doesn’t complain it’s OK, but apparently not :slight_smile:
Thank you!

If you install the Home Assistant extension and set the file format to “Home Assistant”, it will complain… :wink:

Doesn’t work for me.
Switch was created, but Turn Off part does not switch off TV, only wakeup (WOL) works.

  - platform: wake_on_lan
    mac: "XX:XX:XX:XX:XX:XX"
    name: "65EZ1000"
    host: "COM-MID1"
    turn_off:
      service: remote.turn_off
      target:
        entity_id: remote.65ez1000_series

While this automation works fine

alias: Turn Off TV
description: ""
trigger:
  - device_id: 07bfe92a154711ee022e23e2647b7e93
    domain: zha
    platform: device
    type: remote_button_short_press
    subtype: turn_off
condition:
  - condition: state
    entity_id: remote.65ez1000_series
    state: "on"
action:
  - service: remote.turn_off
    data: {}
    target:
      entity_id:
        - remote.65ez1000_series
mode: single

PS I tried media_player.turn_off service. Doesn’t work also, while similar automation works fine.