Unfortunately openweathermap does not offer the daily forecast in the free plan. I would mostly be interested in daily.temperature.max or something like that. Is there any HA weather integration that offers this?
I also found the default 5-day-3-hour forecast is very very bad for my location. Eg for this midnight, it shows 16°C, whereas current nights are never > 10° and any local forecasts confirm that’s below. So anyways I cannot use openweathermap for my case…
For now I solved it as follows: using yr.no with a 4h weather forecast, and evaluation my conditions at 10am in the automation. Then I will receive the temperature approx at the hottest time of the day (2pm). And if threshold is exceeded, I close my blinders.
- name: weather_forecast
platform: yr
forecast: 4
scan_interval: 600
monitored_conditions:
- temperature
- cloudiness
Just for reference: I’m not satisfied with the default OWM implementation in HA. Especially as owm provides a daily report that directly gives out the min/max temperatures for a day. So no need for calculations.
I set up my own sensors using a rest_template as follows:
I like your solution, but I am a bit confused since temp and temp_min/temp_max are always the same in my installation. Now I found this in the OWM API docs:
Please, do not confuse min/max parameters in our weather APIs.
In Current weather API , Hourly forecast API and 5 day / 3 hour forecast API - temp_min and temp_max are optional parameters mean min / max temperature in the city at the current moment just for your reference. For large cities and megalopolises geographically expanded it might be applicable. In most cases both temp_min and temp_max parameters have the same volume as ‘temp’. Please, use temp_min and temp_max parameters in current weather API optionally.
At least for the free subscription plan this might not be what you want?!
PS: Sorry, my mistake. You are using the new One Call API which indeed does provide day min/max temp (daily.temp.min).
Hi, many thanks for the code. It´s generally working. Now I have two requests.
How can I round the decimal of the temp, i.e. 26.45 to 26.5
I tried to modify the api code for using the !secrets=myapikey or !secrets:myapikey implementation without success. How is this possible, is there a solution available?
I did not move the apikey/appid to secrets. Because, if anybody would get knowledge of it, I don’t care. It’s a free service with no personal information.
If you want it in secrets, you have to move the full url to secrets, and then use resource: !secret openweatherurl
Like this solution. Basic question, the I assume need to be replaced by actual values or are these subsituted by HA? If so: where does the apikey come from?
Please forgive my question I am a HA beginner, but how do I integrate your template?
First part in the configuration.yaml and the second as manual automation?
From what I saw, this sensor switches max forecasted temperature around 2am at night.
So I implemented a SQL sensor that queries the max forecasted temperature between current time yesterday and last midnight
(I record my data in a local MariaDB)
# Determine max forecasted temperature for 'today'
- platform: sql
db_url: !secret mariadb_url
queries:
- name: max_temp_fcst_today
query: >
SELECT date(date_add(last_updated, INTERVAL 1 DAY)) AS date, MAX(state) AS max_temp
FROM home_assistant.states
WHERE entity_id = 'sensor.br_temperature_1d'
AND last_updated BETWEEN DATE_ADD(NOW(), INTERVAL -1 DAY) AND CURDATE();
column: max_temp
unit_of_measurement: °C
In other words: I went back into my history to retrieve the forecasted temperature, rather than trying to collect a forecasted temperature for today when I need it.
Another approach if you’re not comfortable with writing SQL statements would be to use an automation that writes the state or attribute of a (sensor) entity into an input_number entity at a given point of time. You can then use this over a certain interval while the source changes.