Page 1 of 1

Alert when device has been online for x amount of time (reverse System Alive Checker)

Posted: Wednesday 02 September 2020 12:26
by DutchSolar
Hi,
I have 2 rather big laser printers at home (1 black and white and 1 color).
These where left overs from some projects years ago and since we have the room for them and toner does not spoil or dry out, I took them home.
I have set them up behind a KaKu switch each so if you want to print, you turn on the printer via Domoticz, wait 1 minute and you are ready to print. When you switch a printer on through Domoticz, I have set up a message through Telegram to remind you to also turn of the printer again. When turning of a printer, you also get a message. I mainly did this to prevent those printers from being powered up all the time and leeching electricity.
This has been working for years and I am quite happy about this.

I would however like to fine-tune this solution by somehow monitoring (pinging) the IP's of the printers and sending a message every 10 minutes when the IP is up.
Domoticz has System Alive Checker built in, but that only reports when a device is down, I am looking for the opposite.

Any help greatly appreciated!

Re: Alert when device has been online for x amount of time (reverse System Alive Checker)

Posted: Wednesday 02 September 2020 21:22
by twoenter
You can use my ping script. Just add some code to send the notification when it's online.

See my blog

https://www.twoenter.nl/blog/domoticz/p ... -domoticz/

Re: Alert when device has been online for x amount of time (reverse System Alive Checker)

Posted: Wednesday 02 September 2020 22:38
by waaren
DutchSolar wrote: Wednesday 02 September 2020 12:26 Domoticz has System Alive Checker built in, but that only reports when a device is down, I am looking for the opposite.
Any help greatly appreciated!
Below dzVents script will notify you every 10 minutes for as long as the printer reacts to a ping

When not yet familiar with dzVents please start with reading Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents enabled' is checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."

Code: Select all

--[[
    pingAlive.lua
]]--

 return
 {
         on =
         {
             timer =
             {
                'every 10 minutes',
             },
        },

        logging =
        {
            level   = domoticz.LOG_DEBUG ,              -- Change to ERROR when script is behaving as expected
            marker  = 'pinger',                              -- Will be set in execute = function block
        },

    execute = function(dz)

       local printers = 
       {
            ['printer1'] = '192.168.192.116', 
            ['printer2'] = '192.168.193.1',
       }
       
       local function osCommand(cmd)
            dz.log('Executing Command: ' .. cmd,dz.LOG_DEBUG)

            local fileHandle = assert(io.popen(cmd))
            local commandOutput = assert(fileHandle:read('*a'))
            local returnTable = {fileHandle:close()}

            return commandOutput,returnTable[3] -- rc[3] contains returnCode
        end

        for name, ip in pairs(printers) do
            local result, returnCode = osCommand('ping -c 1 -w 2 ' .. ip)
            if returnCode == 0 then
               dz.notify('checkPrinter','Printer ' .. name .. ' is responding to ping')
            end
        end
    
    end
}

Re: Alert when device has been online for x amount of time (reverse System Alive Checker)

Posted: Thursday 03 September 2020 8:49
by DutchSolar
Thank you both for the reply!
Really appreciated. Ill let you know the outcome :)

Re: Alert when device has been online for x amount of time (reverse System Alive Checker)

Posted: Monday 09 November 2020 12:19
by DutchSolar
waaren wrote: Wednesday 02 September 2020 22:38
DutchSolar wrote: Wednesday 02 September 2020 12:26 Domoticz has System Alive Checker built in, but that only reports when a device is down, I am looking for the opposite.
Any help greatly appreciated!
Below dzVents script will notify you every 10 minutes for as long as the printer reacts to a ping

When not yet familiar with dzVents please start with reading Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents enabled' is checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."

Code: Select all

--[[
    pingAlive.lua
]]--

 return
 {
         on =
         {
             timer =
             {
                'every 10 minutes',
             },
        },

        logging =
        {
            level   = domoticz.LOG_DEBUG ,              -- Change to ERROR when script is behaving as expected
            marker  = 'pinger',                              -- Will be set in execute = function block
        },

    execute = function(dz)

       local printers = 
       {
            ['printer1'] = '192.168.192.116', 
            ['printer2'] = '192.168.193.1',
       }
       
       local function osCommand(cmd)
            dz.log('Executing Command: ' .. cmd,dz.LOG_DEBUG)

            local fileHandle = assert(io.popen(cmd))
            local commandOutput = assert(fileHandle:read('*a'))
            local returnTable = {fileHandle:close()}

            return commandOutput,returnTable[3] -- rc[3] contains returnCode
        end

        for name, ip in pairs(printers) do
            local result, returnCode = osCommand('ping -c 1 -w 2 ' .. ip)
            if returnCode == 0 then
               dz.notify('checkPrinter','Printer ' .. name .. ' is responding to ping')
            end
        end
    
    end
}
It has been a while, sorry for that.
This script works beautifully!
Thanks.