Turn on TV when I turn on my pc

HI there

I need some assistance, I got a LG c2 42" that I can turn on with Wake on lan - I want to use unifi to detect my desktop and then turn on the tv? How do I setup this automation? Thanks in advance

Write a batch file on your PC to turn on the TV then put it into your startup folder on the PC.

If you have the Unifi integration and want to use that - it should expose a binary_sensor for your PC. Have to be aware that if PC is connected via ethernet, if it’s not fully sleeping/turned off - Unifi might still see it as connected and therefore binary_sensor won’t change status.

To get around this, I use Windows Task Scheduler and run a batch file when the PC unlock & at startup.

My use-case is to turn on a fan that I have near my PC when I’m using it.

I’m currently using Hubitat (mainly for Zigbee/ZWave), but works for this too. I created a virtual button in Hubitat that’s exposed to HA. The batch file when PC is unlocked looks like:

curl http://###.###.###.###/apps/api/3/devices/$$/push/%?access_token=xxxx

Where ### is the local IP of Hubitat, $$ is the Hubitat device # of the virtual button, % is the button number to be pushed and xxxx is the long term access token I created within HA.

I then setup an automation in HA that triggers based on this virtual button being pushed:

Before I went this route, fwiw, I used to have the batch file call a python script that used the HA API to run a script.

Batch file:

python C:\Users\username\Documents\thinkpad_locked.py

.py file:

from requests import post
import json

url = 'https://###.###.###.###:8123/api/services/script/turn_on'
headers = {
    'Authorization': 'Bearer xxxxxxxxx',
    'content-type': 'application/json',
}
payload = {
    'entity_id':'script.thinkpad_locked'}

response = post(url, headers=headers, data = json.dumps(payload))
print(response.text)

Where #### is local ip to Home Assistant and xxx is long lived access token in HA

Hope this at least gets you started - I set these up a while ago - so unsure if an ‘easier’ way exists now to execute this.

I use ping to detect my pc status, and as you have wol on your tv, the automation should be simple, like

- id: turn on off tv when pc on off
  alias: tv.turn.on.off.based.on.corei7
  triggers:
  - trigger: state
    entity_id: binary_sensor.ping_corei7asere
    to: 'on'
  - trigger: state
    entity_id: binary_sensor.ping_corei7asere
    to: 'off'
  action:
  - action: "switch.turn_{{'on' if trigger.to_state.state == 'on' else 'off'}}"
    target:
      entity_id:
      - your.tv

That would mimic your pc state on your tv.
If you just want to turn on your tv and keep it on when your pc is off then you have to change the automation a bit.

1 Like