@ -19,12 +19,6 @@ Reference materials are available at:
[Dad Joke, Quote and Random Fact](./fun.md)
[Pending Updates](./pending%20updates.md)
## Script Contents
The Basis of each Script in Home Assistant is:
```
@ -42,4 +36,10 @@ data:
- 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
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
## TO-DO's
- Turn multi-value outputs into an array of dictionaries/tuples and run through the template in a for loop.
{% 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 %}
{% if wind_speed > 50 %}
Its very windy outside.
{% 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 %}
Inside it's currently {{ states('sensor.temperature_dining') }} °C in the Dining Room,
{{ states('sensor.lounge_ac_inside_temperature') }} °C in the Lounge,
{{ states('sensor.temperature_office')}} °C in the office,
and {{ states('sensor.master_bedroom_purifier_temperature') }} °C in the Master Bedroom.
The {{ state_attr( 'sensor.quote_sensor', 'category' ) }} Quote of the day is by {{ state_attr( 'sensor.quote_sensor', 'author' ) }}.
They said. {{ states('sensor.quote_sensor') }}
Here is a Dad Joke.. {{ states('sensor.dad_joke_of_the_hour') }}
And a random fact.. {{ states('sensor.random_fact') }}
{% if states('update.home_assistant_operating_system_update') == 'off' %}
There's a Home Assistant O S Update pending.
The Installed version is {{ state_attr('update.home_assistant_operating_system_update', 'installed_version') }}
The Available version is {{ state_attr('update.home_assistant_operating_system_update', 'latest_version') }}
{% endif %}
{% if states('update.home_assistant_core_update') == 'off' %}
There's a Home Assistant Core Update pending.
The Installed version is {{ state_attr('update.home_assistant_core_update', 'installed_version') }}
The Available version is {{ state_attr('update.home_assistant_core_update', 'latest_version') }}
{% endif %}
{% if states('update.esphome_update') == 'off' %}
There's an E S P Home Update pending.
The Installed version is {{ state_attr('update.esphome_update', 'installed_version') }}
The Available version is {{ state_attr('update.esphome_update', 'latest_version') }}
{% endif %}
```
__Abstract it all:__
Break it all into Scripts and trigger them in sequence with the Automation.
So for the quote, I want to know the "Category" of quote.
There's a list of categories in the [API Documentation](https://api-ninjas.com/api/quotes).
Expect results like:
@ -125,13 +127,28 @@ And lastly, obviously, the quote:
```
They said. {{ states('sensor.quote_sensor') }}
```
Put altogether, it looks like this.
```
The {{ state_attr( 'sensor.quote_sensor', 'category' ) }} Quote of the day is by {{ state_attr( 'sensor.quote_sensor', 'author' ) }}.
They said. {{ states('sensor.quote_sensor') }}
```
### Now for a Dad Joke
This one is easy. We only need the state of the sensor entity we created:
```
Here is a Dad Joke.. {{ states('sensor.dad_joke_of_the_hour') }}
```
The double stop in the template here adds an additional slight pause to the end of "Here is a Dad Joke". It just seemed to flow better out of the Text To Speech that way
### Lastly, our Random Fact
Again, very simple, only needing to read the State of our Random Fact Entity.
```
And a random fact.. {{ states('sensor.random_fact') }}
```
Again, the double stop seemed to make the timeing better.
### Put All Together
```
@ -141,4 +158,4 @@ They said. {{ states('sensor.quote_sensor') }}
Here is a Dad Joke.. {{ states('sensor.dad_joke_of_the_hour') }}
And a random fact.. {{ states('sensor.random_fact') }}
### Get the current Temperature from Home Assistant
We're casting this as a float, probably no need, but I'd rather be safe.
```
```jinja
{% set current_temp = state_attr ('weather.home','temperature') | float %}
```
### Get the current weather condition from Home Assistant as well
```
```jinja
{% 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.
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
```
```jinja
{% 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.
```
```jinja
{% set high_temp = weather[0].temperature %}
{% set low_temp = weather[0].templow %}
```
@ -46,7 +46,7 @@ We're assigning the temperature from the 0th record in the array to get started.
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
```
```jinja
{% for entry in weather %}
{% if entry.temperature > high_temp %}
{% set high_temp = entry.temperature %}
@ -79,7 +79,7 @@ Change them as you need to
else: the `high_temp` variable must be <0°C
`< 0°C` say "It's going to be freezing today"
```
```jinja
{% if high_temp > 30 %}
It's going to be a hot one
{% elif 20 <high_temp<30%}
@ -98,7 +98,7 @@ else: the `high_temp` variable must be < 0°C
### Announce the `high_temp` and `low_temp` values
Again, built for °C
```
```jinja
The forecast high is {{ high_temp }} °C.
With a Low of {{ low_temp }} °C .
```
@ -116,7 +116,7 @@ Remember these are for the `low_temp` variable, so it's not going to get colder
Puntuation like `.`, `!`, `?` and `,` is important in the text to speech statments so the timing sounds "natural"
```
```jinja
{% if low_temp > 30 %}
Wow. That's hot!
{% elif 20 <low_temp<30%}
@ -131,7 +131,7 @@ Puntuation like `.`, `!`, `?` and `,` is important in the text to speech statmen
```
## Now we can put it all together:
```
```jinja
{% set current_temp = state_attr ('weather.home','temperature') | float %}
{% set current_condition = states('weather.home') %}