Skip to content

Instantly share code, notes, and snippets.

@bartclone
Created November 28, 2021 11:55
Show Gist options
  • Save bartclone/627c70f23116ae9cf78d0040aa6852fb to your computer and use it in GitHub Desktop.
Save bartclone/627c70f23116ae9cf78d0040aa6852fb to your computer and use it in GitHub Desktop.
Schakel switch als tijdstip max/min temperatuur wordt bereikt (OpenWeather)
##################
# Templates BJK # ==> https://www.home-assistant.io/integrations/template/
##################
template:
- binary_sensor:
- name: "Time Max Temperature Reached" # time_max_temperature_reached
state: >
{{ as_timestamp(now())|timestamp_custom('%H:%M')|string()
== states('sensor.time_max_temperature')|string() }}
- name: "Time Min Temperature Reached" # time_min_temperature_reached
state: >
{{ as_timestamp(now())|timestamp_custom('%H:%M')|string()
== states('sensor.time_min_temperature')|string() }}
trigger:
- platform: time_pattern
# Update time of max every 4h
hours: "/4"
- platform: event # reload when scenes or automations are updated
event_type:
- automation_reloaded
- scene_reloaded
sensor:
#
# what time (HH:MM) is forecasted to have max temperature
#
- name: "Time Max Temperature" # time_max_temperature
unit_of_measurement: "h"
state: >
{% set start = now().replace(hour=0,minute=0,second=0, microsecond=0) %}
{% set end = (start + timedelta(days=1)) %}
{% set start = start.strftime("%Y-%m-%dT%H:%M:%S+00:00") %}
{% set end = end.strftime("%Y-%m-%dT%H:%M:%S+00:00") %}
{% set ns = namespace(max_temp=-100, max_temp_datetime=datetime) %}
{% for i in state_attr('weather.openweathermap', 'forecast') -%}
{% if start <= i.datetime < end %}
{% if i.temperature > ns.max_temp %}
{% set ns.max_temp = i.temperature %}
{% set ns.max_temp_datetime = i.datetime %}
{% endif %}
{% endif %}
{% endfor %}
{{ as_timestamp(ns.max_temp_datetime)|timestamp_custom('%H:%M') }}
#
# what hour is forecasted to have min temperature?
#
- name: "Time Min Temperature" # time_min_temperature
unit_of_measurement: "h"
state: >
{% set start = now().replace(hour=0,minute=0,second=0, microsecond=0) %}
{% set end = (start + timedelta(days=1)) %}
{% set start = start.strftime("%Y-%m-%dT%H:%M:%S+00:00") %}
{% set end = end.strftime("%Y-%m-%dT%H:%M:%S+00:00") %}
{% set ns = namespace(min_temp=100, min_temp_datetime=datetime) %}
{% for i in state_attr('weather.openweathermap', 'forecast') -%}
{% if start <= i.datetime < end %}
{% if i.temperature < ns.min_temp %}
{% set ns.min_temp = i.temperature %}
{% set ns.min_temp_datetime = i.datetime %}
{% endif %}
{% endif %}
{% endfor %}
{{ as_timestamp(ns.min_temp_datetime)|timestamp_custom('%H:%M') }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment