Search code examples
luawidgetawesome-wm

cpu temp widget in awesome wm


I recently started using awesome wm version 4.2 and really like it; has significantly improved my workflow. I tried some themes like copycats and others but they're too fancy for me. I like the default configuration and been reading here: https://awesomewm.org/apidoc/index.html as well the rc.lua and theme.lua files from copycats and others and have implemented some of those; keybindings, layout manipulation, startup programs. I wanted to create a widget showing cpu temp, and I made it following intructions from here https://awesomewm.org/apidoc/classes/awful.widget.watch.html like this:

wibox.widget.textbox('  |  '),
awful.widget.watch(
  'bash -c "cat/sys/class/hwmon/hwmon0/device/temp1_input"', 15),
wibox.widget.textbox('  |  '),
awful.widget.watch(
  'bash -c "cat /sys/class/hwmon/hwmon0/device/temp3_input"', 15),

It works, but it shows big numbers i.e 43000 instead of 43. How can I change that? and if possible 43°C.


Solution

  • If you get the correct number and just want to divide it by 1000, you can use the optional callback:

    awful.widget.watch('bash -c "cat /sys/class/hwmon/hwmon0/device/temp1_input"', 15, 
      function(widget, s) widget:set_text(tonumber(s)/1000) end)