Updated README

main
Stuart Lamont 3 years ago
parent 4cfc8e5db9
commit d30e4081df

@ -0,0 +1,45 @@
# Hive Mind Automation - Video - Getting a Briefing from your Smart Home in Home Assistant
## Preface
This serves as supplemental information for the Hive Mind Automation YouTube Video
[Create a Daily Briefing with Home Assistant]()
It contains code snippets of Jinja2 Templates used in the announcements, and I've added a `scripts.yaml` file so you can see how I use it in my setup.
I've broken the scripts into individual snippets to be triggered by the automation.
Reference materials are available at:
[Time Announcement](./time.md)
[Weather - Temperature](./weatherTemperature.md)
[Weather - Wind](./weatherWind.md)
[Inside Temperatures](./inside%20temps.md)
[Dad Joke, Quote and Random Fact](./fun.md)
[Pending Updates](./pending%20updates.md)
## Script Contents
The Basis of each Script in Home Assistant is:
```
service: notify.alexa_media
data:
data:
type: tts
message: "
<YOUR TEMPLATED MESSAGE HERE>
"
target:
- media_player.dining_room_echo_plus
- media_player.bedroom_echo_dot
- media_player.office_echo_dot
- media_player.spare_room_echo_dot
```
Where we'll then swap out `<YOUR TEMPLATED MESSAGE HERE>` for what we want to actually say.
In this case, I'm using the Alexa Media ACS add-on, but you could reasonably use this with Google home, or ANY text to speech engine from Home Assistant, including

@ -1,188 +0,0 @@
# Home Assistant Jinja 2 Templates for Weather Temperatures
## Step-by-step
### Get the current Temperature from Home Assistant
We're casting this as a float, probably no need, but I'd rather be safe.
```
{% set current_temp = state_attr ('weather.home','temperature') | float %}
```
### Get the current weather condition from Home Assistant as well
```
{% set current_condition = states('weather.home') %}
```
### Fix the current Condition
When the Current weather condition is "Partly Cloudy" the default weather integration returns `partlycloudy` and it sounds odd when read out by a Text to Speech engine.
To fix it I added:
```
{% if current_condition == 'partlycloudy' %}
{% set current_condition = 'Partly Cloudy' %}
{% endif %}
```
## Announce the current condition and Temperature
```
Outside, It's {{ current_condition }} and {{ current_temp }} degrees Celsius.
```
## Figure out the Highs and Lows from the forecast
For weather information, I want to know the High and Low temp. This data is strangely not included by default in the default weather integration, so we have to figure it out ourselves.
### Start by Extracting the `forecast` array data into a variable
```
{% set weather = state_attr('weather.home', 'forecast') %}
```
### Instantiate a `high_temp` and `low_temp` variable
We're assigning the temperature from the 0th record in the array to get started.
```
{% set high_temp = weather[0].temperature %}
{% set low_temp = weather[0].templow %}
```
### Iterate through the array and set the `high_temp` or `low_temp` variables accordingly.
I've also added an `if` statement in here to announce if any of the forecast conditions are `rainy` and the `hour` that the rain is forecast for and to tell us to take an umbrella.
I've surrounded that code block with `###########` for clarity
```
{% for entry in weather %}
{% if entry.temperature > high_temp %}
{% set high_temp = entry.temperature %}
{% endif %}
{% if entry.templow < low_temp %}
{% set low_temp = entry.templow %}
{% endif %}
###########
# While we're here, if the condition for this hour is `rainy` let's announce that
{% if entry.condition == 'rainy'%}
It looks like there's rain expected at around {{ entry.datetime.split('T')[1][:2] }} o'clock.
You might want to take an umbrella if you're leaving the house.
{% endif %}
###########
{% endfor %}
```
### Some Qualitative statements about the `high_temp`
This code block looks at the `high_temp` variable and runs the if statement below to make a qualitative statement about it.
These have been built for °C and I pulled the qualitative statements out of my head.
Change them as you need to
`Above 30°C` say "It's going to be a hot one"
`between 20°C and 30°C` say "It should be a warm day"
`between 15°C and 20°C` say "It's going to be a pretty mild temperature today"
`between 10°C and 15°C` say "It seems like it'll be a bit chilly today"
`between 0°C and 10°C` say "It's going to be a cold day"
else: the `high_temp` variable must be < 0°C
`< 0°C` say "It's going to be freezing today"
```
{% if high_temp > 30 %}
It's going to be a hot one
{% elif 20 < high_temp < 30 %}
It should be a warm day
{% elif 15 < high_temp < 20 %}
It's going to be a pretty mild temperature today
{% elif 10 < high_temp < 15 %}
It seems like it'll be a bit chilly today
{% elif 0 < high_temp < 10 %}
It's going to be a cold day
{% else %}
It's going to be freezing today
{% endif %}
```
### Announce the `high_temp` and `low_temp` values
Again, built for °C
```
The forecast high is {{ high_temp }} °C.
With a Low of {{ low_temp }} °C .
```
### Some qualitative statements about the `low_temp`
Again we're looking at °C and the statements and ranges are arbitrary, and can be adjusted to your tastes
Remember these are for the `low_temp` variable, so it's not going to get colder than these
`Above 30°C` say "Wow. That's hot!"
`between 20°C and 30°C` say "it's not going to get below 20°C toda.y"
`between 10°C and 20°C` say "it might get a little bit chilly."
`between 0°C and 10°C` say "That's cold."
`< 0°C` say "Absolutely freezing!"
Puntuation like `.`, `!`, `?` and `,` is important in the text to speech statments so the timing sounds "natural"
```
{% if low_temp > 30 %}
Wow. That's hot!
{% elif 20 < low_temp < 30 %}
it's not going to go below 20°C today.
{% elif 10 < low_temp < 20 %}
it might get a little bit chilly.
{% elif 0 < low_temp < 10 %}
That's cold.
{% else %}
Absolutely freezing!
{% endif %}
```
## Now we can put it all together:
```
{% set current_temp = state_attr ('weather.home','temperature') | float %}
{% set current_condition = states('weather.home') %}
{% if current_condition == 'partlycloudy' %}
{% set current_condition = 'Partly Cloudy' %}
{% endif %}
Outside, It's {{ current_condition }} and {{ current_temp }} degrees Celsius.
{% set weather = state_attr('weather.home', 'forecast') %}
{% set high_temp = weather[0].temperature %}
{% set low_temp = weather[0].templow %}
{% for entry in weather %}
{% if entry.temperature > high_temp %}
{% set high_temp = entry.temperature %}
{% endif %}
{% if entry.templow < low_temp %}
{% set low_temp = entry.templow %}
{% endif %}
{% if entry.condition == 'rainy'%}
It looks like there's rain expected at around {{ entry.datetime.split('T')[1][:2] }} o'clock. You might want to take an umbrella if you're leaving the house.
{% endif %}
{% endfor %}
{% if high_temp > 30 %}
It's going to be a hot one
{% elif 20 < high_temp < 30 %}
It should be a warm day
{% elif 15 < high_temp < 20 %}
It's going to be a pretty mild temperature today
{% elif 10 < high_temp < 15 %}
It seems like it'll be a bit chilly today
{% elif 0 < high_temp < 10 %}
It's going to be a cold day
{% else %}
It's going to be freezing today
{% endif %}
The forecast high is {{ high_temp }} °C.
With a Low of {{ low_temp }} °C .
{% if low_temp > 30 %}
Wow. That's hot!
{% elif 20 < low_temp < 30 %}
it's not going to go below 20 degrees today.
{% elif 10 < low_temp < 20 %}
it might get a little bit chilly.
{% elif 0 < low_temp < 10 %}
That's cold.
{% else %}
Absolutely freezing!
{% endif %}
```

@ -1,56 +0,0 @@
# Home Assistant Jinja Templating to anmnounce Wind Details
## get the current wind speed and wind bearing in degrees from Home Assistant
```
{% set wind_bearing = state_attr('weather.home', 'wind_bearing') | float %}
{% set wind_speed = state_attr('weather.home','wind_speed') | float %}
```
## This array is a list of Cardinal Directions allowing us to convert the
```
{% set directions = {
(0.0, 11.25): 'North',
(11.25, 33.75): 'North North East',
(33.75, 56.25): 'North East',
(56.25, 78.75): 'East North East',
(78.75, 101.25): 'East',
(101.25, 123.75): 'East South East',
(123.75, 146.25): 'South Eeast',
(146.25, 168.75): 'South South East',
(168.75, 191.25): 'South',
(191.25, 213.75): 'South South West',
(213.75, 236.25): 'South West',
(236.25, 258.75): 'West South West',
(258.75, 281.25): 'West',
(281.25, 303.75): 'West North West',
(303.75, 326.25): 'North West',
(326.25, 348.75): 'North Nort West',
(348.75, 360.0): 'North'
} %}
```
## Announce a qualitative description of wind speed
```
{% if wind_speed > 50 %}
Its very windy outside.
{% elif 40 < wind_speed < 50 %}
It's pretty windy at the moment
{% elif 30 < wind_speed < 40 %}
Theres a strong breeze right now
{% elif 20 < wind_speed < 30 %}
It's a bit breezy outside
{% elif 10 < wind_speed < 20 %}
There's a light breeze
{% else %}
it's quite still
{% endif %}
```
###
```
{% for rng, direction in directions.items() %}
{% if wind_bearing >= rng[0] and wind_bearing < rng[1] %}
The wind is currently blowing from the {{ direction }} direction, at {{ wind_speed }} kilometres per hour
{% endif %}
{% endfor %}
```
Loading…
Cancel
Save

Powered by TurnKey Linux.