[mythtv-users] Power on/off TV with CEC

John reidjr at lineone.net
Sun May 25 16:32:59 UTC 2014


On 25/05/14 09:44, Simon Hobson wrote:
> Josu Lazkano <josu.lazkano at gmail.com> wrote:
>
>> But nothing happens on power off. The frontend PC power off but the TV is on.
>>
>> How could I power off? Need I configure any CEC command?
> I'm not familiar with either CEC or this bit of software, but ...
>
> I expect you'll need to configure <something> to send a command as the system shuts down. Timing is important here - you don't want it to happen too soon, but equally your script *MUST* run before the system stops the daemon you use to talk to the CEC adapter (or anything that needs).
>
> I imagine a script added to /etc/init.d, and linked to in /etc/rcn.d/Knnn, would do it - the trick will be getting it to run at the right time.
>
> _______________________________________________
> mythtv-users mailing list
> mythtv-users at mythtv.org
> http://www.mythtv.org/mailman/listinfo/mythtv-users
> http://wiki.mythtv.org/Mailing_List_etiquette
> MythTV Forums: https://forum.mythtv.org
>

The libcec-daemon is cool, but it took me a while to realise it is for 
controlling mythtv from the TV. What I wanted was to control the TV from 
myth. My MCE remote will turn on my SONY TV, but does not (annoyingly) 
turn it to the HDMI port for the FE. So I use irexec from my MCE remote 
to control TV state via cec adapter.

To turn TV on, to correct HDMI port:

john at revo:~$ cat ~/tvon.sh

#!/bin/bash
echo as | cec-client -s -d 1
logger "tvon.sh sent active source to tv"
exit 0


So to simply turn TV off I use :

john at revo:~$ cat /home/john/tvoff.sh

#!/bin/bash
echo standby 0 | cec-client -s -d 1
logger "tvoff.sh sent standby to tv"
exit 0

Logger just echos the text to /var/log/syslog. I found it usefull for 
faultfinding.

As I call it from FE shutdown I also use this to check if the TV is on 
the FE HDMI or doing somthing else, like watching TV from source ( 
Horrors ! ).

john at revo:~$ cat /home/john/tvoffstatefull.sh

#!/bin/bash
             cmd=$(sudo echo scan | cec-client -d 1 -s)

             if [[ "$cmd" == *"source: TV (0)"* ]]
             then
                     logger "tvoffstatefull.sh found DVB-T TV no action"
                    # $(/home/john/tvon.sh)
                     exit 0
             fi

             if [[ "$cmd" == *"source: unknown (-1)"* ]]
             then
                     logger "tvoffstatefull.sh found TV on HDMI TV and 
calls tv.off"
                     bash /home/john/tvoff.sh
                     exit 0
             fi

             logger $cmd
     exit 0



cec-client will fail ( I think) if libcec-daemon is running, so you 
might need to juggle the two aproaches, or just choose one. I use the FE 
remote in preference to the TV remote for Mythtv, so I don't bother with 
inbuilt cec, or libcec-daemon.

Hope this help you.

john





More information about the mythtv-users mailing list