Precip observations (rain, soil temperature, soil moisture) work well as Home Assistant sensors. Personal API keys are included with any Precip plan.
REST sensors (manual)
The REST Sensor integration works out of the box. Replace YOUR_API_KEY and the coordinates. An example from Dima Tokar's write-up is provided below.
sensor:
- platform: rest
name: "Rainfall last 48 Hours"
resource: "https://api.precip.ai/api/v1/last-48?longitude=-122.4194&latitude=37.7749&format=json"
method: GET
headers:
Authorization: "Bearer YOUR_API_KEY"
Accept: "application/json"
scan_interval: 3600
value_template: >
{% if value_json is iterable and value_json | length > 0 %}
{{ value_json[0].rain | float(0) }}
{% else %}
0
{% endif %}
unit_of_measurement: "mm"
icon: "mdi:weather-rainy"
unique_id: "rainfall_last_48h"
state_class: measurement
device_class: precipitation
- platform: rest
name: "Soil temperature upper 10 cm"
resource: "https://api.precip.ai/api/v1/temp-0-10cm-hourly?longitude=-122.4194&latitude=37.7749&start={{ (now() - timedelta(days=1)).strftime('%Y-%m-%d') }}&end={{ now().strftime('%Y-%m-%d') }}&format=json"
method: GET
headers:
Authorization: "Bearer YOUR_API_KEY"
Accept: "application/json"
scan_interval: 3600
value_template: >
{% set data = value_json[0].hours %}
{% if data is iterable and data | length > 0 %}
{{ data[-1]['soil_temp'] | float(0) }}
{% else %}
0
{% endif %}
unit_of_measurement: "°C"
icon: "mdi:thermometer"
unique_id: "soil_temp_0_10cm"
state_class: measurement
device_class: temperature
Personal keys allow 100 requests per day. Two REST sensors polled once per hour use 48 requests per day.
Last modified on