Emailing Variable State in the Subject Line

Posted on
Tue Dec 30, 2014 6:09 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Emailing Variable State in the Subject Line

Also make sure you use dumb quotes instead of smart quotes.

Image

Posted on
Tue Dec 30, 2014 6:14 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Emailing Variable State in the Subject Line

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.

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

Posted on
Tue Dec 30, 2014 6:15 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Emailing Variable State in the Subject Line

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.

Image

Posted on
Tue Dec 30, 2014 6:28 pm
DaveL17 offline
User avatar
Posts: 6743
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Emailing Variable State in the Subject Line

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

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

[My Plugins] - [My Forums]

Posted on
Tue Dec 30, 2014 6:37 pm
DU Lou offline
Posts: 279
Joined: Mar 08, 2012
Location: Florida

Re: Emailing Variable State in the Subject Line

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.
Last edited by DU Lou on Tue Dec 30, 2014 6:41 pm, edited 1 time in total.

Posted on
Tue Dec 30, 2014 6:38 pm
DU Lou offline
Posts: 279
Joined: Mar 08, 2012
Location: Florida

Re: Emailing Variable State in the Subject Line

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?

Posted on
Tue Dec 30, 2014 6:49 pm
DaveL17 offline
User avatar
Posts: 6743
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Emailing Variable State in the Subject Line

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)

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

[My Plugins] - [My Forums]

Posted on
Tue Dec 30, 2014 7:02 pm
DU Lou offline
Posts: 279
Joined: Mar 08, 2012
Location: Florida

Re: Emailing Variable State in the Subject Line

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"

Posted on
Tue Dec 30, 2014 7:06 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Emailing Variable State in the Subject Line

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 "\%".

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

Posted on
Tue Dec 30, 2014 7:09 pm
DaveL17 offline
User avatar
Posts: 6743
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Emailing Variable State in the Subject Line

Apologies. Typo on my part. You can do it like this:

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


(two percent signs.)

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

[My Plugins] - [My Forums]

Posted on
Tue Dec 30, 2014 7:13 pm
DU Lou offline
Posts: 279
Joined: Mar 08, 2012
Location: Florida

Re: Emailing Variable State in the Subject Line

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

Posted on
Tue Dec 30, 2014 7:48 pm
DaveL17 offline
User avatar
Posts: 6743
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Emailing Variable State in the Subject Line

You're welcome. Glad I could help.

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

Dave

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

[My Plugins] - [My Forums]

Who is online

Users browsing this forum: No registered users and 1 guest