Confused again... (Simple) Custom switch not working? wake-on-lan / media-player.turn-off

Hi folks.
I am new to yaml, I am running an up to date HA on RPI4 and trying to do as much as possible without writing script, but you know how that will pan out.

I am not entirely sure but I think my original config option was ‘0’ config, either way all my basic kit is working and configuration.yaml is, well, sparce.

Having decided I needed to get under the hood, as it were, I picked turning on my TV, and subsequently playing with it, as a place to tinker… No risk!

Its an LG running WebOS so there is an integration for that but it cant turn the thing ON just Off.
I know the TV supports WOL so I added that and was extremely pleased when the first switch I ever added, without the UI configuring it for me worked… Silly me…

The pre configured integration for WebOS will happily turn the TV Off as designed.
WOL will turn it On…
My switch will only turn it On and I cant figure out what I am doing wrong.

switch:
  - platform: wake_on_lan
    mac: e4:75:dc:8f:fa:ec
    name: "Lounge TV switch"
    turn_off:
      service: media_player.turn_off
      target:
      entity_id: media_player.lounge_tv

I copied the identity, config check is good… Has to be either structure or complete lack of understanding, and I expect the latter is most likely.

I don’t understand why there is no turn_on but I am guessing it is replaced bu the platform WOL.
I don’t understand why the indents below platform don’t seem to be required.

mmmm…
Whilst typing this I realised that there is no indent below ‘target:’ fixed that, restarted and now it works!!

Given that I don’t know if the indent, or possible me not restarting earlier, fixed the issue I am leaving this post. Seems I have way more than even I thought to learn, and I am well aware of just how little I know right now.

Starting with… Where the hell is my config anyway?
Whilst trying to trouble shoot these few lines I went looking for the code associated with the code associated Wirth the LG integration that was working, and couldn’t find it.

Any and all comments will be much appreciated.

Hi Alistair, welcome to the forum!

Have you tried a WOL from your desktop OS?

No. but only because it worked from HA on the first attempt, and by attempt I mean skimming a youtube vid and stealing the associated code…

It was the ‘OFF’ that wasn’t working… I did appreciate that WOL dosnt ‘DO’ off and that the new switch needed to use different, ‘entities’? to perform the two tasks…

What was wrong was in fact the indent, well lack of one… I guess that would be 2? is 2 spaqces 1 indent in yamleeze?

Probably should have watched a basic yaml tutorial first…
Anyhooo… All good, functionally, on and off, but I decided to post anyway because I have many more questions and a boat load of others that I don’t even now I don’t know about yet.

Just realised you may be asking can this wake a PC… It should if the PC is WOL compliant.
WOL generally… May require a data packet spec, which is an option in HA, and will ONLY work in a single sublet or where layer 2 routing is isn place between different sublets.
There is a help page about WOL in HA docks… It didnt help me much as it was a complete lack of even basic yaml knowledge causing the issue.

No, my bad: I thought you were still struggling.

Ok, since it’s solved: can you please mark this topic as such?

Almost… :slight_smile:

switch:
  - platform: wake_on_lan
    mac: e4:75:dc:8f:fa:ec
    name: "Lounge TV switch"
    turn_off:
      service: media_player.turn_off
      target:
      entity_id: media_player.lounge_tv

I think I understand that ‘switch:’ is a type of thing, entity?, and that all of any switches parts/definitions need to be indented. That would make ‘platform: wake_on_lan’ a part of a switch along with ‘turn_off:’ right?
Assuming that is correct then ‘service: media_player.turn_off’ is a property of ‘turn_off:’ and entity_id: media_player.lounge_tv is a property of target: which is a property of ‘turn_off’, which is the bit I got wrong but if all that is correct why are mac: and name: which are clearly properties of platform, not messing things up?
Is turn_on implied for a switch until a turn off is found?
Is the ‘-’ list marker indicator optional for a single entry, and if so wouldnt it make sense to always use one even for a list of 1 item?

switch:
  - platform: wake_on_lan
    mac: e4:75:dc:8f:fa:ec
    name: "Lounge TV switch"
    turn_off:
      service: media_player.turn_off
      target:
        entity_id: media_player.lounge_tv

is what works… but I don’t understand why, at least not in full.
I get that the indent makes entity id part of target: and not turn_off: but given the importance of that I am struggling to understand the ‘TURN_ON’ part at all, structurally at least.

Have you seen this: Wake on LAN - Home Assistant
and from the forum Invalid config for [switch.template]: not a valid value for dictionary value @ data

Thanks Nick,
I had seen, and failed to fully grasp the WOL info but entirely missed the very useful and absolutely on point LG stuff.

Thanks for the pointers…
I still haven’t grasped the yaml structure nuance but I think I need to do a bit more reading/watching and then come back when I have a better grasp of what I don’t know.

I will mark this thread a s closed/solved… When I find the button :slight_smile:
Cheers.

NB. The post above is the solution, thanks Nick.
As is the way of things there is always more than 1 way.
My original post would have worked but for a single indent, two spaces… It took me until post 5 to realise that and I still don’t have a good handle on code structure, but that is for another day/post.