Home Assistant isĀ extremely extensible and thanks to this you can integrate a whole bunch of stuff without too much work. Carlo lives in Orlando and wanted a way to be alerted when there was a launch at Kennedy Space Center so that he could go outside with some binoculars and watch the launch. He found a pretty cool little API that allows you to query information about rocket launches.

Since it’s a REST API it was easy to use the rest sensor component to get the data, figure out if there was a launch today, and set up a reminder that would be triggered at the beginning of the launch window. (not really, it was extremely difficult but mostly due to me being a jinja novice) You can see the Home Assistant package for it on my github repository.

The REST data has timestamps that are reported in UTC time so a bunch of the stuff in the template is just dealing with finding out the system’s offset from UTC and calculating the actual timestamp of when the launch ocurrs.

{% if strptime(launch.isostart, '%Y%m%dT%H%M%SZ').strftime('%Y-%m-%d') == now().strftime('%Y-%m-%d') %}
	{% set utc_offset_string = now().strftime('%z') %}
	{% set utc_offset_direction = utc_offset_string[:1] %}
	{% set utc_offset_hours = now().strftime('%z')[-4:] %}
	{% set utc_offset_seconds = (utc_offset_hours| int /100) * 60 * 60 %}
	{% if utc_offset_direction == '-' %}
	 {{ launch.wsstamp + utc_offset_seconds}}
	{% else %}
	  {{ launch.wsstamp - utc_offset_seconds}}
	{% endif %}
{% endif %}

The first logic block breaks down the incoming date string of the formatĀ 20171105T113000Z to see if the record matches today. If so, it figures the user’s offset from UTC and then either adds or subtracts that number of seconds from the incoming timestamp to set the local timestamp.

The automation is pretty straightforward. It’s triggered any time the state of the sensor changes and it makes sure that there’s actually a value in the sensor and that the time hasn’t already passed. Then it just waits until the current time is the same as the timestamp for the start of the launch window. My example just turns lights on/off but you can easily modify this to do whatever you’d like. Enjoy!