Page 1 of 1

Read CPU and pass to MySensors LCD

Posted: Sunday 13 January 2019 20:07
by EdddieN
Hello,

I'm trying to do this in dzVents:

Code: Select all

--[[
Domoticz dzVents script for Machinon LCD

Displays the device's Ethernet IP (either DHCP or static) on Machinon LCD using a shell script to get the local IP (or "unknown" if disconnected)

Also shows static info for Kit
]]

return {
    -- trigger
    -- can be a combination:
    on = {

        -- timer riggers
        timer = {
            -- timer triggers.. if one matches with the current time then the script is executed
            -- 1 minute is shortest interval and also the timer granularity???
            'every 1 minutes'
        }
    },

    -- custom logging level for this script
    logging = {
       level = domoticz.LOG_DEBUG,
       marker = "show-ip script"
   },

    -- actual event code
    -- the second parameter is depending on the trigger
    -- when it is a device change, the second parameter is the device object
    -- similar for variables, scenes and groups and httpResponses
    -- inspect the type like: triggeredItem.isDevice
    execute = function(domoticz)
       domoticz.log('Running show-ip script...', domoticz.LOG_INFO)

       local cmd = "/home/pi/domoticz/scripts/machinon-tools/get-ip.sh"
       local f = assert(io.popen(cmd, 'r'))
       local s = assert(f:read('*a'))
       f:close()
       -- strip out any /r/n etc
       s = string.gsub(s, '^%s+', '')
       s = string.gsub(s, '%s+$', '')
       s = string.gsub(s, '[\n\r]+', '')
       
       local CPUtemp = (domoticz.devices('CPU temp').temperature)
       local CPUusage = (domoticz.devices('CPU_Usage').level)
       
       domoticz.log('Got IP = "' .. s .. '"', domoticz.LOG_INFO)
       domoticz.log('CPU Temp = "' .. CPUtemp .. '"', domoticz.LOG_INFO)
       domoticz.log('CPU % = "' .. CPUusage .. '"', domoticz.LOG_INFO)
        
        domoticz.devices('LCD Line 3').updateText('IP = ' .. s)
        domoticz.devices('LCD Line 4').updateText('CPU = ' .. CPUtemp .. '°C')
        domoticz.devices('LCD Line 5').updateText('CPU = ' .. s .. '"%"')
       
       -- also update static info in case it gets corrupted/overwriten   
       --domoticz.devices('LCD Backlight').switchOn()

    end
}
But the log file returns:
2019-01-13 19:03:00.667 Status: dzVents: Info: show-ip script: Got IP = "172.16.1.250"
2019-01-13 19:03:00.667 Status: dzVents: Info: show-ip script: CPU Temp = "50.5"
2019-01-13 19:03:00.667 Status: dzVents: Info: show-ip script: CPU % = "nil"
How do I read the CPU %?
Attached image of what I'm trying to do:
IMG_2515.jpg
IMG_2515.jpg (118.84 KiB) Viewed 709 times

Re: Read CPU and pass to MySensors LCD

Posted: Sunday 13 January 2019 22:11
by waaren
EdddieN wrote: Sunday 13 January 2019 20:07 Hello,

I'm trying to do this in dzVents:
[
Howto depends on the method you choose to get this value in a device: What do you (want to) use ?

Re: Read CPU and pass to MySensors LCD

Posted: Sunday 13 January 2019 23:14
by EdddieN
Ah! Sorry forgot to mention that.

I'm using the hardware: motherboard sensors from Domoticz hardware. I got the CPU % on domoticz, just want to read it on dzVents as the wiki only refers to % as a level. Tried that but didn't work.

Re: Read CPU and pass to MySensors LCD

Posted: Monday 14 January 2019 22:32
by EdddieN
Got it, this:

Code: Select all

--[[
Domoticz dzVents Lua script for Machinon LCD

Displays CPU temp and load (from "Motherboard Sensors") on Machinon LCD whenever either is updated.

Change the device names to match your actual devices.
]]

return {
    on = {
        devices = {
            'CPU temp', 'CPU Usage'
        }
    },
    execute = function(domoticz, device)
        local cpu_temp = tostring(string.format("%4.1f",domoticz.devices('CPU temp').temperature))
        local cpu_usage = tostring(string.format("%4.1f",domoticz.devices('CPU Usage').percentage))
        
        domoticz.devices('LCD Line 3').updateText('CPU Temp = ' .. cpu_temp .. 'C')
        domoticz.devices('LCD Line 4').updateText('CPU Load = ' ..  cpu_usage .. '%')
    end
}