Need hello world python example .. *please*

Posted on
Thu Jan 05, 2017 7:59 am
sgbirch offline
Posts: 99
Joined: Sep 11, 2013

Need hello world python example .. *please*

Hi

I am struggling to understand how to write python code that interacts with directly indigo, not using the RESTFUL interface.

Could you give a "hello world" example . It should do something simple like print the state of a device. It needs to be more than a snippet so we can see which includes are necessary, and let us know where the script should be placed.

There are a few posts like this all asking how to get started. IMHO the documentation is at too high a level with the initial steps not defined, you really need a HOWTO that starts simple and leads the reader in, holding his/her hand.

I can't understand what a background scripts is nor how to write a normal script, if that is possible. I see that a background script can run for a maximum of 10 seconds, but how often is it called? Is all indigo processing stopped while it runs or do they run in parallel?


Help!!!

Posted on
Thu Jan 05, 2017 8:17 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Need hello world python example .. *please*

Where and how is this script going to run? Will it be run "on demand" from an Indigo event (scheduled action, triggered by something)? Does it need to run continuously in parallel to Indigo? On the Indigo server machine or on another machine?

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

Posted on
Thu Jan 05, 2017 8:20 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Need hello world python example .. *please*

For instance, the script I posted in this thread is a complete script, not a snippet: viewtopic.php?f=107&t=17697

But since it's running "inside" Indigo (in a scheduled event), it doesn't need any extra includes to communicate with Indigo.

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

Posted on
Thu Jan 05, 2017 10:36 am
jay (support) offline
Site Admin
User avatar
Posts: 18223
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Need hello world python example .. *please*

Tons of examples in the Scripting Tutorial...

The docs for the Execute Script action describe the two ways scripts are executed. External scripts can be anywhere on your disk.

You don't need any includes to use the indigo module since it's always included automatically. You can't run Indigo python scripts in a standard Python process - they must be executed from the Execute Script action above.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Jan 05, 2017 12:16 pm
sgbirch offline
Posts: 99
Joined: Sep 11, 2013

Re: Need hello world python example .. *please*

FlyingDiver wrote:
Where and how is this script going to run? Will it be run "on demand" from an Indigo event (scheduled action, triggered by something)? Does it need to run continuously in parallel to Indigo? On the Indigo server machine or on another machine?


It's job is to monitor about 25 TRV temperatures and set them according to a set of simple rules. In addition it will turn on/off one of three heating zones. I am trying to automate the heating in a large building.

I think it will run in parallel with indigo but on the same Mac. Alternatively it could be a plugin fired every 5 seconds from a schedule.

Other replies in this thread are pointing me to examples so I am about to go on a hunt to see if I can find what I need to get started. It is probably just me, I can't find my way around the documents very well

Posted on
Thu Jan 05, 2017 12:23 pm
sgbirch offline
Posts: 99
Joined: Sep 11, 2013

Re: Need hello world python example .. *please*

jay (support) wrote:
Tons of examples in the Scripting Tutorial...

The docs for the Execute Script action describe the two ways scripts are executed. External scripts can be anywhere on your disk..


Thank you Jay ... Execute Script is probably exactly what I needed to get started. I was too far down in the docs, looking at the "Technical Documents" and had missed the introduction to scripting. Wish me luck :-)

Posted on
Sun Jan 29, 2017 4:59 am
sgbirch offline
Posts: 99
Joined: Sep 11, 2013

Re: Need hello world python example .. *please*

jay (support) wrote:
You don't need any includes to use the indigo module since it's always included automatically. You can't run Indigo python scripts in a standard Python process - they must be executed from the Execute Script action above.


I'd like to use a couple of functions I've written in multiple Python scripts. Can I include the files and, if so, where should they be located?

Also, how should I backup my Indigo configuration, including scripts? Is there a best practice for this?

Steve


Sent from my iPad using Tapatalk Pro

Posted on
Sun Jan 29, 2017 5:46 am
DaveL17 offline
User avatar
Posts: 6758
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Need hello world python example .. *please*

The answer is on the page that Jay pointed to above: Indigo Scripting Tutorial. Look for the section called "Shared Classes and Methods in Python Files (Python Attachments or Modules)". The example provided is for users on Indigo 7 (which uses Python 2.7) so if you're on a different version of Indigo, you'll have to check the documentation for your version. This allows you to import your scripts into other scripts.

It's tough to talk about best practice for backup. It depends on how you've configured your Indigo setup. If you have scripts in the Python directories or elsewhere, or files and images in multiple places, I'd suggest a whole drive back up (I use CrashPlan). I believe that some people do routine backups using Carbon Copy Cloner (which mirrors the drive in backup) which I gather would allow you to simply restore or even replace the failed drive with the backup. If you have all of your files within the Indigo folder, you could simply drag and drop that folder tree onto a flash drive or other media.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sun Jan 29, 2017 6:03 am
sgbirch offline
Posts: 99
Joined: Sep 11, 2013

Re: Need hello world python example .. *please*

DaveL17 wrote:
If you have all of your files within the Indigo folder, you could simply drag and drop that folder tree onto a flash drive or other media.


Thank you for both answers.

I had, in fact, been backing up using tar to backup the whole Indigo tree so from what you have said it is a reasonable approach.

Thanks,
Steve



Sent from my iPad using Tapatalk Pro

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 12 guests