Home-AssistantConfig/config/packages/space.yaml

143 lines
5.5 KiB
YAML
Executable File

#-------------------------------------------
# Space Related Packages
# @CCOSTAN
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
#-------------------------------------------
#------ISS----------------------------------
#-------------------------------------------
binary_sensor:
- platform: iss
show_on_map: true
#-------------------------------------------
sensor:
- platform: launch_library
- 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
# resource: https://raw.githubusercontent.com/cribbstechnologies/ha_config/master/www/test_launch.json
name: launch window
# if the current timestamp is in the launch window
# this sensor will return the UTC timestamp of the launch
value_template: >-
{%- for launch in value_json.launches %}
{% if launch.location.id == 16 or launch.location.id == 17 %}
{% 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 %}
{% endif %}
{% endfor %}
automation:
- alias: Launch Window Approaching
trigger:
- platform: state
entity_id: sensor.launch_window
condition:
- condition: template
value_template: "{{states('sensor.launch_window') != 'unknown'}}"
action:
- wait_template: >-
{{((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!'
apns_id: 'information'
- 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. {{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.
- alias: 'ISS is above Me -Tweet'
trigger:
- platform: state
entity_id:
- binary_sensor.iss
to: 'on'
from: 'off'
action:
- service: script.tweet_engine_image
data_template:
tweet: >-
{{ [
"The ISS is above me right now!",
"The International Space Station flys by once a day & that time is NOW! (For me)",
"I can look up RIGHT NOW and see the International Space Station.",
"The #ISS just flew by and there is 1 Starman driving a #Tesla and {{states.binary_sensor.iss.attributes.number_of_people_in_space}} people in",
"The #ISS just flew by and there are {{states.binary_sensor.iss.attributes.number_of_people_in_space}} people in",
"The International Space Station Rocks! And it's above me RIGHT NOW!"
] | random + " #Space"}}
image: >-
{{ [
"/config/www/custom_ui/floorplan/images/branding/space.png",
"/config/www/custom_ui/floorplan/images/branding/space2.png",
"/config/www/custom_ui/floorplan/images/branding/starman.png"
] | random }}
- alias: 'Full Moon -Tweet'
trigger:
- platform: state
entity_id: sensor.moon
to: 'Full Moon'
action:
- delay: '0{{ (range(1, 5)|random|int) }}:{{ range(0,5) | random | int }}{{ range(0,9) | random | int }}:00'
- service: script.tweet_engine_image
data_template:
tweet: >-
{{ [
"There is a Full Moon out tonight!",
"Wish my solar panels picked up Moon rays. Full Moon out tonight.",
"The moon is huge! And full. ",
"Turn down the lights, there is a Full Moon out tonight.",
"If you want to see the full moon, tonight is the night.",
"Get out your telescopes, it will be a Full Moon out tonight!",
"Not a half moon, Not a quarter moon. There is a FULL moon out tonight."
] | random + "#Space"}}
image: >-
{{ [
"/config/www/custom_ui/floorplan/images/branding/moon.png",
"/config/www/custom_ui/floorplan/images/branding/moon2.png",
"/config/www/custom_ui/floorplan/images/branding/moon3.png",
"/config/www/custom_ui/floorplan/images/branding/starman.png"
] | random }}