Because i hate standby usage of devices, especially when not using them because we're not home/sleeping, i have some 'standby-killing' switches in Domoticz.
The printerserver is behind a KaKu switch which is controlled by Domoticz (turned on from 6:30 - 23:00 when there is someone home, otherwise off).
The printer is turned on/off by hand (we don't print very often, so don't want it being on the whole day, only turn it on after we have hit the 'Print' button, page is cached by printerserver until it is printed by the printer).
When we go to bed we activate the 'sleeping' sequence on Domoticz, and the printerserver is being turned off. However, sometimes after printing we forget to turn off the printer itself and the printer is standby for the whole night. A waste of energy in my opinion. I created a little script that fetches the device status of the printerserver webpage. This script is being called when we activate the sleeping sequence in Domoticz and sends me a pushmessage to turn off the printer.
Code: Select all
#!/bin/bash
#ip='$1'
string="Device Not Attached"
ping -c 1 $1 >/dev/null 2>&1
if [ $? -ne 0 ] ; then #if ping exits nonzero...
echo "Printerserver not responding to ping"
else
echo "Printerserver responds to ping"
if curl -s "http://"$1"/index_info.htm" | grep -q "$string"; then
echo "Printer is turned off"
else
echo "Printer is still on, please turn off"
fi
fi
Code: Select all
sh /home/pi/printer/printer.sh 192.168.4.2
I could also place a KaKu-plug between the printer itself and turn it on when needed, and automatically turn off when we go to sleep. However this is easier to understand for my girlfriend. And i like fiddling around with creating scripts and such

Scraping other info
The info returned by the webpage of my printerserver is very minimalistic. But most other networkprinters also report toner level and such. For example: you could modify this script to read the amount of toner and store it in a virtual Domoticz sensor (percentage/text) and/or send you a message when the toner is low.
To retrieve the status text (to display in a Domoticz text sensor for example) you could use something like this:
Code: Select all
curl -s "http://192.168.4.2/index_info.htm"|grep -Po '<td\s+class="if">\K.*?(?=</td>)'
Code: Select all
<td class="if">Device Not Attached</td>