Page 2 of 2

Re: Emailing Variable State in the Subject Line

PostPosted: Tue Dec 30, 2014 6:09 pm
by matt (support)
Also make sure you use dumb quotes instead of smart quotes.

Re: Emailing Variable State in the Subject Line

PostPosted: Tue Dec 30, 2014 6:14 pm
by FlyingDiver
matt (support) wrote:
Also make sure you use dumb quotes instead of smart quotes.


Good point. I never have that problem because I edit code using TextWrangler. Except when using the built-in Editor in Indigo. Will that insert smart quotes? Never had it do it to me.

Re: Emailing Variable State in the Subject Line

PostPosted: Tue Dec 30, 2014 6:15 pm
by matt (support)
Not automatically if you type it, but I imagine if you copy/paste from the forum (which is showing smart quotes) they will be smart.

Re: Emailing Variable State in the Subject Line

PostPosted: Tue Dec 30, 2014 6:28 pm
by DaveL17
I would also suggest that it would be better to use ['batteryLevel'] rather than ['batteryLevel.ui'].

States that end in 'ui' are the ones that are used by Indigo for display in the UI and control pages. You won't necessarily run into trouble, but you might. For example, the UI value might include symbols or other characters.

Dave

Re: Emailing Variable State in the Subject Line

PostPosted: Tue Dec 30, 2014 6:37 pm
by DU Lou
matt (support) wrote:
Also make sure you use dumb quotes instead of smart quotes.

What is the difference between smart vs dumb quotes other than you and Dave using "smart" and me using "dumb" ones??? :mrgreen:

matt (support) wrote:
Not automatically if you type it, but I imagine if you copy/paste from the forum (which is showing smart quotes) they will be smart.

Ahhh I think I did just copy Jay's example from another post into notes and then edited and re copied and pasted into indigo.

Re: Emailing Variable State in the Subject Line

PostPosted: Tue Dec 30, 2014 6:38 pm
by DU Lou
DaveL17 wrote:
I would also suggest that it would be better to use ['batteryLevel'] rather than ['batteryLevel.ui'].

States that end in 'ui' are the ones that are used by Indigo for display in the UI and control pages. You won't necessarily run into trouble, but you might. For example, the UI value might include symbols or other characters.

Dave


The Aeon Multi Sensor does have both:
Code: Select all
batteryLevel : 85 (integer)
     batteryLevel.ui : 85% (string)

I actually intentionally picked the .ui so I could see the "%" symbol in the email message. Is that bad?

Re: Emailing Variable State in the Subject Line

PostPosted: Tue Dec 30, 2014 6:49 pm
by DaveL17
DU Lou wrote:
I actually intentionally picked the .ui so I could see the "%" symbol in the email message. Is that bad?


Absolutely not.

But one day, you might be pulling a value to do some math or logic test and the .ui value might trip you up. What I do (just as a matter of good practice IMO) is to pull the value without the "%" and add the "%" in after the value is inserted using '%s':

Code: Select all
theSubject = “Foyer battery level is %s%” % (batteryLevel)

Re: Emailing Variable State in the Subject Line

PostPosted: Tue Dec 30, 2014 7:02 pm
by DU Lou
DaveL17 wrote:
DU Lou wrote:
I actually intentionally picked the .ui so I could see the "%" symbol in the email message. Is that bad?


Absolutely not.

But one day, you might be pulling a value to do some math or logic test and the .ui value might trip you up. What I do (just as a matter of good practice IMO) is to pull the value without the "%" and add the "%" in after the value is inserted using '%s':

Code: Select all
theSubject = “Foyer battery level is %s%” % (batteryLevel)


That makes sense although when I use
Code: Select all
theSubject = “Foyer battery level is %s%” % (batteryLevel)
Indigo returns "embedded script: incomplete format"

Re: Emailing Variable State in the Subject Line

PostPosted: Tue Dec 30, 2014 7:06 pm
by FlyingDiver
DU Lou wrote:
DaveL17 wrote:
That makes sense although when I use
Code: Select all
theSubject = “Foyer battery level is %s%” % (batteryLevel)
Indigo returns "embedded script: incomplete format"


Heh. The % is a special character in print type statements, so that happens. You actually need:

Code: Select all
theSubject = “Foyer battery level is %s\%” % (batteryLevel)


The backslash says to just use the %, don't treat it special. At least, I think Python works that way. If you get an error, try "%%" instead of "\%".

Re: Emailing Variable State in the Subject Line

PostPosted: Tue Dec 30, 2014 7:09 pm
by DaveL17
Apologies. Typo on my part. You can do it like this:

Code: Select all
theSubject = “Foyer battery level is %s%%” % (batteryLevel)


(two percent signs.)

Re: Emailing Variable State in the Subject Line

PostPosted: Tue Dec 30, 2014 7:13 pm
by DU Lou
FlyingDiver wrote:
DU Lou wrote:
DaveL17 wrote:
That makes sense although when I use
Code: Select all
theSubject = “Foyer battery level is %s%” % (batteryLevel)
Indigo returns "embedded script: incomplete format"


Heh. The % is a special character in print type statements, so that happens. You actually need:

Code: Select all
theSubject = “Foyer battery level is %s\%” % (batteryLevel)


The backslash says to just use the %, don't treat it special. At least, I think Python works that way. If you get an error, try "%%" instead of "\%".


It's "%%" :)

Thanks for all the help Dave! I also think part of the problem earlier was that I copied and pasted and some of the quotes where 'smart' so that fouled things up a bit. But I have now accomplished exactly what I was looking for with your assistance!

~Lou

Re: Emailing Variable State in the Subject Line

PostPosted: Tue Dec 30, 2014 7:48 pm
by DaveL17
You're welcome. Glad I could help.

Before you know it, you'll be the one helping the next guy.

Dave