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.
I have a similar problem as others. I would like to use our local weather forecast from switzerland (HACS, Meteoswiss integration).
Using the template editor in development tools with the template {{ states.weather.basel_binningen }}, I get the following response:
My question as a template newbie: How do I get the forecast temperature of the next day out of this with a template? I assume this must be the the temperature in forecast[0], but this is how far I get
Hi,
I’ve managed to use the weather.xxx_hourly entity to get the forecast for the current day.
Fist you need to head over to Integrations, select Home. There will be a disabled entity for an hourly forecast, enable it.
You can then use the same array notation, but it will give you the forecast for the hour you indicate rather than the day… {{ state_attr('weather.xxx_hourly', 'forecast')[4].temperature }}
This is a late reply, but might help somebody.
I’d suggest to use NodeRed which can manipulate data and create a node sensor that will provide you with the desired data.
Step 1) Extract the desired attributes and create a separate entity for them.
Configuration.yaml:
template:
- sensor:
- name: Forecasted Precipitation
unit_of_measurement: "mm"
state: "{{ state_attr('weather.forecast_hourly', 'forecast')[0].precipitation }}"
- name: Forecasted Temperature Tomorrow
unit_of_measurement: "°C"
state: "{{ state_attr('weather.forecast', 'forecast')[1].temperature }}"
- name: Forecasted Temperature Day after Tomorrow
unit_of_measurement: "°C"
state: "{{ state_attr('weather.forecast', 'forecast')[2].temperature }}"
Step 2) Create an automation
alias: Sunscreen out to prevent heating the house on warm days
description: ""
trigger:
- platform: numeric_state
entity_id: sun.sun
attribute: azimuth
above: 119
alias: Before the sun hits the house on the South side.
condition:
- condition: or
conditions:
- condition: state
entity_id: sensor.season
state: spring
- condition: state
entity_id: sensor.season
state: summer
alias: During spring and summer;
- condition: and
conditions:
- condition: numeric_state
entity_id: sensor.forecasted_temperature_day_after_tomorrow
above: 21
- condition: numeric_state
entity_id: sensor.forecasted_temperature_tomorrow
above: 21
alias: When the next two days are forecasted to be warmer than inside;
- condition: numeric_state
entity_id: sensor.forecasted_precipitation
below: 0.1
alias: When no rain is to be expected in the next hour;
- condition: numeric_state
entity_id: weather.forecast_hourly
attribute: wind_speed
enabled: true
below: 5.1
alias: With not to much wind expected in the next hour (meters per second);
- condition: device
# Device_id is generated for you if you use build the automation using the UI.
device_id: 6afa398809a08778afda1b614e
domain: cover
entity_id: cover.sunscreen
type: is_position
enabled: true
below: 40
alias: When the sunscreen is not opened already;
- condition: numeric_state
entity_id: zone.home
enabled: true
above: 0
alias: When somebody is home.
action:
- device_id: 6afa398809a08778afda1b614e
domain: cover
entity_id: cover.sunscreen
type: set_position
position: 41
alias: Open sunscreen a bit to prevent warming the house!
mode: single
HINT: Use something you use to perform easy tests as an additional trigger such as a button/switch during testing.
I created a automation and lovelace card for controling my awning/sunscreen,
Hope to help and inspire others: GitHub - remb0/Sunscreen: Sunscreen-Awning project
It’s work in progress and I have a wishlist with things like: actionable notifications, blueprint, shutter integration and other improvements.