Epson Expression Inket printer using HTTP Binding

While learning the new OH3 HTTP Binding I have managed to pull some of the details across from my Epson XP-352 printer web UI and thought it might be of use to others.

I expect it would work for other Epson Expression printers. Feedback good or bad appricated. Enjoy :slight_smile:

epson.things

Thing http:url:epson352 [ 
        baseURL="http://X.X.X.X/PRESENTATION/HTML/TOP/PRTINFO.HTML", 
        refresh=300,
        commandMethod="GET" ] 
{
// Other local URLs that could be used for additional details
// http://X.X.X.X/PRESENTATION/ADVANCED/INFO_PRTINFO/TOP
// http://X.X.X.X/PRESENTATION/ADVANCED/INFO_NWINFO/TOP
    
    Channels:    
       Type string : status           [ mode = "READONLY", stateTransformation = "REGEX:.*PRTSCN_STATUS.+?ce\">(.*?)<\\/div>.*" ]
       Type number : inkLevelC        [ mode = "READONLY", stateTransformation = "REGEX:.*Ink_C.+?='(.*?)'.*" ]
       Type number : inkLevelM        [ mode = "READONLY", stateTransformation = "REGEX:.*Ink_M.+?='(.*?)'.*" ]
       Type number : inkLevelY        [ mode = "READONLY", stateTransformation = "REGEX:.*Ink_Y.+?='(.*?)'.*" ]
       Type number : inkLevelK        [ mode = "READONLY", stateTransformation = "REGEX:.*Ink_K.+?='(.*?)'.*" ]
       Type string : deviceName       [ mode = "READONLY", stateTransformation = "REGEX:.*Device Name.+?\">(.*?)<\\/td>.*" ]
       Type string : connectionStatus [ mode = "READONLY", stateTransformation = "REGEX:.*Connection Status.+?\">(.*?)<\\/td>.*" ]
       Type string : signalStrength   [ mode = "READONLY", stateTransformation = "REGEX:.*Signal Strength.+?\">(.*?)<\\/td>.*" ]
       Type string : macAddress       [ mode = "READONLY", stateTransformation = "REGEX:.*MAC Address.+?\">(.*?)<\\/td>.*" ]
       Type string : ipAddress        [ mode = "READONLY", stateTransformation = "REGEX:.*IP Address.+?\">(.*?)<\\/td>.*" ]
       // There is a lot more network information that could be scraped from the prtinfo.html page if requred.     
}

epson.items

String   Epson352Status           "Status [%s]"              <status>   {channel="http:url:epson352:status", expire="301s,state=Offline"}
Number   Epson352InkLevelC        "Cyan Ink Level [%.0f/50]"    <rgb>   {channel="http:url:epson352:inkLevelC"}
Number   Epson352InkLevelM        "Magenta Ink Level [%.0f/50]" <rgb>   {channel="http:url:epson352:inkLevelM"}
Number   Epson352InkLevelY        "Yellow Ink Level [%.0f/50]"  <rgb>   {channel="http:url:epson352:inkLevelY"}
Number   Epson352InkLevelK        "Black Ink Level [%.0f/50]"   <rgb>   {channel="http:url:epson352:inkLevelK"}
String   Epson352DeviceName       "Device name [%s]"         <keyring>  {channel="http:url:epson352:deviceName"}
String   Epson352ConnectionStatus "Connection status [%s]"   <network>  {channel="http:url:epson352:connectionStatus", expire="301s,state=Offline"}
String   Epson352SignalStrength   "Signal Strength [%s]" <qualityofservice> {channel="http:url:epson352:signalStrength", expire="301s,state=Offline"}
String   Epson352IpAddress       "IP address [%s]"         <network>  {channel="http:url:epson352:ipAddress"}
String   Epson352MacAddress       "MAC address [%s]"         <network>  {channel="http:url:epson352:macAddress"}

DateTime Epson352LastUpdated "Last updated [%1$td/%1$tm/%1$ty %1$tH:%1$tM]" <time> {channel="http:url:epson352:status" [profile="timestamp-update"] }

.sitemap

Frame label="Printer" {
 Default item=Epson352Status
 Slider item=Epson352InkLevelC maxValue=50
 Slider item=Epson352InkLevelM maxValue=50
 Slider item=Epson352InkLevelY maxValue=50
 Slider item=Epson352InkLevelK maxValue=50 
 Default item=Epson352DeviceName
 Default item=Epson352ConnectionStatus  
 Default item=Epson352SignalStrength 
 Default item=Epson352IpAddress 
 Default item=Epson352MacAddress 
 Default item=Epson352LastUpdated   			
}		
2 Likes

Exactly what im looking for!

I use it with Pushover to inform about collorlevel at low level…

refresh=300 mean 5 Minutes?

This is realy nice!
I already managed to grab the ink levels (most important), but I’m struggeling with the other things.
eg, the device name

<td class="item-key"><bdi>Device Name</bdi>&nbsp;:</td>
<td class="item-value">EPSON2CD0CB</td>

I don’t get any vaues with this transformation:
REGEX:.*Device Name.+?\">(.*?)<\\/td>.*

300 seconds indeed

Hi,

I do’nt realy understand that REGEX ?\">(.*?)<\\/td>.* hieroglyph :rofl:. My Epson have 2 black cartridges and i did’nt get it with REGEX.

When i’m home i will show my solution…

ok, my HTML looks like this. Because it includes 2times “/Ink_K.PNG” i had problems using REGEX

<li class='tank'>
<div class='tank'>
<img class='color' src='../../IMAGE/Ink_K.PNG' height='3' style=''>
</div>
<div class='clrname'>BK</div>
</li><!--
--><li class='tank'>
<div class='tank'>
<img class='color' src='../../IMAGE/Ink_C.PNG' height='2' style=''>
<img class='inkst' src='../../IMAGE/Icn_low.PNG' height='22' width='22'>
</div>
<div class='clrname'>C</div>
</li><!--
--><li class='tank'>
<div class='tank'>
<img class='color' src='../../IMAGE/Ink_Y.PNG' height='4' style=''>
</div>
<div class='clrname'>Y</div>
</li><!--
--><li class='tank'>
<div class='tank'>
<img class='color' src='../../IMAGE/Ink_M.PNG' height='4' style=''>
</div>
<div class='clrname'>M</div>
</li><!--
--><li class='tank'>
<div class='tank'>
<img class='color' src='../../IMAGE/Ink_K.PNG' height='5' style=''>
</div>
<div class='clrname'>PBK</div>
</li>

what have i done… using JS!
For evey Item i put a little FILE.JS in transform Folder.

to get Black epsonBK.js

(function(html) {
    return html.split("Ink_K.PNG' height='")[1].split("'")[0] * 2; 
})(input)

to get PhotoBlack epsonPBK.js

(function(html) {
    return html.split("Ink_K.PNG' height='")[2].split("'")[0] * 2;  
})(input)

Because of “DeviceName”
my html looks like this, language depending its “Printer Name”
for engl → baseURL=“http://xxx.xxx.xxx.xxx/PRESENTATION/HTML/TOP/PRTINFO.HTML?SEL_LANGB=1”,

<table style="border-collapse: collapse; width: 100%;">
<tr class="item clearfix"><td class="item-key"><bdi>Printer Name</bdi>&nbsp;:</td><td class="item-value">EPSON8130AB</td></tr>
<tr class="item clearfix"><td class="item-key"><bdi>Connection Status</bdi>&nbsp;:</td><td class="item-value">100BASE-TX Full Duplex</td></tr>
<tr class="item clearfix"><td class="item-key"><bdi>Obtain IP Address</bdi>&nbsp;:</td><td class="item-value">Auto</td></tr>
<tr class="item clearfix"><td class="item-key"><bdi>IP Address</bdi>&nbsp;:</td><td class="item-value">192.168.188.26</td></tr>
<tr class="item clearfix"><td class="item-key"><bdi>Subnet Mask</bdi>&nbsp;:</td><td class="item-value">255.255.255.0</td></tr>
<tr class="item clearfix"><td class="item-key"><bdi>Default Gateway</bdi>&nbsp;:</td><td class="item-value">192.168.188.1</td></tr>
<tr class="item clearfix"><td class="item-key"><bdi>DNS Server Setting</bdi>&nbsp;:</td><td class="item-value">Auto</td></tr>
<tr class="item clearfix"><td class="item-key"><bdi>Primary DNS Server</bdi>&nbsp;:</td><td class="item-value">192.168.188.1</td></tr>
<tr class="item clearfix"><td class="item-key"><bdi>Secondary DNS Server</bdi>&nbsp;:</td><td class="item-value">&nbsp;</td></tr>
<tr class="item clearfix"><td class="item-key"><bdi>Proxy Server</bdi>&nbsp;:</td><td class="item-value">Do Not Use
</td></tr>
<tr class="item clearfix"><td class="item-key"><bdi>File Sharing</bdi>&nbsp;:</td><td class="item-value">Enable</td></tr>
<tr class="item clearfix"><td class="item-key"><bdi>File Sharing Mode</bdi>&nbsp;:</td><td class="item-value">Read/Write</td></tr>
<tr class="item-last clearfix"><td class="item-key"><bdi>MAC Address</bdi>&nbsp;:</td><td class="item-value">9C:AE:D3:81:30:AB</td></tr>
</table>

and JS for DeviceName is epsonName.js

(function(html) {
    return html.split("<bdi>Printer Name</bdi>")[1].split("item-value")[1].split(">")[1].split("<")[0] ; 
})(input)

the File.things

Thing http:url:epson [ 
        baseURL="http://xxx.xxx.xxx.xxx/PRESENTATION/HTML/TOP/PRTINFO.HTML?SEL_LANGB=1", 
        refresh=280,
        commandMethod="GET" ] 
{
// Other local URLs that could be used for additional details
// http://X.X.X.X/PRESENTATION/ADVANCED/INFO_PRTINFO/TOP
// http://X.X.X.X/PRESENTATION/ADVANCED/INFO_NWINFO/TOP
    
    Channels:    
       Type number : inkLevelC		[ mode = "READONLY", stateTransformation = "JS:epsonC.js" ]
       Type number : inkLevelM      [ mode = "READONLY", stateTransformation = "JS:epsonM.js" ]
       Type number : inkLevelY      [ mode = "READONLY", stateTransformation = "JS:epsonY.js" ]
       Type number : inkLevelBK     [ mode = "READONLY", stateTransformation = "JS:epsonBK.js" ] 
	   Type number : inkLevelPBK    [ mode = "READONLY", stateTransformation = "JS:epsonPBK.js" ]
       Type string : deviceName     [ mode = "READONLY", stateTransformation = "JS:epsonName.js" ]
//       Type string : connectionStatus [ mode = "READONLY", stateTransformation = "REGEX:.*Connection Status.+?\">(.*?)<\\/td>.*" ]
//       Type string : signalStrength   [ mode = "READONLY", stateTransformation = "REGEX:.*Signal Strength.+?\">(.*?)<\\/td>.*" ]
//       Type string : macAddress       [ mode = "READONLY", stateTransformation = "REGEX:.*MAC Address.+?\">(.*?)<\\/td>.*" ]
//       Type string : ipAddress        [ mode = "READONLY", stateTransformation = "REGEX:.*IP Address.+?\">(.*?)<\\/td>.*" ]
       // There is a lot more network information that could be scraped from the prtinfo.html page if requred.     
}

just works…