Read CPU and pass to MySensors LCD

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
User avatar
EdddieN
Posts: 510
Joined: Wednesday 16 November 2016 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Location: Scotland
Contact:

Read CPU and pass to MySensors LCD

Post 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 707 times
11101101 - www.machinon.com
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Read CPU and pass to MySensors LCD

Post 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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
EdddieN
Posts: 510
Joined: Wednesday 16 November 2016 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Location: Scotland
Contact:

Re: Read CPU and pass to MySensors LCD

Post 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.
11101101 - www.machinon.com
User avatar
EdddieN
Posts: 510
Joined: Wednesday 16 November 2016 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Location: Scotland
Contact:

Re: Read CPU and pass to MySensors LCD

Post 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
}
11101101 - www.machinon.com
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest