How turn on Philips TV using WOL?

okay updated !

Google philips commands :wink:
You can check connection to your TV in offline mode- it should answer:

http://ip:1925/system

Maybe my post in this thread can give an alternate solution (more of a hack actually…)

Hey guys, just in case someone lands on this page later (like I did)…

I struggled a bit turning on my Phillips Android TV with the wake on LAN. The TV does indeed go into a deep sleep after about 10 minutes. I randomly found out though, that in that case you can use Wake On Lan to wake it up, after which you can turn it on again using the remote integration. This script uses the android remote integration. Make sure you add your TV’s mac address.

conditional_wol_and_turn_on:
  sequence:
    - choose:
        - conditions:
            - condition: state
              entity_id: "remote.tv_current"
              state: "unavailable"
          sequence:
            - service: wake_on_lan.send_magic_packet
              data:
                mac: MAC_ADDRESS_HERE
            - repeat:
                sequence:
                  - delay:
                      seconds: 1
                  - condition: template
                    value_template: "{{ is_state('remote.tv_current', 'off') }}"
                until: "{{ repeat.index == 30 or is_state('remote.tv_current', 'off') }}"
    - service: remote.turn_on
      target:
        entity_id: remote.tv_current

For my TV it takes about 5 seconds to wake up after the WOL packet is send. I tried using a wait_for_trigger, but for me the state going from “unavailable” back to “off” didn’t trigger that event. This uses a loop that checks it every second for 30 seconds.

Hope this helps someone!

where have you put the code? in a script in the script section?
sorry , just need a little help , my tv works perfect with the integration but after 2-3 min it is turned off , cannot be turned on again by the integration

I would also like to join in here. It sounds like this is my solution, but I still don’t understand how to use this script as I’m relatively new to Home Assistant.
I have already tried to save the first script from this thread under Automations, but I get the error message: Message malformed: extra keys not allowed @ data[’automation‘] so I assume that something has changed in the syntax and it is no longer compatible with the latest Home Assistant version. How should I configure it instead? Or is there another solution to the problem in the meantime?

Thank you very much!

Hello, I was also struggling with wake on lan for my Philips TV and finally build a script that seems to work all the time.

Just put this as a python script somewhere:

#!/usr/bin/env python3
import socket
import time
import sys

def send_wol(mac_address, broadcast_ip=‘[your_ip_range_here]’, port=9, retries=15, delay=0.5):
“”"
Send a Wake-on-LAN magic packet multiple times.

Args:
    mac_address (str): MAC address of the target device (e.g., "10:3D:0A:8F:44:D4").
    broadcast_ip (str): Broadcast address for your network.
    port (int): UDP port to send the packet (commonly 9 or 7).
    retries (int): Number of times to send the magic packet.
    delay (int|float): Delay in seconds between attempts.
"""
# Remove common MAC separators and validate length

mac_clean = mac_address.replace(“:”, “”).replace(“-”, “”)

mac_clean = mac_address.replace(":", "").replace("-", "").lower()  # Convert to lowercase

if len(mac_clean) != 12:
    raise ValueError("MAC address should be 12 hexadecimal digits")

# Construct the magic packet: 6 bytes of 0xFF followed by 16 repetitions of the MAC address.
magic_packet = bytes.fromhex("FF" * 6 + mac_clean * 16)

# Create a UDP socket and enable broadcasting.
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    for attempt in range(1, retries + 1):
        try:
            sock.sendto(magic_packet, (broadcast_ip, port))
            print(f"Attempt {attempt}: Magic packet sent to {mac_address} via {broadcast_ip}:{port}")
        except Exception as e:
            print(f"Attempt {attempt}: Error sending magic packet: {e}", file=sys.stderr)
        if attempt < retries:
            time.sleep(delay)

if name == ‘main’:
MAC_ADDRESS = “[your_mac_address_here]”
BROADCAST_IP = “[your_ip_address_here]]” # Adjust this if needed for your network.
UDP_PORT = 9 # Commonly used port for WOL.
RETRIES = 15 # Number of attempts.
DELAY_SECONDS = 0.5 # Delay between attempts in seconds.

send_wol(MAC_ADDRESS, BROADCAST_IP, UDP_PORT, RETRIES, DELAY_SECONDS)

then add to your configuration.yaml:

shell_command:
wake_tv: “/config/[location_of_your_script_here]/wol.py”

then run the script with: action: shell_command.wake_tv

Hope this helps!