{"id":378,"date":"2017-11-03T19:17:47","date_gmt":"2017-11-03T19:17:47","guid":{"rendered":"https:\/\/www.cribbstechnologies.com\/?p=378"},"modified":"2017-11-03T19:19:35","modified_gmt":"2017-11-03T19:19:35","slug":"rocket-launch-sensor","status":"publish","type":"post","link":"https:\/\/www.cribbstechnologies.com\/index.php\/2017\/11\/03\/rocket-launch-sensor\/","title":{"rendered":"T-5, 4, 3, 2, 1 Liftoff &#8211; Rocket Launch Sensor"},"content":{"rendered":"<p>[et_pb_section bb_built=&#8221;1&#8243; admin_label=&#8221;section&#8221;][et_pb_row admin_label=&#8221;row&#8221;][et_pb_column type=&#8221;4_4&#8243;][et_pb_text admin_label=&#8221;Text&#8221; background_layout=&#8221;light&#8221; text_orientation=&#8221;left&#8221; use_border_color=&#8221;off&#8221; border_color=&#8221;#ffffff&#8221; border_style=&#8221;solid&#8221;]<\/p>\n<p>Home Assistant is\u00a0<strong>extremely<\/strong> extensible and thanks to this you can integrate a whole bunch of stuff without too much work. <a href=\"http:\/\/www.vmwareinfo.com\">Carlo<\/a> 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 <a href=\"https:\/\/launchlibrary.net\/docs\/1.2.1\/api.html\">cool little API<\/a> that allows you to query information about rocket launches.<\/p>\n<p>Since it&#8217;s a REST API it was easy to use the <a href=\"https:\/\/home-assistant.io\/components\/sensor.rest\/\">rest sensor<\/a> 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 <a href=\"https:\/\/github.com\/cribbstechnologies\/ha_config\/blob\/master\/packages\/launch_sensor.yaml\">my github repository<\/a>.<\/p>\n<p>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&#8217;s offset from UTC and calculating the actual timestamp of when the launch ocurrs.<\/p>\n<pre lang=\"yaml\">{% if strptime(launch.isostart, '%Y%m%dT%H%M%SZ').strftime('%Y-%m-%d') == now().strftime('%Y-%m-%d') %}\r\n\t{% set utc_offset_string = now().strftime('%z') %}\r\n\t{% set utc_offset_direction = utc_offset_string[:1] %}\r\n\t{% set utc_offset_hours = now().strftime('%z')[-4:] %}\r\n\t{% set utc_offset_seconds = (utc_offset_hours| int \/100) * 60 * 60 %}\r\n\t{% if utc_offset_direction == '-' %}\r\n\t {{ launch.wsstamp + utc_offset_seconds}}\r\n\t{% else %}\r\n\t  {{ launch.wsstamp - utc_offset_seconds}}\r\n\t{% endif %}\r\n{% endif %}\r\n<\/pre>\n<p>The first logic block breaks down the incoming date string of the format\u00a020171105T113000Z to see if the record matches today. If so, it figures the user&#8217;s offset from UTC and then either adds or subtracts that number of seconds from the incoming timestamp to set the local timestamp.<\/p>\n<p>The automation is pretty straightforward. It&#8217;s triggered any time the state of the sensor changes and it makes sure that there&#8217;s actually a value in the sensor and that the time hasn&#8217;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&#8217;d like. Enjoy!<\/p>\n<p>[\/et_pb_text][\/et_pb_column][\/et_pb_row][\/et_pb_section]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[et_pb_section bb_built=&#8221;1&#8243; admin_label=&#8221;section&#8221;][et_pb_row admin_label=&#8221;row&#8221;][et_pb_column type=&#8221;4_4&#8243;][et_pb_text admin_label=&#8221;Text&#8221; background_layout=&#8221;light&#8221; text_orientation=&#8221;left&#8221; use_border_color=&#8221;off&#8221; border_color=&#8221;#ffffff&#8221; border_style=&#8221;solid&#8221;] Home Assistant is\u00a0extremely 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,15,19,16],"tags":[],"class_list":["post-378","post","type-post","status-publish","format-standard","hentry","category-blog","category-home-assistant","category-jinja","category-json"],"_links":{"self":[{"href":"https:\/\/www.cribbstechnologies.com\/index.php\/wp-json\/wp\/v2\/posts\/378","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cribbstechnologies.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cribbstechnologies.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cribbstechnologies.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cribbstechnologies.com\/index.php\/wp-json\/wp\/v2\/comments?post=378"}],"version-history":[{"count":4,"href":"https:\/\/www.cribbstechnologies.com\/index.php\/wp-json\/wp\/v2\/posts\/378\/revisions"}],"predecessor-version":[{"id":382,"href":"https:\/\/www.cribbstechnologies.com\/index.php\/wp-json\/wp\/v2\/posts\/378\/revisions\/382"}],"wp:attachment":[{"href":"https:\/\/www.cribbstechnologies.com\/index.php\/wp-json\/wp\/v2\/media?parent=378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cribbstechnologies.com\/index.php\/wp-json\/wp\/v2\/categories?post=378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cribbstechnologies.com\/index.php\/wp-json\/wp\/v2\/tags?post=378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}