Trigger automation with Launch Library entity?

Was delighted today to find the “Launch Library” integration today…
… Then bummed when I couldn’t find a way to get an automation to trigger from the time-to-launch sensor.

What does it take to get sensors like those to be exposed as a trigger for an automation?

Use them in a Time trigger…

trigger:
  - platform: time
    at: sensor.next_launch_launch_time

Drew, thanks for the clue. Not trying to be dense, but in what for is that used?

Today I stumbled on your same problem :slight_smile: If you want we can try and solve it together. I will start with this automation and will improve it along the way.
For now this will send a notification when launch time is lest than 1 day (to be honest I dont think this will work but this is a start)

alias: Next Rocket Launch
description: Next Rocket Launch
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.next_launch_launch_time
    below: 1
condition: []
action:
  - data:
      title: Rocket Launch
      message: >-
        Next Launch: {{ states('sensor.next_launch_launch_mission') }}  Time: {{
        states('sensor.next_launch_launch_time') }} Probability: {{
        states('sensor.next_launch_launch_probability') }} Status: {{
        states('sensor.next_launch_launch_status') }}
    service: notify.mobile_app_mi_9t_pro
mode: single

Hey! Just noticed your message, and I’d like to work on that automation with you, as you suggested… just as soon as I fix this @#$!@ WLED problem (hopefully sometime tonight).

That trigger will never fire because the sensor’s state is a datetime string not a number. You could use a numeric state trigger if you added a value_template, but it would be easier to just use a template trigger:

trigger:
  - platform: template
    value_template:  "{{ now() >= states('sensor.next_launch_launch_time')|as_datetime - timedelta(days=1) }}"

Starting from your efforts, I ended up with the following, which gives a 2-hour heads-up:

alias: "Notification: Upcoming Space Launch"
description: ""
trigger:
  - platform: template
    value_template: >-
      {{ now() >= states('sensor.launch_time') | as_datetime -
      timedelta(hours=2) }}
condition:
  - condition: not
    conditions:
      - condition: state
        entity_id: sensor.launch_time
        attribute: stream_live
        state: false
action:
  - action: notify.mobile_app_brendan_galaxy_s22_ultra
    metadata: {}
    data:
      message: Space Launch in 2 hours
      data:
        actions:
          - action: URI
            title: Open Launch info
            uri: /config/devices/device/e0236a78e08cb98ad6ead5744f6d2e1e
mode: single

The main thing I haven’t tested is the “steam_live” attribute. It turns out the stream_live attribute is a timestamp - and is set to false when there is no live stream - so I’ve reversed that logic in my edit above.

The URI given to “Open Launch info” is going to the main service page in HA. I’m sure we could still improve the message slightly so it gives more information.

1 Like