You are not logged in.

#1 2022-03-21 12:02:44

lmart
Member
Registered: 2019-01-04
Posts: 22

"[Solved]" Conky - AC Power Cord, Battery Script

Trying to write conky code to test when AC power cord is unplugged, then kick off a script to display battery status and, turn off when plugged into wall circuit.
Any suggestions?
Thanks.

Last edited by lmart (2022-03-24 22:42:28)

Offline

#2 2022-03-21 14:52:49

eight.bit.al
Member
From: Prison
Registered: 2015-10-01
Posts: 1,288

Re: "[Solved]" Conky - AC Power Cord, Battery Script

lmart wrote:

Trying to write conky code to test when AC power cord is unplugged, then kick off a script to display battery status and, turn off when plugged into wall circuit.
Any suggestions?
Thanks.

Please share what you have already.

8bit

Offline

#3 2022-03-22 16:12:19

lmart
Member
Registered: 2019-01-04
Posts: 22

Re: "[Solved]" Conky - AC Power Cord, Battery Script

thank you for your reply
do you have conky code to check the ac power cord?


per your request, the following code is for the battery
it does not address the issue of the AC power cord


IF AC POWER CORD UNPLUGGED THEN:

${if_existing /sys/class/power_supply/BAT0}\
${alignr}${battery_bar 8,70 BAT0}\
${endif}\

${if_existing /sys/class/power_supply/BAT1}\
${alignr}${battery_bar 8,70 BAT1}\
${endif}\

END-IF AC POWER CORD UNPLUGGED:

Offline

#4 2022-03-22 17:06:56

PackRat
jgmenu user Numero Uno
Registered: 2015-10-02
Posts: 1,605

Re: "[Solved]" Conky - AC Power Cord, Battery Script

This might help you. It's the baraction.sh script for spectrum. The battery section takes the status of the AC into account then uses acpi for the output.

spectrum baracction script

You might be able to reverse engineer something for conky, or maybe just use that script and only output the battery information.


You must unlearn what you have learned.
    -- yoda

Offline

#5 2022-03-22 23:59:37

lmart
Member
Registered: 2019-01-04
Posts: 22

Re: "[Solved]" Conky - AC Power Cord, Battery Script

thanks
will check out your suggestion

to reverse engineer, will need to know what conky commands relate to the AC Power and, right now, unable to find anything that works ... most likely my inability ...

Offline

#6 2022-03-23 00:32:28

PackRat
jgmenu user Numero Uno
Registered: 2015-10-02
Posts: 1,605

Re: "[Solved]" Conky - AC Power Cord, Battery Script

acpiacadapter may be what you want:

       acpiacadapter (adapter)
              ACPI ac adapter state. On linux, the adapter option specifies
              the subfolder of /sys/class/power_supply containing the state
              information (tries "AC" and "ADP1" if there is no argument
              given).  Non-linux systems ignore it.


       acpifan
              ACPI fan state.


       acpitemp
              ACPI temperature in C.

conky has a pretty extensive man page - better than the online document in many ways; open your preferred terminal and "man conky"


You must unlearn what you have learned.
    -- yoda

Offline

#7 2022-03-23 01:26:59

lmart
Member
Registered: 2019-01-04
Posts: 22

Re: "[Solved]" Conky - AC Power Cord, Battery Script

thanks for your reply

checked the man page before posting and, after many fruitless attempts, started my post

result from terminal session:
$ # AC unplugged
$ cat /sys/class/power_supply/AC/online
0
# AC plugged in
$ cat /sys/class/power_supply/AC/online
1

still trying to figure out exactly how to write the conky code to test this condition
hoped there might be some existing conky code to help me figure out what's what

Offline

#8 2022-03-23 11:43:37

lmart
Member
Registered: 2019-01-04
Posts: 22

Re: "[Solved]" Conky - AC Power Cord, Battery Script

resolved:

${if_match ${acpiacadapter} == "off-line"}${color yellow}unplugged${color}${endif}\

Offline

#9 2022-03-23 12:03:26

rbh
Moderator
From: Sweden/Vasterbotten/Rusfors
Registered: 2016-08-11
Posts: 1,513

Re: "[Solved]" Conky - AC Power Cord, Battery Script

lmart wrote:

Trying to write conky code to test when AC power cord is unplugged, then kick off a script to display battery status and, turn off when plugged into wall circuit.

In your last post, You wrote "resolved" and posted one line. So, what is the whole code?

When realy solved, please edit your first post, prepend "[Solved]" on the subjectline.


// Regards rbh

Please read before requesting help: Guide to getting help,
Introduction to the Bunsenlabs Lithium Desktop and other help topics under "Help Resources" on the BunsenLabs menu

Offline

#10 2022-03-23 17:35:51

lmart
Member
Registered: 2019-01-04
Posts: 22

Re: "[Solved]" Conky - AC Power Cord, Battery Script

thank you
will edit first post and, prepend "[Solved]" on the subject line
per my first post, "Trying to write conky code to test when AC power cord is unplugged", which the code segment posted addresses that issue; ${if_match ${acpiacadapter} == "off-line"}${color yellow}unplugged${color}${endif}\

previously posted battery code replaces ${color yellow}unplugged${color}

actual code from my conf follows:
${if_match ${acpiacadapter} == "off-line"}\
${if_existing /sys/class/power_supply/BAT0}\
${alignr}${battery_bar 8,70 BAT0}
${else}\
${if_existing /sys/class/power_supply/BAT1}\
${alignr}${battery_bar 8,70 BAT1}
${endif}${endif}${endif}\

Offline

#11 2022-03-23 20:52:25

lmart
Member
Registered: 2019-01-04
Posts: 22

Re: "[Solved]" Conky - AC Power Cord, Battery Script

Eating my words ...

this code segment does not work
${if_match ${acpiacadapter} == "off-line"}${color yellow}unplugged${color}${endif}\

nor does this code segment
${if_match ${acpiacadapter} == "on-line"}${color yellow}plugged${color}${endif}\

so, back to the basic question: does anyone have conky code to check the status of ac power cord, whether plugged or unplugged?

Offline

#12 2022-03-23 23:02:08

PackRat
jgmenu user Numero Uno
Registered: 2015-10-02
Posts: 1,605

Re: "[Solved]" Conky - AC Power Cord, Battery Script

^ No, acpiacadapter didn't even work on my laptop.

I was toying with this today since I sometimes like to see the battery info.

Try this in a terminal -

acpi -a

You should get something along the lines of:

Adapter 0: off-line

You can use awk to parse the status. Right now, I'm using:

${execpi 10 acpi -a | awk '/Adapter 0/ {print $3}'}

You may need to actually use a script and not conky variables to do what you want. I bet it's already been done. Ask your question in the main conky thread. That group has done pretty much everything.

Last edited by PackRat (2022-03-24 00:25:17)


You must unlearn what you have learned.
    -- yoda

Offline

#13 2022-03-23 23:25:48

lmart
Member
Registered: 2019-01-04
Posts: 22

Re: "[Solved]" Conky - AC Power Cord, Battery Script

Thanks,
Coming to the conclusion conky code is unable to accomplish the task of determining the status of the AC (unplugged or not).
Will try your code suggestion. Thanks.
Will try your suggestion of posting on the main board. Thanks.

Offline

#14 2022-03-24 13:51:46

lmart
Member
Registered: 2019-01-04
Posts: 22

Re: "[Solved]" Conky - AC Power Cord, Battery Script

PackRat wrote:

^ No, acpiacadapter didn't even work on my laptop.

I was toying with this today since I sometimes like to see the battery info.

Try this in a terminal -

acpi -a

You should get something along the lines of:

Adapter 0: off-line

You can use awk to parse the status. Right now, I'm using:

${execpi 10 acpi -a | awk '/Adapter 0/ {print $3}'}

You may need to actually use a script and not conky variables to do what you want. I bet it's already been done. Ask your question in the main conky thread. That group has done pretty much everything.


PackRat,

Thanks. Your code segment works and, is similar to my code using cat /sys/class/power_supply/AC/online, which returns 0 (off-line) or 1 (on-line).

${if_match ${execpi 10 acpi -a | awk '/Adapter 0/ {print $3}'}  == "on-line"}on-line${endif}

Interestingly, ${acpiacadapter} accurately displays the AC status; one-line or off-line. My continuing frustation is that I am unable to test against the results of ${acpiacadapter}.

Will give this post a day or two before marking it solved ...

Offline

#15 2022-03-24 22:41:19

lmart
Member
Registered: 2019-01-04
Posts: 22

Re: "[Solved]" Conky - AC Power Cord, Battery Script

PackRat

whoddathunk ... after weeks working on this AC Power (connected, disconnected) issue, success using only conky code ... finally "[Solved]"

Here's the code: ${if_existing /sys/class/power_supply/AC/online 0}${color white}AC is off-line${color}${endif}

When the AC is unplugged, the battery code (not supplied here) kicks off so that no work is lost!

refer to: http://www.ifxgroup.net/conky.htm

${if_existing file_name [string]

if_existing Arguments: file_name [string]
${if_existing ~/results.log "fail"}
${endif}

    If the named file exists show everything between "${if_existing}" and the matching "${endif}". The optional second parameter checks for file containing the specified string and prints everything between "${if_existing}" and the matching "${endif}".

Offline

Board footer

Powered by FluxBB