Email to device status

Skibum

Senior Member
I am trying to retrieve the first sentence of an email from a particular source, and display that as a device value.

Suggestions?

Thanks
 
Do you just need help trying to figure out what the first sentence is, or do you also want help with retrieving/reading the emails?
 
Unfortunately my coding only goes as far as me modifying someone elses code....

So I probably need to see the whole kit and kaboodle.
 
That definitely should help out a lot, if not do everything you want. Thanks for sharing!
 
OK

The srcipt from Scott does way way more than I need. Isn't there like a 3 line sub that would handle this?

If mail is from

copy first sentence to device status

end script.
 
It's not that simple. Device status is technically an integer. What you want to do is change a particular device status integer's associated string to the first sentence from an email. Determining the FROM person or address is relatively easy, as we are given that fromthe email and can just check it.

The first major issue is determining what that sentence is. Is the email HTML mail? If so, you may have to strip the HTML from the text (bunch of replace functions as in the example code).

Can we assume the sender will always use correct punctuation? If so, what punctuation will be used to end the first sentence? Usually, a period, question mark, exclamation mark can easily be sentence endings. So, how do we know which is in use? If we don't then we have to crawl the sentence text until we find one of them. The SPLIT function can do this for us, if properly coded. You could also locate where all the punctuation is in the body text, and pick the lowest location value and assume that is the end of the first sentence, then take the substring of the body text up to that point.

From there you need to pick a status value, then change the string associated with it in the device values strings. In a normal X10 device, those values are 2=ON, 3=OFF, 4=DIM and 17=UKNOWN.

This last part would be easier if it was just the device string you wanted to change, but getting the first sentence is still the biggest issue.
 
huggy59 said:
The first major issue is determining what that sentence is. Is the email HTML mail? If so, you may have to strip the HTML from the text (bunch of replace functions as in the example code).

Can we assume the sender will always use correct punctuation? If so, what punctuation will be used to end the first sentence? Usually, a period, question mark, exclamation mark can easily be sentence endings. So, how do we know which is in use? If we don't then we have to crawl the sentence text until we find one of them. The SPLIT function can do this for us, if properly coded. You could also locate where all the punctuation is in the body text, and pick the lowest location value and assume that is the end of the first sentence, then take the substring of the body text up to that point.

From there you need to pick a status value, then change the string associated with it in the device values strings. In a normal X10 device, those values are 2=ON, 3=OFF, 4=DIM and 17=UKNOWN.

This last part would be easier if it was just the device string you wanted to change, but getting the first sentence is still the biggest issue.
The mail is plain text. Formatting will always be the same.

The sentence is the first one, and ends with a period.
 
Code:
'  This script should be called by an event triggered on email received.
'  Script assumes email body text is plain text - no provisions for HTML (webmail) have been made.
'  Script assumes sentences are properly terminated with punctuation, and that the first one is a period "." .
'  NOT TESTED!  EXAMPLE ONLY!

sub main()

 dim MyArray, MsgIndex, MsgSubject, MsgFrom, MsgText

 MsgIndex = hs.MailTrigger
 MsgSubject = hs.MailSubject(MsgIndex)
 MsgFrom = hs.MailFrom(MsgIndex)

 if MsgFrom = "[email protected]" then

  MsgText = hs.MailText(MsgIndex)

  MyArray = split(MsgText, ".", 1)

  hs.SetDeviceString(A1, MyArray(0))

 end if
 
end sub
 
I see it... I LIKE IT!

will try to set this up when I get home... THANKS!
I'll buy the first round in the chat tonight.... :)
 
Back
Top