Android TV - Turn on at time

Hi all, I am very new to Home Assistant and am just running my first setup.

I am testing HA at work and have 4 Android TV’s

As my first automation, which I thought would be simple, I wanted to turn the TV’s on at a certain time and turn them off again at a later time.

Turning off I have managed after a little messing about, but turning them on again is proving problematic.

I have the following two automations:

turning off:

  • id: ‘1650386802740’

    alias: turn off TV

    description: ‘’

    trigger:

    • platform: time

      at: ‘18:12:00’

    condition:

    • condition: time

      weekday:

      • mon

      • tue

      • wed

      • thu

      • fri

    action:

    • service: media_player.turn_off

      data: {}

      target:

      device_id: 0f6a6a38966ddeaddd3159426d0392fd

    mode: single

and turning off:

  • id: ‘1650386225577’

    alias: Turn on Tv @ 7:59

    description: ‘’

    trigger:

    • platform: time

      at: ‘18:14:00’

    condition:

    • condition: time

      weekday:

      • mon

      • tue

      • wed

      • thu

      • fri

    action:

    • service: wake_on_lan.send_magic_packet

      data:

      mac: “d4-ab-cd-87-37-ee”

      broadcast_address: ‘192.168.69.115’

    mode: single

Ignore the times, this was just me testing certain things.

The Wake On LAN seems to work sometimes and not others.

I then tried the Services in Developer tools with the following:

service: wake_on_lan.send_magic_packet
data:
mac: d4:ab:cd:87:37:ee

Again this seemed to work occasionally, but most times not.

am I missing something?

The TV’s are TCL 43ep658 Android TV’s and I am running HA on a desktop PC, using Debian.

Firstly can you reformat your yaml using the </> button so we can see it properly?

If media_player.turn_off works then what happens when you use media_player.turn_on?

Hi OzGav, thanks for your reply.

Sorry I did try the code block, but the forum gave me some error and I put it in quotes instead:

- id: '1650386225577'

  alias: Turn on Tv @ 7:59

  description: ''

  trigger:

  - platform: time

    at: '18:14:00'

  condition:

  - condition: time

    weekday:

    - mon

    - tue

    - wed

    - thu

    - fri

  action:

  - service: wake_on_lan.send_magic_packet

    data:

      mac: "d4-ab-cd-87-37-ee"

      broadcast_address: '192.168.69.115'

  mode: single

Turn Off:

- id: '1650386802740'

  alias: turn off TV

  description: ''

  trigger:

  - platform: time

    at: '18:12:00'

  condition:

  - condition: time

    weekday:

    - mon

    - tue

    - wed

    - thu

    - fri

  action:

  - service: media_player.turn_off

    data: {}

    target:

      device_id: 0f6a6a38966ddeaddd3159426d0392fd

  mode: single

If I try the media_player.turn_on option then nothing happens ever.

However when I try the above, occasionally it works, but 95% of the time not.

Not sure if the TV won’t accept the commands. Given it occasionally works with the magic packet you could try sending multiple packets a second apart and see if that works. Its a hack but…

If I try the media_player.turn_on option then nothing happens ever

However when I try the above, occasionally it works, but 95% of the time not.,

Ok I have it working now… sort of

Being honest I am an idiot. When you go in to Network settings on the TV, with wireless turned off and Ethernet connected, it tells you the IP and Mac address.

However it turns out the mac address is for the wireless adapter.

When you go in Settings, Contact Us, there is another mac address under "Wire " when using this mac address it worked.

I can only assume it worked occasionally as the wireless was enabled.

Thank you all for you help.

The only issue I have now is the Wake On Lan packet needs to be sent twice so I need to work out how to send it twice with a short delay between each one.

I never could setup this with wifi. Check for developer options on your tv. I set up it with developer options. I use wake on lan and wifi is disabled.
And you have to ping your tv because it will go into deep sleep regardless.

Any idea how I do multiple commands? As in send the Wake On Lan command twice with 5 - 10s delay in between?

There is no need for that at least not in my config. Disable wifi, enable wake on lan and ping tv. That is it.
If you can turn it on/off in media card it should work without any problems.

There is no need for that at least not in my config. Disable wifi, enable wake on lan and ping tv. That is it.
If you can turn it on/off in media card it should work without any problems.

I can’t turn it on in a card on the dashboard, once it is off, there is no power button on the dashboard any more.

image

However running an automation to turn it on works, but I have to run it twice.

When I run it the first time, I see the standy light go out as though the TV is going to turn on, but then it comes back on again. Then I run the automation again and it comes on.

This is the same when I just run the code in Developer Tools > Services

That means that tv went into deep sleep. Thats why I told you to ping it. I wrote in my thread how to do it. I have that setup and it is working. I can switch tv on whenever by home assistant or alexa.
This is working on wake on lan. I dont know what is your problem but something is wrong with your setup.

1 Like

Sorry Daniel, I dont see where you said how to ping it?

Can you share an example (I am very new to all this )

In file binary_sensor.yaml that is in config directory of home assistant you will have to add lines

# android tv
- platform: ping
 host: ip_address_of_tv
 name: Android TV
 count: 1
 scan_interval: 15

This should ping tv every 15 minutes with one ping preventing it from going into deep sleep.
If you dont have that file, create it. And restart ha.

Ok so I created the binary_sensor.yaml

Added the code and updated IP and name

I have now deleted my automations and am just trying the wake on LAN in a script with the following:

turn_on_tv4:

  alias: Turn on TV4

  sequence:

    - service: wake_on_lan.send_magic_packet

      data:

        mac: 34:51:80:a6:46:74

    - delay:

        seconds: 10

    - service: wake_on_lan.send_magic_packet

      data:

        mac: 34:51:80:a6:46:74

  mode: single

  icon: mdi:television-classic

But still it doesnt work unless run twice, the first time the standby light goes out and comes back on, the second time the TV comes on.

I do see this in my logs:

[TV 4(192.168.69.115):8009] Heartbeat timeout, resetting connection

18:10:16 – (WARNING) /usr/local/lib/python3.9/site-packages/pychromecast/socket_client.py

Couldn’t connect to 192.168.69.115:5555. TcpTimeoutException: Connecting to 192.168.69.115:5555 timed out (1.0 seconds)

18:10:12 – (WARNING) /usr/local/lib/python3.9/site-packages/androidtv/adb_manager/adb_manager_async.py

Failed to execute an ADB command. ADB connection re-establishing attempt in the next update. Error: Reading from 192.168.69.115:5555 timed out (9.0 seconds)

18:10:10 – (ERROR) Android TV

I really dont understand what is happening. The Wake On Lan is working, but seems to need to be run twice each time.

The script above was meant to run it, wait 10 seconds then run it again to work round the issue, but it doesnt work

Its up on your tv. I had some cheap android tv that always had problems with android tv integrations. I gave it to my dad. Everything is oke with that tv but it is not suitable for automation. Now I have xiaomi tv with build in chromecast and this is working without issues.
You can live with it for some time. When you figure things out little bit more with home assistant buy new tv.

I figured as much Daniel, thanks so much for all your help.

The script I posted should that work for sending the magic packet, waiting 10s and sending it again? as in is the format correct?

if it works for you than it is. There is no right or wrong.

Yes the script should do what you are after. You can check though using the automation traces Troubleshooting Automations - Home Assistant