# Using openweathermap forecast for today and tomorrow ([0] and [1])
rainy_day:
friendly_name: "Rainy in next 48 Hours"
value_template: >-
{% set p0 = state_attr('weather.openweathermap', 'forecast[0].precipitation') == None %}
{% set p1 = state_attr('weather.openweathermap', 'forecast[1].precipitation') == None %}
{{ 'false' if p0 and p1 else 'true' }}
automation.yaml
- id: '1560827530261'
alias: Switch Walkway Sprinkler
trigger:
# Start watering at 6AM
- at: 06:00:00
platform: time
condition:
- condition: state
entity_id: sensor.rainy_day
state: 'false'
- condition: time
# only on below weekdays
weekday:
- mon
- wed
- fri
action:
- data:
entity_id: switch.walkway_sprinkler
service: switch.turn_on
# Water for 15 Minutes
- delay: 00:15:00
- data:
entity_id: switch.walkway_sprinkler
service: switch.turn_off
Glad to hear that the latest version of the template works correctly for you.
To make it easier for others seeking a similar solution, please mark my previous post (the one containing the two functional versions of the template) as the ‘Solution’ (only the author of a topic can mark a post with this tag). After you do that, a link to the ‘Solution’ post will automatically appear under your first post.
Trying to implement your logic. When I run the following in Template Editor
p0 is {{ states.weather.openweathermap.attributes.forecast[0].precipitation }}
p1 is {{ states.weather.openweathermap.attributes.forecast[1].precipitation }}
result is
p0 is None
p1 is 0.6
When I run this in Template Editor from your sensor.yam
{% set p0 = state_attr(‘weather.openweathermap’, ‘forecast[0].precipitation’) == None %}
{% set p1 = state_attr(‘weather.openweathermap’, ‘forecast[1].precipitation’) == None %}
{{ ‘false’ if p0 and p1 else ‘true’ }}
the result is
false
Shouldn’t I be getting true since I am showing 0.6 for p1 in the first result? I am not clear what the 0.6 represents?
when there will be no rain (precipitation) then the result is None and in my logic when there is no rain today or tomorrow then it will send false, otherwise you get true.
precipitation result represents the amount of rain.
e.g.
Light Rain: A rain rate of 0.10 inches per hour or less
Rain: A rain rate of 0.11 to 0.30 inches per hour
Heavy Rain: A rain rate of 0.31 inches per hour or greater.
I just updated my logic to below and it’s working for me
{% set p0 = state_attr('weather.openweathermap', 'forecast')[0].precipitation != None %}
{% set p1 = state_attr('weather.openweathermap', 'forecast')[1].precipitation != None %}
{{ 'true' if p0 or p1 else 'false' }}
so if today or tomorrow precipitation result exists you will get true and the last line is checking if there is a true for today OR tomorrow.
there are many different paths you can take like instead of using precipitation you can use condition
{% set p0 = state_attr('weather.openweathermap', 'forecast')[0].condition == "rainy" %}
{% set p1 = state_attr('weather.openweathermap', 'forecast')[1].condition == "rainy" %}
{{ 'true' if p0 or p1 else 'false' }}
Hey Armin. I’ve just moved OWM over to the integration under 0.115.2 and I’ve lost sensor.openweathermap_forecast_precipitation and sensor.openweathermap_forecast_temperature_low. Have you see that too?
Thank you to @arvage and @123 for this post. I’m new to HA (and Python, YAML, Jinja and the template language) so this post helped me a lot in getting my watering system going. I ran into a few problems and I thought I’d share the details in case it helps any other newbies.
The first problem is that (for me) forecast precipitation is always null so the only useful forecast value is condition, I’m using the next 4 days with this code:
- platform: template
sensors:
rainy_day:
friendly_name: "Rain in next 48 Hours"
value_template: >-
{% set p0 = state_attr('weather.openweathermap', 'forecast')[0].condition == 'rainy' %}
{% set p1 = state_attr('weather.openweathermap', 'forecast')[1].condition == 'rainy' %}
{% set p2 = state_attr('weather.openweathermap', 'forecast')[2].condition == 'rainy' %}
{% set p3 = state_attr('weather.openweathermap', 'forecast')[3].condition == 'rainy' %}
{{ 'Yes' if p0 or p1 or p2 or p3 else 'No' }}
I put the pull request and they were working on It. Not sure if it’s been applied to the HA yet. I’m getting null on precipitation which is correct for when there is no rain so maybe they did. I have to check.