From 7b110def1bb38db89c99665c3eca845c785b5bbf Mon Sep 17 00:00:00 2001
From: ccostan <carlo@ipm.com>
Date: Sat, 11 Jul 2020 11:26:42 -0400
Subject: [PATCH] Spaceship updates - #411

---
 config/packages/space.yaml | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/config/packages/space.yaml b/config/packages/space.yaml
index d6f5a6fd..1847e55c 100755
--- a/config/packages/space.yaml
+++ b/config/packages/space.yaml
@@ -15,6 +15,25 @@ sensor:
 
   - platform: moon
 
+  - platform: rest
+    scan_interval: 1800
+    name: SpaceX Starman
+    json_attributes:
+      - earth_distance_mi
+    value_template: '{{ value_json["speed_mph"] }}'
+    unit_of_measurement: "mph"
+    resource: 'https://api.spacexdata.com/v2/info/roadster'
+
+  - platform: rest
+    scan_interval: 1800
+    name: SpaceX
+    json_attributes:
+      - mission_name
+      - launch_site
+      - rocket
+    value_template: '{{ value_json["launch_date_unix"] }}'
+    resource: 'https://api.spacexdata.com/v2/launches/next'
+
   - platform: rest
     scan_interval: 1800
     resource: https://launchlibrary.net/1.2.2/launch/next/10
@@ -50,7 +69,7 @@ automation:
 
     action:
       - wait_template: >-
-          {{((as_timestamp(now()) - states('sensor.launch_window') | float) | abs < 601)}}
+          {{((as_timestamp(now()) - states('sensor.launch_window') | float) | abs < 301)}}
       - service: script.notify_engine
         data_template:
           value1: 'Go Outside!  There is a Rocket Launch very soon!'
@@ -58,7 +77,11 @@ automation:
 
       - service: script.tweet_engine_no_image
         data_template:
-          tweet: 'There is a Rocket launch happening right now!  I can see it if I look closely. @BrianCribbs #SpaceX #Space'
+          tweet: >-
+            {{ [
+            "There is a Rocket launch happening right now!  I can see it if I look closely. {{states.sensor.next_launch.attributes.stream }}",
+            "Check out {{ states('sensor.next_launch') }} on {{states.sensor.next_launch.attributes.stream }} right now.  Launch Window is opening."
+            ] | random + " #Space @BrianCribbs #SpaceX " }}
 
 # This automation was also moved to a macro in the speech_engine.
 # It's a random fact now.