I was wondering if it would be possible to detect when an HDMI screen is turned on, and then launch, say, Kodi?

Lets say I want to use the Pi as a server and don't need Kodi to run its UI game loop 24/7, but would like it to launch if I decide to turn on the TV.

Can this be done with e.g. systemd dependencies? Or are there better ways?

Currently running OSMC but Raspbian solutions are just as interesting.

1 Answer 1


Seeing as I don't know enough about Systemd and you've welcomed "better ways" I'll offer an alternative solution from a hardware standpoint.

You don't say how you switch the TV state, whether by use of a physical button on the screen or a remote control. I'll start with the remote control because if it's a TV, the chances are it'll have one and is probably an easier solution.

You could use an IR receiver attached to a GPIO on the PI to detect power/standby button presses on the remote and use a script in your preferred language to take some action - in this case launch Kodi. If the remote has otherwise unused buttons say for DVD or teletext functions you could detect one of those and use the screen for other functions too - one to launch Kodi, a browser or, any other application/command you choose.

If you don't have a remote then you could still use the GPIO and a LDR (light dependant resistor) to detect state changes in say a status LED on the screen's case or the light levels coming from the screen itself - although this would probably result in an ugly solution. You could put an LDR inside the case of the screen and detect the state changes on the screens back light. If you are using a physical button on the case to cycle the power you could use the GPIO again to detect the presses.

  • IR receiver, of course! Very good suggestion. Edit: yes, you're right in your assumption — it's a tv leaving standby by remote
    – Andreas
    Oct 25, 2017 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.