Last active
June 6, 2024 03:46
-
-
Save skrashevich/a181955d14e9bb9c1ffbab3a94569600 to your computer and use it in GitHub Desktop.
OpenWeatherMap sender
This file contains 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
blueprint: | |
name: Send Weather Data to OpenWeatherMap (v0.1.3.2) | |
source_url: https://gist.github.com/skrashevich/a181955d14e9bb9c1ffbab3a94569600 | |
description: Automate sending weather data to OpenWeatherMap every 15 minutes. | |
domain: automation | |
input: | |
api_key: | |
name: API Key | |
description: Your OpenWeatherMap API Key | |
selector: | |
text: {} | |
temperature_sensor: | |
name: Temperature Sensor | |
description: Sensor entity for temperature (optional) | |
selector: | |
entity: | |
domain: sensor | |
default: '' | |
wind_speed_sensor: | |
name: Wind Speed Sensor | |
description: Sensor entity for wind speed (optional) | |
selector: | |
entity: | |
domain: sensor | |
default: '' | |
pressure_sensor: | |
name: Pressure Sensor | |
description: Sensor entity for pressure (optional) | |
selector: | |
entity: | |
domain: sensor | |
default: '' | |
humidity_sensor: | |
name: Humidity Sensor | |
description: Sensor entity for humidity (optional) | |
selector: | |
entity: | |
domain: sensor | |
default: '' | |
station_id: | |
name: Station ID | |
description: The ID of the weather station | |
selector: | |
text: {} | |
trigger: | |
- platform: time_pattern | |
minutes: "/15" | |
condition: [] | |
action: | |
- choose: | |
- conditions: | |
- condition: template | |
value_template: "{{ not states('input_text.station_id') }}" | |
sequence: | |
- service: rest_command.create_station | |
data: | |
api_key: !input api_key | |
- service: rest_command.send_weather_data | |
data: | |
api_key: !input api_key | |
station_id: !input station_id | |
temperature: "{{ states(!input.temperature_sensor) if is_state(!input.temperature_sensor, '') else 'null' }}" | |
wind_speed: "{{ states(!input.wind_speed_sensor) if is_state(!input.wind_speed_sensor, '') else 'null' }}" | |
pressure: "{{ states(!input.pressure_sensor) if is_state(!input.pressure_sensor, '') else 'null' }}" | |
humidity: "{{ states(!input.humidity_sensor) if is_state(!input.humidity_sensor, '') else 'null' }}" | |
rest_command: | |
create_station: | |
url: "http://api.openweathermap.org/data/3.0/stations?appid={{ api_key }}" | |
method: POST | |
headers: | |
Content-Type: application/json | |
payload: > | |
{ | |
"external_id": "home_assistant_station", | |
"name": "Home Assistant Weather Station", | |
"latitude": {{ state_attr('zone.home', 'latitude') }}, | |
"longitude": {{ state_attr('zone.home', 'longitude') }}, | |
"altitude": 0, | |
"metadata": { | |
"created": {{ now().timestamp() | int }} | |
} | |
} | |
content_type: "application/json" | |
send_weather_data: | |
url: "http://api.openweathermap.org/data/3.0/measurements?appid={{ api_key }}" | |
method: POST | |
headers: | |
Content-Type: application/json | |
payload: > | |
[ | |
{ | |
"station_id": "{{ station_id }}", | |
"dt": {{ now().timestamp() | int }}, | |
"temperature": {{ temperature }}, | |
"wind_speed": {{ wind_speed }}, | |
"pressure": {{ pressure }}, | |
"humidity": {{ humidity }} | |
} | |
] | |
content_type: "application/json" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment