Storing a reference to an instance of a class..

Posted on
Sat Oct 31, 2020 10:04 pm
lazlohollyfeld offline
Posts: 29
Joined: Jan 09, 2012

Storing a reference to an instance of a class..

Is there a way to store a reference to a class instance - so that I can access it from multiple python scripts?
i've tried the output to unicode - not what i wanted..

thanks!

Posted on
Sun Nov 01, 2020 3:01 am
FlyingDiver offline
User avatar
Posts: 4669
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Storing a reference to an instance of a class..

The class instance itself can only exist in one script. When that script goes away, so does the class instance.

What class is this an instance of? How hard is it to re-create? Maybe show some of the code you're working with?

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

Posted on
Sun Nov 01, 2020 3:02 pm
jay (support) offline
Site Admin
User avatar
Posts: 16460
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Storing a reference to an instance of a class..

Maybe just a thorough description of the scenario you're working on - perhaps someone has already tackled something similar.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Nov 02, 2020 12:45 am
lazlohollyfeld offline
Posts: 29
Joined: Jan 09, 2012

Re: Storing a reference to an instance of a class..

ok - here goes.. thanks for asking! Here's my "thorough description of the scenario"!!

I've been using motion sensors since I started with Indigo, jeesh - > 12 years now? I've never been satisfied with the setup.. The kitchen, for example - 2 motions sensors and 6 different lights (insteon dimmers + Zigby light strips) - and I used different "scenes" (now action groups) based on the time of day. I hard-wired some Aeotec 6-in-1 sensors, as well as some really nice Security system sensors via EZIO8SA.. I want to incorporate the 6-in-1's luminance value next to have more adaptive lighting based on the light levels in the rooms . I found that for each room, i had a ton of artifacts and it was a pain to manage - and very inelegant. Triggers, schedules, action groups, etc... With 5 motion-sensed rooms and growing, it's a TON of stuff to manage, create and troubleshoot..

I've since distilled the whole setup to just a couple components using python, variables and shared functions:
  1. I now have 1 motion-sensed (on or off) trigger per room - the listener
  2. I use a bunch of variables to maintain state for each room ( kitchenCurrent state, kitchenDefaultDuration, kitchenCurrentDuration, kitchenCurrentScene, kitchenDesiredScene, kitchenDecrement and a host of others for debugging and overrides.
  3. I still use Action groups - 1 ea per scene to update the various devices
  4. And lastly - a single schedule - "the scheduler" that wakes up every minute and tears thru all the room vars and decrements the countdown values, figures out what the current "scene" should be and then calls action groups as needed to turn on/off devices at varying levels

I'm trying to move away from using Action Groups and all those variables - and maintain the levels and settings for each room in class properties and some JSON for the "scene" configurations - in "room-specific" instances of my class. I'd like "the scheduler" to have access to each instance so it can loop thru and call the methods in each instance.. And then use the luminance values to fine tune each light's level as needed.. But references to the instances are not available outside of the trigger script that instantiates them :(

I eventually want to turn this into an Occupancy Plugin - and perhaps incorporate some light machine learning to optimize the default duration and decrement value based on patterns.. I've already started experimenting with increasing the decrement value based on the #motion events in a given time period - kind of an accelerated decay if you will..

And that's where i'm at.. Should I just move this to a plugin? Would that be better model?

thanks in advance!

Posted on
Mon Nov 02, 2020 4:02 am
FlyingDiver offline
User avatar
Posts: 4669
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Storing a reference to an instance of a class..

You need to turn this into a plugin now. That's the only way you're going to be able to maintain the persistent state for all these inputs. You'll also be able to run the polling schedule internal to the plugin as well.

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

Posted on
Mon Nov 02, 2020 4:09 am
siclark offline
Posts: 1414
Joined: Jun 13, 2017
Location: UK

Re: Storing a reference to an instance of a class..

Plus 1. I would love this. Never got round to working out how to implement it

Posted on
Mon Nov 02, 2020 9:49 am
jay (support) offline
Site Admin
User avatar
Posts: 16460
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Storing a reference to an instance of a class..

Yep, it's definitely time to make it a plugin as it will provide you with all the infrastructure you need without cobbling together individual parts (not that that's a bad thing, but some solutions just outgrow the glue together approach).

A lot of our more prolific plugin devs are here on the forums (as, obviously, we are) to help you through any learning curve about plugins. I think we've done a pretty good job making them relatively easy to implement but also balanced with the features that almost every advanced solution needs.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Nov 02, 2020 12:14 pm
Colly offline
Posts: 361
Joined: Jan 16, 2016
Location: Ireland

Re: Storing a reference to an instance of a class..

For what it’s worth I’d be interested in the Occupancy plugin.

Posted on
Mon Nov 02, 2020 1:23 pm
lazlohollyfeld offline
Posts: 29
Joined: Jan 09, 2012

Re: Storing a reference to an instance of a class..

wow- thanks all! I guess it's time to start "plugging" away on the plug-in! (he he)

Posted on
Mon Nov 02, 2020 1:25 pm
peszko offline
Posts: 268
Joined: Mar 07, 2012

Re: Storing a reference to an instance of a class..

I'd love a plugin presence that takes multiple devices as input. Currently I run several triggers and variables per room to do this, and was planning on making it in to a plug in for me. I find the trigger variable route to be messy and difficult to repeat. Especially that when I need to repeat it, long enough time went by that I always forget something and mess it up.

Posted on
Mon Nov 02, 2020 4:01 pm
FlyingDiver offline
User avatar
Posts: 4669
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Storing a reference to an instance of a class..

I had posted a question about presence detection in this thread: viewtopic.php?f=5&t=24490

At the time, I was thinking more about detecting leaving/arriving at a location, not presence within rooms. But the subject has some interest for me.

I don't want to step on the OP's toes, but if this is something of general interest, I might write a plugin for it.

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

Posted on
Mon Nov 02, 2020 6:43 pm
lazlohollyfeld offline
Posts: 29
Joined: Jan 09, 2012

Re: Storing a reference to an instance of a class..

No worries here! I’ve been thinking about this off and on for a long time. I’d love to see how you’d solve it!

Posted on
Tue Nov 03, 2020 12:19 am
lazlohollyfeld offline
Posts: 29
Joined: Jan 09, 2012

Re: Storing a reference to an instance of a class..

fwiw, i glossed over the motion bit - but I feel compelled to praise the EZIO8SA and SensorSwitch gear...

After years of constantly changing motion sensor batteries - that NEVER last as long as they say - I am free of the burdon! On a recent kitchen remodel - I was able to pull wire for all of the existing sensors on the main floor and add some additional ones.

After quite a bit of research i have 5 different models of sensors deployed;
  • DSC BV-502, Ademco 997: the first ones I bought - before I knew anything. They're good general purpose sensors, but lack the range or sensitivity that i needed.. Great for "deliberate", big motion occupancy areas - like hallways and laundry rooms.
  • Sensor Switch CM-9: used in my office, selected for its ability to detect small movements - like typing for long periods of time. The Insteon sensors would often trigger an off signal when they weren't able to sense movement while typing..
  • Sensor Switch CMR 10: Like the CM-9, it has great sensitivity. This model covers a 30 foot radius - which is great for a large, open kitchen where people often sit for long periods of time with small movements.
  • Aeotec 6-in-1: These are kind of like the jacks of all trades. They're "ok" for motion in small areas, 10 feet is pushing it. I also measure luminance - for my eventual progressive lighting. I use the optional recessed wall mounts for a really clean look. I soldered a micro usb jack to the hardwire run - for power.

It took some trial and error getting each of the models to work - as some of these are designed to be incorporated into commercial lighting "systems". The Sensor Switch models were the biggest challenge as they have a ton of configurable options - some of the default values weren't expected.. Overall, the documentation was pretty good.

These aren't that pretty to look at - but they disappear on the ceiling once you disable the status LED.

They all run back to a panel in my utility room - where the EZIO8SA is mounted. The Aeotec sensors are powered by a small USB transformer.

The overall sensitivity & reliability from these sensors is like day and night compared to battery operated variety. I still have quite a few of the newer Insteon models with usb option - i may re-introduce them at some point. Aside from the Aeotec - they were all found on eBay for a fraction of their retail price - mostly NIB.

Hope that helps someone! I'm still prettying it all up - so I'll wait to post photos...

Posted on
Wed Nov 04, 2020 4:49 pm
FlyingDiver offline
User avatar
Posts: 4669
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Storing a reference to an instance of a class..

looking for testers: viewtopic.php?f=216&t=24528

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 1 guest