I created a card to help with outdoor water use, aimed around figuring out if it’s okay to water the lawn or wash the car, taking into account:
- my city’s summer water restrictions (only water on even/odd days)
- if it’s going to rain soon
Binary Sensor
First this needs a binary sensor outdoor_water_use
, which has one of 3 states:
-
Allowed
- Allowed to use water today -
Restricted
- City restricts water use today -
Unrestricted
- During the part of the year where there are no restrictions
This also looks at weather.home.forcecast
and finds the next time it’s going to rain more than 2mm, then stores two attributes:
-
next_rain
- the next forecast value with rain, ornull
-
rain_text
- the text showing when it will rain next
friendly_name: 'Outdoor Water Usage'
value_template: |
{{ is_state_attr('binary_sensor.outdoor_water_use', 'restriction', 'Restricted') == false }}
icon_template: |
{% set restriction = state_attr('binary_sensor.outdoor_water_use', 'restriction') %}
{% if restriction == 'Restricted' %}
mdi:water-pump-off
{% else %}
{% if state_attr('binary_sensor.outdoor_water_use', 'next_rain') %}
mdi:weather-rainy
{% else %}
mdi:water-pump
{% endif %}
{% endif %}
attribute_templates:
next_rain: |
{%- set ns = namespace(nextRain=null) -%}
{%- for forecast in state_attr('weather.home', 'forecast') -%}
{%- if ns.nextRain == null and forecast.precipitation > 2 -%}
{%- set ns.nextRain = forecast -%}
{%- endif -%}
{%- endfor -%}
{{ ns.nextRain }}
rain_text: |
{% set rain = state_attr('binary_sensor.outdoor_water_use', 'next_rain') %}
{% if rain %}
{{ rain.condition|title }} ({{ rain.precipitation }} mm) on {{ rain.datetime| as_timestamp | timestamp_custom('%A',true) }}
{% else %}
No rain forecast for next {{ state_attr('weather.home', 'forecast')|length }} days
{% endif %}
restriction: |
{## restricted from June 15 (day 166) to Sept 15 (day 258) -- ignoring leap years ##}
{% set now_timestamp = now()|as_timestamp %}
{% set dayOfYear = now_timestamp|timestamp_custom('%j')|int %}
{% set restrictionsInEffect = dayOfYear >= 166 and dayOfYear <= 258 %}
{% if restrictionsInEffect %}
{% set isOdd = (now_timestamp|timestamp_custom('%d')|int % 2) == 1 %}
{% if isOdd %}
Allowed
{% else %}
Restricted
{% endif %}
{% else %}
Unrestricted
{% endif %}
You’ll need to modify a couple things in the restriction
property:
- Update the restriction start/stop days, eg: June 15 (day 166) to Sept 15 (day 258)
- I was allowed to water on odd days – if you are even days, flip the
Allowed
andRestricted
values in theif isOdd
statement
Lovelace card
The card uses template-entity-row:
type: 'custom:template-entity-row'
entity: binary_sensor.outdoor_water_use
active: >
{{ state_attr('binary_sensor.outdoor_water_use', 'next_rain') == null and
is_state('binary_sensor.outdoor_water_use', 'on') }}
secondary: |
{{ state_attr('binary_sensor.outdoor_water_use', 'rain_text') }}
state: Allowed