From f3b4c006911357287aa30d0c91068cd796a785bd Mon Sep 17 00:00:00 2001 From: zerf58 Date: Thu, 26 Dec 2024 15:19:33 -0800 Subject: [PATCH] cec to turn tv on and off --- .gitignore | 2 ++ buttons.sh | 3 +++ cec.sh | 23 +++++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100755 cec.sh diff --git a/.gitignore b/.gitignore index 0e8f9a6..88f200c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /secrets.env +/tv_state + diff --git a/buttons.sh b/buttons.sh index fcacf7c..dc20082 100755 --- a/buttons.sh +++ b/buttons.sh @@ -48,6 +48,9 @@ all(){ "tasks") ;; + "sleep") + sh ~/scripts/PJ/cec.sh + ;; ### test "test") #test code here, run with buttons.sh test diff --git a/cec.sh b/cec.sh new file mode 100755 index 0000000..cd99355 --- /dev/null +++ b/cec.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +tv_on() { + cec-ctl --to 0 --image-view-on + echo "on">~/scripts/PJ/tv_state +} + +tv_off() { + cec-ctl --to 0 --standby + echo "off">~/scripts/PJ/tv_state +} + +if [[ -z "$1" ]]; then + if grep -q off ~/scripts/PJ/tv_state; then + tv_on + elif grep -q on ~/scripts/PJ/tv_state; then + tv_off + fi +elif [[ $1 = "on" ]]; then + tv_on +elif [[ $1 = "off" ]]; then + tv_off +fi