Skip to content

Commit

Permalink
Imrpove rain notification automation
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Kissling committed Jun 17, 2024
1 parent 2b88883 commit 2538137
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
12 changes: 11 additions & 1 deletion automations/weather.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@
message: >
{% if is_state('binary_sensor.weather_raining', 'on') %}
Current rate: {{ states('sensor.gw1100a_rain_rate') }} mm/m2.
Last rain was {{ trigger.from_state.state / 60 }} hours ago.
Last rain was {{ (trigger.from_state.state | int / 60) | round }} hours ago.
{% else %}
The rain has stopped after {{ trigger.from_state.state }} minutes.
{% endif %}
- alias: Weather - last_rain_not_rain_change - Update
trigger:
platform: state
entity_id: binary_sensor.weather_raining
action:
service: input_datetime.set_datetime
entity_id: input_datetime.last_rain_not_rain_change
data:
datetime: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
2 changes: 1 addition & 1 deletion binary_sensors/weather.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
sensors:
weather_raining:
value_template: "{{ states('sensor.gw1100a_rain_rate') | float > 0 }}"
delay_off: 00:02:00
delay_off: 00:10:00
5 changes: 5 additions & 0 deletions input_datetimes/weather.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---

last_rain_not_rain_change:
has_date: true
has_time: true
2 changes: 1 addition & 1 deletion sensors/weather.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
weather_rain_not_rain_duration:
unit_of_measurement: "min"
value_template: >
{% set rain_start = states.binary_sensor.weather_raining.last_changed %}
{% set rain_start = states('input_datetime.last_rain_not_rain_change') | as_datetime | as_local %}
{% set rain_end = now() %}
{{ ((rain_end - rain_start).total_seconds() / 60) | round(0) }}

0 comments on commit 2538137

Please sign in to comment.