template-diff
39 lines
template:
template:
- trigger:
- trigger:
- platform: state
- platform: state
entity_id: weather.home
entity_id: weather.home
- platform: homeassistant
- platform: homeassistant
event: start
event: start
- platform: time_pattern
- platform: time_pattern
hours: 1
hours: 1
action:
action:
- service: weather.get_forecasts
- service: weather.get_forecasts
data:
data:
type: hourly
type: hourly
target:
target:
entity_id: weather.home
entity_id: weather.home
response_variable: hourly
response_variable: hourly
sensor:
sensor:
- name: Sunny in next 10 hour
- name: Sunny in next 10 hour
unique_id: q_sunny_today
unique_id: q_sunny_today
state: >
state: >
{% set counter = 0 %}
{% set counter = 0 %}
{% set counter2 = 0 %}
{% set counter2 = 0 %}
{% set status = false %}
{% set status = false %}
{% set lstcondition = {{ hourly['weather.home'].forecast[:10].condition | map(attribute='precipitation')}} %}
{% set lstcondition = hourly['weather.home'].forecast[:10] | map(attribute='condition') | list %}
{%- for i in lstcondition if i= "sunny" -%}
{%- for i in lstcondition if i == "sunny" -%}
{{ counter + 1 }}
{% set counter = counter + 1 %}
{% if loop.length >= 4 and loop.first -%}
{% if loop.length >= 4 and loop.first %}
true
{{ true }}
{% endif -%}
{% endif %}
{%- endfor-%}
{%- endfor -%}
{%- for i in lstcondition if i= "partlycloudy" -%}
{%- for i in lstcondition if i == "partlycloudy" -%}
{{ counter2 + 1 }}
{% set counter2 = counter2 + 1 %}
{% if loop.length >= 8 and loop.first -%}
{% if loop.length >= 8 and loop.first %}
true
{{ true }}
{% endif -%}
{% endif %}
{%- endfor-%}
{%- endfor -%}
{% if counter + (counter2/2) >= 4 %}
{% if counter + (counter2 / 2) >= 4 %}
true
{{ true }}
{% else %}
{{ false }}
{% endif %}
{% endif %}