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

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
DutchSolar
Posts: 10
Joined: Sunday 23 August 2015 20:43
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Contact:

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

Post 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!
twoenter
Posts: 76
Joined: Sunday 17 February 2019 15:01
Target OS: NAS (Synology & others)
Domoticz version: 4.10
Contact:

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

Post 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/
Check my Domoticz tutorials, ESP8266 and Synology blog at https://www.twoenter.nl/blog
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
DutchSolar
Posts: 10
Joined: Sunday 23 August 2015 20:43
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Contact:

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

Post by DutchSolar »

Thank you both for the reply!
Really appreciated. Ill let you know the outcome :)
DutchSolar
Posts: 10
Joined: Sunday 23 August 2015 20:43
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Contact:

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

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest