How can I run "echo 'on 0' | cec-client -s -d 1" on system boot?

Forum rules
Before you post please read how to get help
rene
Level 16
Level 16
Posts: 6294
Joined: Sun Mar 27, 2016 6:58 pm

Re: How can I run "echo 'on 0' | cec-client -s -d 1" on system boot?

Post by rene »

Mmm. There is a significant difference between that and the previous log. Specifically, from the immediately above:

Code: Select all

DEBUG:   [            1028]	GetPhysicalAddress - trying to get the physical address from the OS
DEBUG:   [            1040]	GetPhysicalAddress - OS returned physical address 4000
DEBUG:   [            1041]	AutodetectPhysicalAddress - autodetected physical address '4000'
DEBUG:   [            1041]	Recorder 1 (1): physical address changed from ffff to 4000
DEBUG:   [            1041]	<< Recorder 1 (1) -> broadcast (F): physical address 4000
whereas from the previous log at shutdown when it did not work:

Code: Select all

DEBUG:   [            1131]        GetPhysicalAddress - trying to get the physical address from the OS
DEBUG:   [            1131]        GetPhysicalAddress - OS returned physical address 0000
NOTICE:  [            1131]        setting HDMI port to 1 on device TV (0)
DEBUG:   [            1131]        Recorder 1 (1): physical address changed from ffff to 1000
DEBUG:   [            1131]        << Recorder 1 (1) -> broadcast (F): physical address 1000
Does it work if you in the /etc/systemd/system/cec-client.service file let the ExecStop line be

Code: Select all

ExecStop=/bin/sh -c 'echo standby 0 | /usr/bin/cec-client -s -b 4000 -d 1'
or perhaps

Code: Select all

ExecStop=/bin/sh -c 'echo standby 0 | /usr/bin/cec-client -s -b $((0x4000)) -d 1'
If not (not sure we're talking about the same "base address" here) then I'm going to need to read the source of cec-client and that'll again to wait one or two sleep-wake cycles.

Seems likely to be the issue though. The "on 0" from the ExecStart does work so "the OS" in this is likely not in fact X: it's mildly fascinating what part is up and running at command line time above yet not at shutdown time and is worthy of the moniker "the OS". Anyways, let's hope it'll at least work with the explicit -b even though it would suggest we'd want to order the .service shutdown before something else instead of relying on specifying the address manually.

PsychedelicHell
Level 1
Level 1
Posts: 26
Joined: Wed Jun 24, 2020 1:33 pm

Re: How can I run "echo 'on 0' | cec-client -s -d 1" on system boot?

Post by PsychedelicHell »

Neither of those worked, I've not noticed anything new or strange to report either. Linux just shuts down and the screen stays on.

Perhaps its worth debugging the Windows CEC client to see why that one works to turn the screen off on shutdown?

rene
Level 16
Level 16
Posts: 6294
Joined: Sun Mar 27, 2016 6:58 pm

Re: How can I run "echo 'on 0' | cec-client -s -d 1" on system boot?

Post by rene »

Well, that's mightily annoying as it stood pretty good chance. No, I don't think that dragging Windows into this is going to be useful. We'd no doubt simply see the basically same address autodetect working for runtime and shutdown-time there. We've here basically still not progressed at all, are still at the "something is keeping it from working at shutdown" with a big fat question mark as to what said something might be. It's from the log clearly not USB as such, and the only way I, without further CEC or CEC-adaptor specific knowledge, can potentially find out is by digging through the cec-utils source which I will do later, but I can't give a specific ETA. Might be able to later today or tomorrow, might have to be put on the backburner for a bit.

Wonder though why pulse-eight isn't apparently finding this to be a FAQ...

PsychedelicHell
Level 1
Level 1
Posts: 26
Joined: Wed Jun 24, 2020 1:33 pm

Re: How can I run "echo 'on 0' | cec-client -s -d 1" on system boot?

Post by PsychedelicHell »

No rush to find an answer, I really appreciate your help. Perhaps it's time to approach pulse-eight directly?

I posted my issue on their Github but I haven't had a response yet. . .

rene
Level 16
Level 16
Posts: 6294
Joined: Sun Mar 27, 2016 6:58 pm

Re: How can I run "echo 'on 0' | cec-client -s -d 1" on system boot?

Post by rene »

Okay, by "the OS" in the above address-autodetect from the logs is meant RandR, i.e., an X extension, i.e., the GUI that needs to be up indeed at least for autodetect. Given moreover that we already found manual -b to not work seems that autodetect might not be the only X dependency.

So this is to say that we need (or want, and as far as we know) to send the standby command before X shuts down which is as was already discussed early in this thread unfortunately however not as easily done as stated within the current systemd and/or desktop environment infrastructure. Easiest method is, first disable and delete the systemd route again:

Code: Select all

$ sudo systemctl disable cec-client.service
$ sudo rm /etc/systemd/system/cec-client.service
and then create the following as /etc/lightdm/lightdm.conf.d/cec-client.conf

Code: Select all

[Seat:seat0]
session-setup-script=/bin/sh -c 'echo on 0 | /usr/bin/cec-client -s -d 1'
session-cleanup-script=/bin/sh -c 'echo standby 0 | /usr/bin/cec-client -s -d 1'
and reboot. I'd be quite surprised if it still doesn't work then, but nice it is not. For one this will also sent the standby command on logout rather than just full shutdown but let's at the very least try this first. The Seat:seat0 specification is already an attempt to limit scope but if it does not work you may need Seat:* instead.

If it does work a better but more custom solution is wrapping around all of the display manager, not just around user sessions, but as said, let's at least first try. Because, yes, I do feel it a good idea to go ask pulse-eight. There might after all be a way to not need X to be up in which case a variant of the systemd service is going to be an option after all.

I.e., maybe you can refer to this post (specifically this post is probably better than this whole thread) in your GitHub request/comment: our question is how to send "standby 0" without X hence RandR up, given that -b 4000 (nor -b $((0x4000)) if the logged address was hex) which address it normally autodetects did not work either.

And if the above lightdm.conf additions also don't work we definitely need pulse-eight here, because I'm in that case definitively giving up. And it would seem that your want would not be so custom that they haven't encountered it before.

PsychedelicHell
Level 1
Level 1
Posts: 26
Joined: Wed Jun 24, 2020 1:33 pm

Re: How can I run "echo 'on 0' | cec-client -s -d 1" on system boot?

Post by PsychedelicHell »

Hey Rene,

This didn't work either, screen turns on but not off. I did see on the screen as the computer is shutting down something like "a cron job has started for TV startup/shutdown and it looks like that properly runs but again, the screen stays on.

Looks like I'll forward this thread to pulse-eight, I appreciate all your time you've spent on this and I'm sorry we couldn't solve it.

rene
Level 16
Level 16
Posts: 6294
Joined: Sun Mar 27, 2016 6:58 pm

Re: How can I run "echo 'on 0' | cec-client -s -d 1" on system boot?

Post by rene »

Given that the same works from a terminal inside X that seems hardly possible. Together with the cron job message (which none of what we did has anything to do with) I'm now starting to suspect that something you did earlier while testing is interfering. But, yes, I can't see what's happening then; hope pulse-eight knows. If they do, and if you could in that case report back: I'm now curious...

Post Reply

Return to “Scripts & Bash”