Posts: 47
Threads: 14
Joined: Feb 2008
All,
I have a quick question that I am sure is in the documentation, but I wasn't able to find it quickly.  I have a HA7net Temperature device and I want to take one of the readings off of it and send it in an email.  I am using an Event with an Action using the "System::Email" Command.  I want to put the temperature reading in the message body.  I know you can put Real Time Variables in using something line "%(StdRTV:HHMM)", but how do you put something read from a device?
Thanks,
Dan
Posts: 40,483
Threads: 491
Joined: Aug 2002
You can use this form:
$(MyDevice.MyField)
Or, if you want to be more fault tolerant, you can use Devices::FieldRead to read it into a variable, and then reference the variable in the subsequent e-mail command, checking for a failure to read:
Code:
If Not Devices::FieldRead(mydevice.myfield, LVar:Temp, False)
LocalVars::SetVariable(LVar:Temp, ???)
EndIf
// Send e-mail here, use %(LVar:Temp) to get the value from the variable
This will do FieldRead and tell it not to fail the action if it the field can't be read, but to just return False. So we do "If Not", so if FieldRead returned a false result, i.e. couldn't read the field. In that case, we put ??? into the variable to indicate we couldn't read it.
Is this a scheduled event or a triggered one? If it's a triggered one and is being caused by a trigger you put on the temp field, then the trigger info that was received will also include the temp that caused the trigger, so you could get it from that and not have to read the field again.
Dean Roddey
Explorans limites defectum
Posts: 47
Threads: 14
Joined: Feb 2008
Thanks Dean!
That did the trick. I am using a scheduled event and it seems to be working fine. I am just putting $(MyDevice.MyField) in the message body.
One other question. The temperature field comes in looking something like 68.24000. Is there any formatting parameters I can put with the $(MyDevice.MyField) to remove everything after the "."? If there is a configuration document that goes over these kind of questions, can you point me toward it?
Thanks again,
Dan
Posts: 40,483
Threads: 491
Joined: Aug 2002
01-09-2018, 05:21 PM
(This post was last modified: 01-09-2018, 05:23 PM by Dean Roddey.)
There's no specific document, just the action reference material, which is in the /Reference area of the HTML help. You just have to get familiar with what's available, or ask.
If just want to keep the decimal digits, you could do something like:
Code:
If Devices::FieldRead(mydevice.myfield, LVar:Temp, False)
If LocalVars::Find(%(LVar:Temp), LVar:PeriodAt, ., False)
LocalVars::CapAt(LVar:Temp, %(LVar:PeriodAt));
EndIf
Else
LocalVars::SetVariable(LVar:Temp, ???)
EndIf
// Now use LVar:Temp as the value to put into the e-mail
It tries to read the field value into LVar:Temp. If not it sets it to ???. If it does, then it does a Find on that to see if the period character is in that resulting text. If so, LVar

eriodAt will be set to the index at which the period is found. Then use CapAt to cap the value in LVar:Temp at the index where the period was found.
You can then use %(LVar:Temp) to put the resulting clipped value into the e-mail.
Dean Roddey
Explorans limites defectum