Last active
January 9, 2022 21:48
-
-
Save tathamoddie/8fcc0117b17dbd3fe0447a2e6a5a4705 to your computer and use it in GitHub Desktop.
Home Assistant Australian RAT Finder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Per https://www.home-assistant.io/docs/configuration/packages/#create-a-packages-folder | |
homeassistant: | |
packages: !include_dir_named packages |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# packages/rat_finder.yaml | |
# Expects a notify.everyone service, per https://companion.home-assistant.io/docs/notifications/notifications-basic/#sending-notifications-to-multiple-devices | |
input_number: | |
rat_search_range: | |
name: RAT Search Range | |
min: 1 | |
max: 20 | |
unit_of_measurement: km | |
rest: | |
- scan_interval: 150 | |
resource: https://sparkling-voice-bdd0.pipelabs-au.workers.dev | |
sensor: | |
- name: Nearby RAT Locations | |
value_template: ' | |
{% set locationsInStock = value_json | selectattr("status", "equalto", "IN_STOCK") | list %} | |
{%- for location in locationsInStock -%} | |
{%- set distanceAway = distance(location.lat, location.lng)|round(2) -%} | |
{%- if (distanceAway < (states("input_number.rat_search_range")|float)) -%} | |
{{ distanceAway }}km: {{ location.name }} | |
{% endif -%} | |
{%- endfor -%}' | |
automation: | |
- id: rats_found | |
alias: "[COVID] RAT Stock Found" | |
trigger: | |
- platform: state | |
entity_id: sensor.nearby_rat_locations | |
condition: | |
- "{{ states('sensor.nearby_rat_locations') != '' }}" | |
action: | |
- service: notify.everyone | |
data: | |
title: "🐀 RAT Nearby" | |
message: "{{ states('sensor.nearby_rat_locations') }}" | |
data: | |
ttl: 0 | |
important: high | |
actions: | |
- action: URI | |
title: Find a RAT | |
uri: https://findarat.com.au/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment