Dynamic Page Viewer: Working Solution A

Posted on
Sat Mar 11, 2017 8:14 am
whmoorejr offline
User avatar
Posts: 762
Joined: Jan 15, 2013
Location: Houston, TX

Dynamic Page Viewer: Working Solution A

This provides a way to view different control pages within a control page as a refreshing image URL. It’s not the cleanest approach and since the background logic is written in python, I’m sure someone could pick up the ball and turn this into a plugin.

When you are done, you will be able to create an action that will call up an image of a control page. You could have triggers that bring out different control pages.

My usage: I have one main home control page. It is a white on black floor plan of my home with all the lights, outlets, etc all over it.

For security, I have triggers that go off when motion is detected that capture a camera image and save in a desktop folder with the name “R.jpg” <- for rotation image.

When motion is detected, a 1 minute timer starts (or restarts), a camera snapshot is taken and saved as “R.jpg”. When the timer expires, another action fires to take a screenshot of my main control page and save it as “R.jpg” and restart the timer. If not motion is detected within that minute, the page is refreshed with an updated screenshot of the main control page.

Because there is a bunch of applescript making this happen, it’s a little slow… about 5 seconds between capturing the image and saving as “R.jpg.” (for the control page, the camera images are quicker) If I need a more “updated” view, the client action for the Refreshing Image URL takes me to the main control page where I can see it all live and turn on/off lights.

How I did it:

Step 1: Download / Install webkit2png www.paulhammond.org/webkit2png

This will allow you to grab a screen shot of whatever without messing with opening a browser window.

some variables you will need to be familiar with:
-T = thumbnail (you will probably want a smaller files size version of your control page to speed up the process. Default size is a little to small for my taste… so,

-s = scale. I used .3 = 30%

-D = destination (where to save the image)

-o = filename to save as. Note, it adds “Thumb” or “Full” to the end of it.

Step 2: I used script editor to make the following applescript and save as “Grab.scpt”

Code: Select all
do shell script “/usr/local/bin/webkit2png -T -s .3 -o ISL -D ~/Desktop http://10.0.6.10/controlpage?name=ISLFloorPlanLS”


(Substitute variables where you need to in above)

Step 3: Create an action command
first part: Execute Script File (select the one you just wrote in Step 2)
second part: Execute Script (Embeded Applescript) with a 6 second delay

Code: Select all
property outputPNGFN : "Users:williammoore:Desktop:IPCamRotate:R.jpg"
property noMotionFN : "Users:williammoore:Desktop:ISL-thumb.png"
property targetSize : 256

on run
   my outputPlaceholderImage(noMotionFN)
end run
to outputPlaceholderImage(filename)
   set outputFileHandle to (open for access (outputPNGFN as alias) with write permission)
   try
      write (read (filename as alias)) to outputFileHandle starting at 0
      close access outputFileHandle
   on error err_msg
      close access outputFileHandle
   end try
end outputPlaceholderImage


substitute variables in the first two lines to work with your file’s locations and names.

Done. Now use triggers or whatever to change out the “R.jpg” image whenever you want to and

Step 4: Set your refreshing image to:

File:///Users/williammoore/Desktop/IPCamRotate/R.jpg


I’m working with a couple folks to see if I can come up with a solution that is less applescript and more python to see I have better results. That will take me some time because I have never written a python script that has worked. If I get a working python version or something similar, I'll post it as a different working solution.

Bill
My Plugin: My People

Posted on
Sat Mar 11, 2017 8:52 am
whmoorejr offline
User avatar
Posts: 762
Joined: Jan 15, 2013
Location: Houston, TX

Re: Dynamic Page Viewer: Working Solution A

Step 2 Substitute (One less applescript thing)

Use embedded Python (Thanks to Jon "autolog" for the script)

Code: Select all
import subprocess as sub
try:
    p = sub.Popen(['/usr/local/Cellar/webkit2png/0.7/bin/webkit2png', '-T', 'http://10.0.6.10:8176/controlpage?name=ISLFloorPlanLS', '-D', '/Users/<YOUR USERNAME>/Desktop', '-s', '.5', '-o', 'ISL'],stdout=sub.PIPE,stderr=sub.PIPE)
    output, errors = p.communicate()
    errorMsg = ''
    if errors != '':
        errorMsg = 'Error Detected with webkit2png : %s' % errors
    indigo.server.log('WEBKIT2PNG: %s\n%s' % (output, errorMsg))
except OSError, e:
    indigo.server.log('OSError invoking webkit2png: %s' % e)


again, substitute out the address for your control page and what you want to name it and it should work for you too. :-)

Bill
My Plugin: My People

Posted on
Mon Mar 20, 2017 11:27 am
bkmar1192 offline
Posts: 274
Joined: Sep 12, 2015

Re: Dynamic Page Viewer: Working Solution A

I just posted an update to Security Camera that can access a local file as a "camera". You should be able to create a new camera and point it at the file that is created with webkitpng. Security Camera can then manage all your of the thumbnails, image switching, etc.


Sent from my iPhone using Tapatalk

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests