2

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.

Paul Kulchenko
  • 25,884
  • 3
  • 38
  • 56
Moltke
  • 35
  • 4

2 Answers2

3

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)
Paul Kulchenko
  • 25,884
  • 3
  • 38
  • 56
  • Thanks for yur answer. I tried your suggestion but then no values are shown. Check in here: https://imgur.com/FSvnzyY – Moltke Sep 09 '18 at 03:24
  • it seems like the callback takes two parameters instead of one and there was space missing between `cat` and the filename, so I updated the example to fix both. If it still doesn't work, show the content of `temp1_input` file. – Paul Kulchenko Sep 09 '18 at 03:31
  • Same result; no temp values are shown. The content of temp1_input is a number, right now is 43000 and if close and open again it's another higher or lower one. Thanks for your answer. – Moltke Sep 09 '18 at 03:41
  • Ok, updated the example with setting the explicit value for the widget. – Paul Kulchenko Sep 09 '18 at 04:08
  • 1
    You can also try `("%d°C"):format(tonumber(s)/1000)` if you want to show `40°C`. – Paul Kulchenko Sep 09 '18 at 04:50
  • and that would go right after widget:set_text? Ok, I tried and it shows the %d instead of numbers, I copied/pasted, excuse my ignorance but how do I fix it? – Moltke Sep 09 '18 at 05:00
  • It should look like `widget:set_text(("%d°C"):format(tonumber(s)/1000))`. – Paul Kulchenko Sep 09 '18 at 16:17
0

Just use sensors, it is easier. I achieved this by creating a widget that updates to the value of sensors:

local wibox = require("wibox")
local awful = require("awful")

local temprature = wibox.widget {
    widget = awful.widget.watch('bash -c "sensors | grep CPU |     awk \'{print $2}\' | se
d \'s/C/C   /\'"', 5),
}

local temprature_clr = wibox.widget.background()
temprature_clr:set_widget(temprature)
temprature_clr:set_fg("#e5a75b")

return temprature_clr
TechTycho
  • 134
  • 1
  • 10