Capture Indigo Log entries to variable

Posted on
Mon Feb 27, 2023 11:02 am
Different Computers offline
User avatar
Posts: 2541
Joined: Jan 02, 2016
Location: East Coast

Capture Indigo Log entries to variable

I had this working at one time and still have the three variables in my setup, but at least since 2022.2, they've stopped being updated. I've tried searching but even as restrictive a search here as I can come up with has 28 pages of results and nothing in the first 14 that addresses the topic.

The idea was that the last three lines of the Indigo log are constantly being populated into three Indigo variables.

Was this a script maybe that used "tail"?

If anyone can point out the forum post where this was explained, I'd be grateful. While SQL Logger is sort of working, it seems like conditions about a variable may work better for me.

Thanks!

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Mon Feb 27, 2023 11:53 am
Different Computers offline
User avatar
Posts: 2541
Joined: Jan 02, 2016
Location: East Coast

Re: Capture Indigo Log entries to variable

Found it, though it needs some updating

viewtopic.php?f=4&t=6057&hilit=log+tail&start=30

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Mon Feb 27, 2023 12:06 pm
Different Computers offline
User avatar
Posts: 2541
Joined: Jan 02, 2016
Location: East Coast

Re: Capture Indigo Log entries to variable

for anyone who might want to put log entries into variables, here's the script I'm using now, triggered by SQL Logger plugin on errors.

Code: Select all
import sys
import collections
import re

def tail(iterable, N):
    deq = collections.deque()
    for thing in iterable:
        if len(deq) >= N:
            deq.popleft()
        deq.append(thing)
    return list(deq)

# A list of the variable IDs - this script doesn't create them so they have to exist already
variable_ids = [1, 2, 3]

lines = tail(open(f"{indigo.server.getInstallFolderPath()}/Logs/indigo_log.txt", encoding='utf-8'), len(variable_ids))
for index, line in enumerate(lines):
    if re.match(r'^[0-9]{4}\-[0-9]{2}\-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}', line):
        line = "\t".join(line.split("\t")[1:])
    if index < min(len(variable_ids), len(lines)):
        indigo.variable.updateValue(variable_ids[index], value=line)

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Mon Feb 27, 2023 2:54 pm
jay (support) offline
Site Admin
User avatar
Posts: 18212
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Capture Indigo Log entries to variable

Hey, can you restate exactly what you want (with specifics on formats, data elements, etc)? I suspect there's a better way, but having it completely outlines might help to determine that.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Feb 27, 2023 4:27 pm
Different Computers offline
User avatar
Posts: 2541
Joined: Jan 02, 2016
Location: East Coast

Re: Capture Indigo Log entries to variable

I have several cameras that natively save images via Camect into the public web server folder. From two of the cameras in particular, as saved they are too large to be served via control pages.

I have a python script that, in theory, reduces the size of such images using PIL.

In theory doesn't always work. I haven't been able to tell why.

I use SQL Logger to trigger on error and on any error, it triggers the script in question.

This script offers a "belt and suspenders" attempt to fix too-large images after the fact, when my log fills up with
Code: Select all
Web Server Error                /web/refreshingimage: refreshing image from file:///Library/Application Support/Perceptive Automation/Indigo 2022.2/Web Assets/public/ImageWhichevert.jpg too large
it puts those errors into variables.

The change in those variables trigger another attempt to reduce the file size of ImageWhatever.jpg

All of this was working in 2022.1 and I'm not entirely sure what has happened. As I asked in another thread, I wonder if the new web server has a lower maximum file size.

Ultimately, this is about the log being used to trigger actions by making log entries be variables because conditions are much more powerful than trigger "types."

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Wed Mar 01, 2023 10:22 am
jay (support) offline
Site Admin
User avatar
Posts: 18212
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Capture Indigo Log entries to variable

So, basically, this is a hack because there's a bug in getting the image correctly sized. Seems like a much better idea is to figure out why resizing the image isn't working in the first place, no? :D

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Mar 01, 2023 10:44 am
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: Capture Indigo Log entries to variable

I just replied on the other thread (which slipped through the cracks – sorry), but the image size restrictions have not changed in Indigo 2022.2. The maximum image size allowed is 475K for an image that has to go over a reflector and 1.5M otherwise.

Image

Posted on
Wed Mar 01, 2023 4:00 pm
Different Computers offline
User avatar
Posts: 2541
Joined: Jan 02, 2016
Location: East Coast

Re: Capture Indigo Log entries to variable

jay (support) wrote:
So, basically, this is a hack because there's a bug in getting the image correctly sized. Seems like a much better idea is to figure out why resizing the image isn't working in the first place, no? :D


Absolutely. However, this has so far eluded me.

The images are always the same size as they come from Camect.

They are always massaged the same way by the same script.

And yet, sometimes the file is too big. I can't figure out why. So yes this *ahem* workaround is supposed to catch images that didn't get shrunk and shrink them.

There's also another use case for turning log entries into variables: when a plugin device gets into a status that isn't supported by triggers (usually "no ack") an error caused by indigo attempting to control it can trigger the series of steps that will reconnect it.

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Thu Mar 02, 2023 5:20 pm
jay (support) offline
Site Admin
User avatar
Posts: 18212
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Capture Indigo Log entries to variable

Different Computers wrote:
There's also another use case for turning log entries into variables: when a plugin device gets into a status that isn't supported by triggers (usually "no ack") an error caused by indigo attempting to control it can trigger the series of steps that will reconnect it.


So, a misbehaving plugin isn't reconnecting a device or something and you have to do something to restart it?

I don't want to sound negative, I'm just trying to get to a reasonable use-case that we can use to determine what the priority of any changes should be be, and what those changes should actually look like.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Mar 02, 2023 5:45 pm
Different Computers offline
User avatar
Posts: 2541
Joined: Jan 02, 2016
Location: East Coast

Re: Capture Indigo Log entries to variable

I have a Nanoleaf light panel that routinely gets into some weird state where it is accessible by bluetooth, and is on wifi according to my Unify system, but is "No Ack" in Indigo.

Looks like the plugin MAY notice, and I had a lack of realizing that "connected" is the same as "ack" and "Not Connected" is the same as "No Ack". Testing now, but I have to wait for the intermittent problem to show again.

Until and unless that works, here's how my system functions:

When the light panel stops responding, an entry in the log triggers an action group that:

tells the Unifi plugin to reconnect the device

Waits a moment

restarts the Nanoleaf plugin.

This usually results in the panels once again communicating with Indigo.

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Wed Mar 29, 2023 12:24 pm
whmoorejr offline
User avatar
Posts: 762
Joined: Jan 15, 2013
Location: Houston, TX

Re: Capture Indigo Log entries to variable

Maybe a random question....
Is "ImageWhichevert.jpg" the saved smaller version of "ImageWhatever.jpg"?

Bill
My Plugin: My People

Posted on
Fri Mar 31, 2023 8:47 am
Different Computers offline
User avatar
Posts: 2541
Joined: Jan 02, 2016
Location: East Coast

Re: Capture Indigo Log entries to variable

Yes. Same image, saved again with the same name. The “t” at the end of whatever was a typo.

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Mon Apr 03, 2023 6:52 am
whmoorejr offline
User avatar
Posts: 762
Joined: Jan 15, 2013
Location: Houston, TX

Re: Capture Indigo Log entries to variable

Here is a script that I used for image resizing.... I'll paste the whole thing so you can just cut out what you don't need, compare it to the script you are using, see if there are any differences.
This script is something I would run when there was no camera activity. No activity trigger runs this script to look in a folder of family pictures, pick one at random, resize the image and then save the resized image at the target location to be used on a control page. (So my control page always points to "R.jpg") When there is camera activity, the camera image goes there. No activity, it cycles through family pics and works like a digital photo frame.

It's been so long since I found this code, I couldn't begin to remember where I got it. Also, I don't remember if was buggy or not because I scrapped that control page layout a while ago in favor of a security specific page.

Code: Select all
import glob
import random
import requests
import os, os.path
import sys

from PIL import Image
from shutil import copyfile

ThisScript = 'Roate Random Image: {}'
PathFrom = "/Users/williammoore/Pictures/"
PathTo = "/Users/williammoore/Desktop/IPCamRotate/R.jpg"

jpegList = glob.glob(PathFrom+"/*.JPG")
      
# indigo.server.log("Glob List: "+str(jpegList))


files=os.listdir(PathFrom)
Pic=random.choice(files)

PicPath=random.choice(jpegList)

indigo.server.log("Random ImageD: "+str(Pic))
indigo.server.log("Random ImageA: "+str(PicPath))

img = Image.open(PicPath)
old_size = img.size
indigo.server.log(str(img)) #<-- for debug

new_size = (600, 400)
new_img = Image.new("RGB", new_size, "black")

border_size = (604, 404)
border_img = Image.new("RGB", border_size, "white")

if (old_size[0] > new_size[0]) or (old_size[1] > new_size[1]):
   per_dem = (float(new_size[0])/float(old_size[0]), float(new_size[1])/float(old_size[1]))
else:
   per_dem = (float(old_size[0])/float(new_size[0]), float(old_size[1])/float(new_size[1]))

if per_dem[0] > per_dem[1]:
   percent = per_dem[1]
else:
   percent = per_dem[0]

recalc_size = (int(old_size[0]*percent),int(old_size[1]*percent))
img = img.resize(recalc_size)

final_size = img.size

BorderWidth = int((new_size[0] - final_size[0])/2)
BorderHeight = int((new_size[1] - final_size[1])/2)
new_img.paste(img, (BorderWidth,BorderHeight))
   
BorderWidth = 2
BorderHeight = 2
border_img.paste(new_img, (BorderWidth,BorderHeight))

border_img.save(PathTo,optimize=True,quality=75)


#copy one file
#from shutil import copyfile

#copyfile(a,'/Users/williammoore/Desktop/IPCamRotate/R.jpg')


Another option is the plugin route with Camect. IMO, it's a waste of resources to bring high resolution images from the NVR over into Indigo. Good to have the High Rez saved on the NVR for investigatory purposes. But I would have questions on the plugin side.... Can Camect pull images from a 2nd stream image (which most cameras serve and is generally a lower quality image/stream)? Can the plugin add "download image from camera - action" where you can adjust the image size? In contrast, I'm using blue iris which pulls the lower quality images. There is a download image action where I can adjust the width to control the overall image size.

Lastly, there may be a "snapshot" setting on either your cameras or within the Camect device that can be reduced which would only affect still images for indigo and not interfere with video stream quality. Again, it depends on where the plugin is getting the image from.

Bill
My Plugin: My People

Posted on
Mon Apr 03, 2023 7:12 am
FlyingDiver offline
User avatar
Posts: 7210
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Capture Indigo Log entries to variable

whmoorejr wrote:
Another option is the plugin route with Camect. IMO, it's a waste of resources to bring high resolution images from the NVR over into Indigo. Good to have the High Rez saved on the NVR for investigatory purposes. But I would have questions on the plugin side.... Can Camect pull images from a 2nd stream image (which most cameras serve and is generally a lower quality image/stream)?


I haven't done it, but if the camera provides an alternate RTSP URL for the secondary stream, then you could set up a camera in Camect with that stream. And pull images from it.

whmoorejr wrote:
Can the plugin add "download image from camera - action" where you can adjust the image size? In contrast, I'm using blue iris which pulls the lower quality images. There is a download image action where I can adjust the width to control the overall image size.


The plugin will grab images from the specified camera device. There's no provision for the plugin to resize the image after it's received (nor will there ever be one).

However, looking at the API, the plugin does pass size parameters to the device when requesting an image. Right now, that's hard coded to the camera image size. I have no idea what happens if you request a smaller image. It might be downsized. It might be cropped.

whmoorejr wrote:
Lastly, there may be a "snapshot" setting on either your cameras or within the Camect device that can be reduced which would only affect still images for indigo and not interfere with video stream quality. Again, it depends on where the plugin is getting the image from.


See above.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests