Create a notify standardised python and html template

Hi guys/gals,

I have several python scripts running various stuff and would like to simplify the email massages for a more consistent look and feel across all the notifications… a template.
then just replace some ~ ~placeholders~ ~ that are written in to the html with the info needed to be transmitted.


- alias: x_schedule4

	#every 10 seconds *For Testing*
    - platform: time_pattern
      seconds: /10

    - condition: state
      entity_id: input_boolean.testing
      state: "on"

    - service:


# Open (read) html email template file into str variable
with open('/home/homeassistant/.homeassistant/python_scripts/email-template.html', 'w') as htmlfile:
    notification_email =

str_message1 = 'data gathered and manipulated from Home Assistant'
str_message2 = 'data gathered and manipulated from Home Assistant'

# Replace email template place holders with script variables
notification_email = notification_email.replace("~~message1~~", str_message1)
notification_email = notification_email.replace("~~message2~~", str_message2)

# Send email with hass service call'notify', email_info, {'title' : notification_tilte, 'html': notification_email})


<!DOCTYPE html>
<html lang="en">
<head runat="server">
	<meta charset="UTF-8">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<style type="text/css">	

	<div class="head">
		<h1>email alert</h1>
	<div class="box">
	<div class="box">

	<div class="foot">

This would work perfectly if ‘open’ was in RestrictedPython and defined, but it is not, so this fails.
So what options, alternatives or methods are there to achieve this and still use the python variables?

Many Thanks

AppDaemon gives you full python functionality.