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

		user_alerted = true

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

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