You can’t convert datetime to an int without using a forloop, so if you want to keep your code the way it is, you need to adjust {% set end = start + 86400000 %} to be a datetime string. And to configure that line, we’d need to know the format of datetime.
EDIT: to further clarify, post a screenshot of your attributes for weather.home
Just wanted to thank DaveH for this. Just what I was looking for. Well, almost.
Here is the code modified for Open Weather Map showing minimum temp today with a second sensor for showing minimum forecast temperature over the next 24 hours which I plan to use as a frost warning for garden plant protection purposes
template:
- sensor:
- name: "Today Minimum Temperature"
unique_id: "today_minimum_temperature"
device_class: temperature
unit_of_measurement: "°C"
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") %}
{{ state_attr('weather.openweathermap', 'forecast') | selectattr('datetime', '>=', start) | selectattr('datetime','<=', end) | map(attribute='temperature') | list | min }}
#
- sensor:
- name: "24H Minimum Temperature"
unique_id: "24h_minimum_temperature"
device_class: temperature
unit_of_measurement: "°C"
state: >
{% set start = now() %}
{% 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") %}
{{ state_attr('weather.openweathermap', 'forecast') | selectattr('datetime', '>=', start) | selectattr('datetime','<=', end) | map(attribute='temperature') | list | min }}