Simple arithmetic or kelvin to celsius method?

Forums Desktop Info Simple arithmetic or kelvin to celsius method?

This topic contains 7 replies, has 2 voices, and was last updated by Glenn Glenn 3 months, 4 weeks ago.

  • Author
    Posts
  • #1616 Reply
    Avatar
    cuttle

    Hi. I’m trying to get CPU temperature value using WMI query. Using this method I’m getting the temperature in Kelvins. I would prefer to see the result in Celsius. To achieve it I need to subtract 273,15 from the value I got using the query. Is there a way to do it?

    I use the following configuration string:
    WMI=active:1,interval:5,namespace:root\cimv2,query:Win32_PerfFormattedData_Counters_ThermalZoneInformation,display:%temperature%K,set:cputemp,text:cputemp

    0
  • #1626 Reply
    Glenn
    Glenn
    Keymaster

    Not right now. I’ll raise an issue and see if I can figure something out.

    0
  • #1646 Reply
    Glenn
    Glenn
    Keymaster

    I’m thinking something like this:

    Add a new option to the WMI item (and possibly others as required):

    evaluate:TemperatureC=%temperature%-273.15

    where:
    TemperatureC = declares a new user variable to contain the results of the evaluation.
    %temperature% = is a wmi return value.

    The whole expression is then evaluated and the result put in the declared user variable so you can then use it in the display option in the usual manner.

    evaluate:TemperatureC=%temperature%-273.15,display:%TemperatureC%

    It might be a useful addition to the TEXT item, for example:

    TEXT=active1,text:Cpu Temp,evaluate:TemperatureC=%cputemp%-273.15,display:%TemperatureC%C

    where %cputemp% was created previously in your WMI query above.

    perhaps in the SET item, I’ll have to figure out the syntax for that.

    • This reply was modified 4 months ago by Glenn Glenn.
    0
  • #1648 Reply
    Glenn
    Glenn
    Keymaster

    Here’s another thought.

    I’m thinking of using the display template formatting/transformation tools to do some simple on-the-fly arithmetic on a single return value/property. Say, something like this:

    display:%1[a:-273.15]

    where the value of %1 will be transformed using the given formula. In other words:

    %1-273.15

    So your original example might look like this:

    WMI=active:1,interval:5,namespace:root\cimv2,query:Win32_PerfFormattedData_Counters_ThermalZoneInformation,display:%temperature%[a:-273.15]C,set:cputemp,text:cputemp

    • This reply was modified 4 months ago by Glenn Glenn.
    0
  • #1650 Reply
    Avatar
    cuttle

    I like both solutions. Does the second solution permit to evaluate any equation in the brackets or just to correct the original value with + and – correction factor? The former seems a little complicated to implement, but the latter does not allow to see the temperature in Fahrenheit(for example).

    If I think about it, I actually don’t see many use cases, where user needs to change the output values arithmetically. Apart from the unit conversion of course. Most of the metrics provided by the WMI interface are already good enough. May be sometimes you need change Kb to Mb, but this part is already implemented. Then here comes the Kelvins thing. Well, it is official temperature unit in the international system of units, but who would use it in real life and why the wmi query result is in Kelvins? It is rather exception, because GPU temperature is given in good Celsius.

    So, my point is may be in this particular case it is enough to make a simple conversion option for temperature value, something like %temperature%[t:k-c], where “t” directs to use the formatting for the temperature and “k-c” converts Kelvins to Celsius.

    Of course, if it is too generous to write the code just to convert some temperature given in Kelvins, which might be the only one instance in the whole scope of WMI output values, then the suggested solutions are undoubtedly more universal.

    Anyway, thank you for your attention to this topic. I will appreciate any solution.

    0
    • #1651 Reply
      Glenn
      Glenn
      Keymaster

      I tend to agree. The idea of a simple k->c and k->f transform was my first thought. I think I will do that because it is simple to do and I’ll look at adding an expression evaluator later on if there’s any demand for it.

      So there are currently byte transformations: b B k K m M g G t T
      to transform bytes into kilobytes or whatever which look like this:

      [1.0k] [3.1M] etc…..

      I’ll add two new transforms: C F
      which will assume the property is Kelvin and do the conversion to Celsius and Fahrenheit respectively. So something like this:

      display:%temperature%[1.1C]
      or
      display:%temperature%[1.0F]

      These will be floating point transforms so you can format them the same as the floating point (lower case f) transform.

      • This reply was modified 4 months ago by Glenn Glenn.
      0
  • #1657 Reply
    Glenn
    Glenn
    Keymaster

    I notice root\cimv2, Win32_PerfFormattedData_Counters_ThermalZoneInformation is in degrees Kelvin while root\wmi, MSAcpi_ThermalZoneTemperature is in tenths of degrees Kelvin, Win32_TemperatureProbe is tenths of degrees Centigrade.

    Hurrah for Microsoft to endlessly complicate things.

    • This reply was modified 4 months ago by Glenn Glenn.
    0
  • #1670 Reply
    Glenn
    Glenn
    Keymaster

    Given that the above is such an edge case, I’ve elected to implement the expression evaluator, except that it will be done completely within the display template with access to all the return values and reasonable arithmetic functionality.

    Let’s take the example from your original post:

    WMI=active:1,interval:5,namespace:root\cimv2,query:Win32_PerfFormattedData_Counters_ThermalZoneInformation,display:%temperature%K,set:cputemp,text:cputemp

    drop the ‘set’ option and change the display template:

    WMI=active:1,interval:5,namespace:root\cimv2,query:Win32_PerfFormattedData_Counters_ThermalZoneInformation,text:Cpu Temp,display:{{1.0d:%Temperature%-273.15}} Celsius

    That’s all there is to it. The first bit is the number format, followed by the expression to be evaluated, which includes the wmi return value.

    0
Reply To: Simple arithmetic or kelvin to celsius method?
Your information:




Do NOT follow this link or you will be banned from the site!