Sending an Email with embedded values (Pro Only)

You can have Indigo send you an email as an action to various events, but the UI for the email sending feature doesn't allow you to insert any data from Indigo (variable values, device states, etc). However, if you're familiar with AppleScript, you can use a script to send an email that contains any information that Indigo stores (as well as anything that you can get to from AppleScript - pretty much any application on the Mac). This How-to level of difficulty is Moderate.


Janet wants to get an email when the temperature falls below 35 degrees fahrenheit while she is on vacation. The email should contain the current indoor temperature, heat setpoint on her thermostat, the latest weather observation time, the actual temperature, and the wind speed. The weather data will come from variables that are populated by the NOAA weather script that comes with Indigo, so you should also make sure that you're running that script. One other thing that you'll want to set up: we're going to use a variable called houseMode with values of “home”, “away”, and “vacation”. This variable will be changed to represent the mode that the house is operating under: “home” when there's someone at home, “away” when nobody is home (everyone is at work, school, etc.), and “vacation” to indicate that nobody is home for extended periods of time.

Follow these steps to create the trigger action that will make this happen:

  1. Select TRIGGERS in the outline view on the left side (or a subfolder under triggers)
  2. Click the New… button above the trigger list
  3. Name the trigger “Email when freezing”
  4. Select Variable Changed from the Type: popup
  5. Select “Weather_Temperature_F” from the popup next to the word Variable
  6. Select the becomes less than: radio button, and enter 33 on the text field next to it
  7. That specifies that this trigger will fire when the variable “Weather_Temperature_F” becomes 32 or less. Next, select the Condition tab
  8. Select the If variable radio button, and select your “houseMode” variable from the list
  9. Select the equals: radio button, and type in “vacation” (without quotes)
  10. This specifies that this trigger will only execute it's actions if you have houseMode set to vacation. Next, select the Actions tab
  11. Select Execute AppleScript from the Type: popup
  12. Ensure that the radio button next to Embedded: is checked
  13. In the text field below Embedded:, paste in the following script (note, you should replace the values in the first two lines, email address and thermostat name, so that the script will run correctly):
    property emailAddress : "ENTER EMAIL ADDRESS HERE"
    property thermostatName : "ENTER THERMOSTAT NAME HERE"
    property emailSubject : "Temperature dropped below freezing"
    property newline : ASCII character (10)
    tell application "IndigoServer"
    	-- sending an email from Indigo requires 3 bits of information:
    	--    address - who the email goes to
    	--    subject - the subject of the email
    	--    body - the body or text of the email
    	-- 2 of the variables we need were created above, here's the third:
    	set emailBody to ""
    	-- OK, so we have the variables now, but you'll notice that emailBody
    	-- is empty. We need to add each element to the body that we want sent.
    	-- First, let's add the thermostat's temperature (I'm assuming the therm only has 1 temperature reported):
    	set emailBody to emailBody & "Indoor Temperature: " & temperatures of device thermostatName
    	-- Next, let's add the set point
    	set emailBody to emailBody & newline & "Heat Setpoint: " & heat setpoint of device thermostatName
    	-- Next, we'll add the variable values:
    	set emailBody to emailBody & newline & "Outside Temperature: " & value of variable "Weather_Temperature_F"
    	set emailBody to emailBody & newline & "Outside Temperature: " & value of variable "Weather_Observation_Time"
    	set emailBody to emailBody & newline & "Outside Temperature: " & value of variable "Weather_Wind_MPH"
    	send email to emailAddress with subject emailSubject with body emailBody
    end tell

Congratulations, that's it! Now, whenever the “Weather_Temperature_F” variable falls below 32 degrees, and “houseMode” is set to “vacation”, Janet will get an email with that data. You should be able to see now how to expand/change the script to do more. BTW, strictly speaking, you don't need the “tell application” block around the stuff in the middle since an embedded script is already running inside the server, but this script works equally well as-is if you want to execute it as a separate file.

custom_email.txt · Last modified: 2019/01/25 22:53 (external edit)

© Perceptive Automation, LLC. · Privacy