So, you've thrown together some Python awesomeness to create a message that will get plopped into an email to yourself.... now you want to add some buttons and hyperlinks? That was where I got stuck.... So I made a template action to mess with until I got it working and thought I'd share with anyone else trying to do this.
FYI, if you look at my HTML stuff and have a better suggestion, I will not be offended.
First you will have all your stuff that culminates in some sort of a message variable. In my example below, the plain text stuff is all saved as "fMessage" (I didn't include that part, it's a bunch of junk that checks to see if any Fans are on, if so, it builds a message to let me know which ones are on or all off. Fans = fmessage.
For the HTML bit, you need the below "Start HTML" and "Close HTML". All the other bits are put in between those.
- Code: Select all
##################
#Start HTML
##################
html = """\
<html>
<head></head>
<body>
"""
- Code: Select all
##################
#Close HTML
##################
html = html + """\
</body>
</html>
"""
I leave descriptions in my python stuff because two days from now I will have totally forgotten what that code does and how I figured it out... Here are the middle bits (Add HTML Message, Insert a Button that links to an indigo touch control page, Insert a message variable (fMessage), and Insert a hyperlink)
- Code: Select all
##################
#Add HTML Message
##################
html = html + """\
<p>Hi!<br>
How are you?<br>
Here is the <a href="http://www.python.org">python</a> you wanted.<br>
Look at the other links for more stuff.
</p>
"""
- Code: Select all
##################
#Insert a Button: see https://wiki.indigodomo.com/doku.php?id=indigo_touch_urls
##################
html = html + """\
<p><a href="indigodomo://controlpage/FRONT_DOOR">
<button style="padding: 16px; background-color: darkblue; color:aliceblue; border-radius: 4px;font-size: 12px">Door Page</button>
</a></p>
"""
- Code: Select all
##################
#Insert a message variable where "fMessage" is something you put together above.
##################
html = html + "<p>"+ str(fMessage) + "<br></p>"
- Code: Select all
##################
#Insert a hyperlink
##################
html = html + """\
<p>For More Details, Click <a href="http://www.python.org">here.</a>
</p>
"""
Lastly, I save the html as a new variable, theMessage and send it. Note, I # the stuff I'm not using, but I leave it there for future use.
- Code: Select all
theMessage = html
##################
#Send It. See: https://wiki.indigodomo.com/doku.php?id=indigo_2021.1_documentation:plugins:email
##################
props = {
'emailTo': 'me@gmail.com',
# 'emailCC': 'address3, address4',
# 'emailBCC': 'address5, address6',
'emailSubject': title,
# 'emailAttachments': 'file1, file2, file3',
'emailFormat': 'html',
'emailMessage': theMessage
}
plugin = indigo.server.getPlugin("com.indigodomo.email")
if plugin.isEnabled():
plugin.executeAction("sendEmail", deviceId=1082559553, props=props)