Automation cannot turn on switch

Hi

Im trying to turn on a switch with automation, does anyone have an idea why this is not working ?

- alias: "Turn the TV on"
  trigger:
    - platform: state
      entity_id: binary_sensor.tv_power
      to: 'on'
  action:
    service: switch.turn_on
    entity_id: switch.wake_lg_tv

The format of your automation looks correct.

Have you reloaded your automations or restarted the HA service since writing the automation?

Look in the developer tools states menu (this <> button lower left of main page).

Is binary_sensor.tv_power the correct entity_id?

Is it changing to on?

What sort of switch are you using?

Can you successfully control it manually?

Is switch.wake_lg_tv the correct entity_id?

Yes I have reloaded Automations and also restarted the server after writing the automation.

And yes I am using the correct entity_id, see below

image

My binary sensor is changing to on I can see that on the states page.

My switch is a command_line switch with the following configuration:

switch WOL:
  - platform: command_line
    switches:
      wake_lg_tv:
        command_on: ssh -i (Etc.. I have tested the command from within my Docker container and it works)

Actually I cannot control it manually, I just assumed it worked which seems a bit stupid now I think of it. So i guess something is wrong with my command_line switch, but I have followed the documentation on the home page. Can you see anything wrong with it ?

Rather than using the command line platform you could try HA’s built in WoL switch platform, this works for me:

switch:
  - platform: wake_on_lan
    mac_address: "xx:xx:xx:xx:xx:xx" #[redacted]
    name: "Wake-up Cinema PC"
    host: 10.1.1.3

I have also tried that. But I believe it didn’t work because my server is connected to the network via wlan, and the wake on lan switch uses Ethernet to send the packet, and that cannot be changed. So I use etherwake on my host PC because with that I can specify it to use wlan.

But what I really want is to turn on my tv using automation.
And my tv is connected with the WebOs component and with that I can turn on the tv using wake on lan. But when I try and do an automation with action “media_player.turn_on” nothing happens.

Yeah WoL broadcast packets will get blocked from your wireless network.

What happens if you run a shell command in a script rather than a command line switch?

I have not tried shell_command yet, I will try that later. Do I put the shell_command into configuration.yaml, like so?

shell_command:
  wol_packet: ‘ssh -i etc...’

And then call the service “shell_command.wol_packet” with an automation?

Yep. That’s the way to do it. Careful with those single quote types though (you have pasted fancy ones).

Oh yes I can see that thanks.

So i tried the shell command but that did not work either. However it is not showing in the states page, should it do that ?

Bugger.

So, you can run the command from within the docker container but not get an automation to do so.

I struggled for ages with a shell command to delete old backups. Never got a solution. Some things just aren’t possible in the hassio environment, possibly due to permission problems, I just don’t know.

It should show in the developer tools ‘services’ menu.

Hurray, I finally got it working after weeks of trying to turn my TV on with automation.

The issue was that I needed to run the etherwake command on the host with sudo, which normally requires a password. But I added a line in sudo visudo so that I can run sudo commands without passords for the specific user I log on to the host with.

Now I should be able to set up Siri to turn the TV on via mqtt, which was my original goal.