Fandom

Conky Wiki

Battery threshold (Lua)

13pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Battery threshold exampleEdit

This Lua script will execute the system 'beep' command when the battery value drops below a certain threshold. Use it like so (beeps when battery goes below 6%):

${lua_read_parse bat_warn 5 ${battery_percent BAT0}}

The ScriptEdit

--
-- Lua scripting example to alert the user when battery percentage
-- goes below some threshold
--
-- usage in conky:
-- ${lua_read_parse bat_warn <alert_perc> ${battery_percent <battery>}}
--
-- Example: alert when BAT0 goes below 6 percent:
-- ${lua_read_parse bat_warn 5 ${battery_percent BAT0}}
--

local user_alerted = false
function conky_bat_warn(str)
	local alert_percent, percent = string.match(str, '^(%d+) (%d+)$')

	if percent <= alert_percent and not user_alerted then
		-- alert the user, put your command here
		os.execute('beep')

		user_alerted = true
	end

	-- reset alert if battery percentage goes above alert level
	if percent > alert_percent and user_alerted then
		user_alerted = false
	end

	-- display nothing in conky itself so returning empty string
	return ''
end

Also on Fandom

Random Wiki