Rocket launch warning


#1

Hi

How would you alert the next rocket launch based on the new component https://www.home-assistant.io/components/sensor.launch_library/ ?

I’ve tried this in the template sand box:

Title:

next: {{ states(“sensor.next_launch”) }}
next: Falcon 9 Block 5 | SpX CRS-16

Date:

at: {{ state_attr(‘sensor.next_launch’, ‘launch_time’) }}
at: December 4, 2018 18:38:51 UTC

Convert to timestamp so we can alert 1 hr in advance:

alert at: {{ as_timestamp(state_attr(‘sensor.next_launch’, ‘launch_time’)) }}
alert at: None

No go. The best solution would be if the component could give us a timestamp, but can someone help me convert the date?


#2

I think that i found a solution.
alert at: {{ as_timestamp(strptime(state_attr('sensor.next_launch', 'launch_time'), '%B %d, %Y %H:%M:%S %Z')) }}


#3

Nice, and then we can start the stream on our TVs.


#4

Thanks. This is what I ended up with:

  • id: launchalert
    alias: ‘Notify 1 hr before next rocket launch’
    trigger:
    • platform: time
      minutes: ‘/60’
      seconds: 00
      condition:
    • condition: template
      value_template: >-
      {%- if (as_timestamp(now()) > (as_timestamp(strptime(states.sensor.next_launch.attributes.launch_time, ‘%B %d, %Y %H:%M:%S %Z’)) - 3600)) and ( as_timestamp( strptime(states.sensor.next_launch.attributes.launch_time, ‘%B %d, %Y %H:%M:%S %Z’) ) ) - ( as_timestamp( now() ) > 0 ) -%}
      true
      {%- endif -%}
      action:
    • service_template: notify.telegramchannel
      data_template:
      title: “Oppskytning om under en time”
      message: “Oppskytning av {{ states.sensor.next_launch.attributes.agency }} kl {{ states.sensor.next_launch.attributes.launch_time }}. Se {{ states.sensor.next_launch.attributes.stream }}.”

Will tune it a bit. Timezone adjustments i.e.


#5

It would be nice to have also a lovelace card with a countdown of the launch. maybe next week I’ll look into how to do it


#6

Hey @lars1 I am using @jones custom component SpaceX sensors: Starman and next rocket launch for the SpaceX launches, but I can’t see the to get the notifications working for me from his script.

I have seen your setup, but I am not too good with templating. I have tried to modify it to matches the sensor and time format, but I can’t quite seem to get it right. Don’t suppose if you have a spare moment, you would might seeing where I might have gone wrong or something.

value_template: >-
{%- if (as_timestamp(now()) > (as_timestamp(strptime(states.sensor.spacex.state, ‘%M:%S’)) - 3600)) and ( as_timestamp( strptime(states.sensor.spacex.state, ‘%M:%S’) ) ) - ( as_timestamp( now() ) > 0 ) -%}
true
{%- endif -%}

It just use’s a time rather than date and year and month

although the main sensor uses this for it’s time.

spacextime

Many thanks in advance if you can help out.


#7

From what i can see, sensor.spacex is a UNIX time. Since as_timestamp(now()) will give you another UNIX time, you can simply compare these two values.
Try to do something like this

{% if as_timestamp(now()) > states(‘sensor.spacex’) - 3600 %}
True
{% else %}
False
{% endif %}


#8

Awesome, thank you very much @marco9446 Will have a play around :slight_smile: