This post is meant as a companion post to my latest video.
In the video I go through three awesome examples of how I’m using A.I. to send me really fun notifications from my smart home, so be sure to check it out.
If you’ve watched the video here are some YAML code snippets you can use in your projects. If you haven’t watched it yet, go check it out!
Air Quality Update
Here is the YAML for the three times a day Air Quality updates that I get.
alias: "OpenAI Daily: Environmental Notification"
description: ""
trigger:
- platform: time
at: "08:05:00"
- platform: time
at: "12:40:00"
- platform: time
at: "18:30:00"
condition: []
action:
- service: weather.get_forecast
target:
entity_id: weather.forecast_weather_station
data:
type: daily
response_variable: daily_forecast
alias: "Call a service 'Weather: Get Forecast'"
- service: conversation.process
data:
agent_id: 8e448500f3d39bcd73b81d343e4bd843
text: "For this task, you are an environmental consultant and responsible for ensuring a healthy indoor air quality for the inhabitants of your smart home. Please provide your thoughts on our indoor air quality as it relates to the weather outside and our current heating / cooling system settings. \_ Current time {{now()}} Current thermostat setting {{states('climate.living_room_thermostat')}} temperature {{state_attr(\"climate.living_room_thermostat\",\"current_temperature\")}} Current average temperature is {{states('sensor.average_temperature')}} Current maximum humidity is {{states('sensor.max_humidity')}} Status of all downstairs windows {{states('binary_sensor.windows')}} Exterior Weather Data Temperature is {{ states('sensor.tempest_temperature') }} Feels like temperature is {{ states('sensor.tempest_feels_like_temperature') }} Humidity is {{ states('sensor.tempest_humidity') }} Current Rain Intensity {{ states('sensor.tempest_rain_intensity') }} Forecasted Conditions for Today {{daily_forecast.forecast[0].condition}} Forecasted High Tempterature for Today {{daily_forecast.forecast[0].temperature}} Forecasted Low Temperature for Today {{daily_forecast.forecast[0].templow}} Forecasted Precipitation Probability {{daily_forecast.forecast[0].precipitation_probability}} Weather outlook for today is {{daily_forecast.forecast[0].condition}} with a high of {{daily_forecast.forecast[0].temperature}}"
enabled: true
response_variable: agent
- service: notify.notify
data:
title: Air Quality Update
message: "{{agent.response.speech.plain.speech}}"
mode: single
Daily Stats Notification
Here is how I set up the Conversational Assistant during the integratio:
You are an intelligent smart home AI - respond as yourself. Each day you provide information. Your update is sent in a daily push notification and should be 178 characters for it to be displayed properly. Your tone can be humorous like Jarvis, you are a pretty powerful smart home. Please provide analysis of numbers. If historical data is provided, please analyze recent usage in comparison to previous days.
Below is the YAML for my Daily Energy and Water stats.
alias: "OpenAI Daily: Stats Notification"
description: ""
trigger:
- platform: time
at: "08:00:00"
condition: []
action:
- service: weather.get_forecast
target:
entity_id: weather.forecast_weather_station
data:
type: daily
response_variable: daily_forecast
alias: "Call a service 'Weather: Get Forecast'"
- service: conversation.process
data:
agent_id: 183b8b601f6340dcc77d55bfee484d8d
text: >
{{states('input_number.yesterdays_energy_usage')}} kWh of energy
yesterday. {{states('input_text.weekly_energy_usage_json')}} JSON array
of energy first entry is yesterday, use for analysis and comparison
only. {{states('input_number.yesterdays_water_usage')}} gallons of
water. {{states('input_text.weekly_water_usage_json')}} JSON array of
energy first entry is yesterday, use for analysis and comparison only.
Weather outlook for today is {{daily_forecast.forecast[0].condition}}
with a high of {{daily_forecast.forecast[0].temperature}}
response_variable: agent
- service: notify.notify
data:
title: Daily Update
message: "{{agent.response.speech.plain.speech}}"
mode: single
To get these input_text values to store JSON correctly, you’ll need the following code snippet to run in a daily automation after you’ve grabbed the correct value for whatever you are tracking see ‘sensor.phyn_pp1_daily_water_usage’ which is the number I stored for the number of gallons we used.
alias: "Daily: Stats Collection"
description: ""
trigger:
- platform: time
at: "23:58:00"
condition: []
action:
- service: input_number.set_value
data:
value: "{{states('sensor.daily_usage')}}"
target:
entity_id: input_number.yesterdays_energy_usage
enabled: true
- service: input_number.set_value
data:
value: "{{states('sensor.phyn_pp1_daily_water_usage')}}"
target:
entity_id: input_number.yesterdays_water_usage
enabled: true
- service: input_text.set_value
target:
entity_id: input_text.weekly_energy_usage_json
data:
value: |
{% set raw = states('input_text.weekly_energy_usage_json') %}
{% set current_data = raw | from_json if (raw | length > 0 and raw[0] in ['[', '{']) else [] %}
{% set new_data = ([states('sensor.daily_usage') | float] + current_data)[:7] %}
{{ new_data | to_json }}
alias: Store Energy Usage in JSON
- service: input_text.set_value
target:
entity_id: input_text.weekly_water_usage_json
data:
value: |
{% set raw = states('input_text.weekly_water_usage_json') %}
{% set current_data = raw | from_json if (raw | length > 0 and raw[0] in ['[', '{']) else [] %}
{% set new_data = ([states('sensor.phyn_pp1_daily_water_usage') | float] + current_data)[:7] %}
{{ new_data | to_json }}
alias: Store Water Usage in JSON
mode: single
A.I For Kids
This is the YAML for my Kid’s weather forecaster automation. You might have to update the formatting when pasting it in to your automation.
alias: OpenAI Weather update
description: ""
trigger: []
condition: []
action:
- service: weather.get_forecast
target:
entity_id: weather.forecast_weather_station
data:
type: daily
response_variable: daily_forecast
- service: conversation.process
data:
agent_id: 0a9aad64a75118f903bfe043cfbd73e8
text: >-
You are an advanced smart home with a built in personal weather station. Weather updates will be spoken out loud and should be funny and creative because two children will be listening. Please use whole numbers and try to make it educational! This should be less than 1 minute in length.
\n Current Conditions are below\n Current time is {{ now()}}
Temperature is {{ states('sensor.tempest_temperature') }} Feels like
temperature is {{ states('sensor.tempest_feels_like_temperature') }}
Humidity is {{ states('sensor.tempest_humidity') }} UV Index is {{
states('sensor.tempest_uv_index') }} Current Rain Intensity {{
states('sensor.tempest_rain_intensity') }} Forecasted Conditions for
Today {{daily_forecast.forecast[0].condition}} Forecasted High
Tempterature for Today {{daily_forecast.forecast[0].temperature}}
Forecasted Low Temperature for Today
{{daily_forecast.forecast[0].templow}} Forecasted Precipitation
Probability {{daily_forecast.forecast[0].precipitation_probability}}
response_variable: agent
- service: tts.cloud_say
data:
cache: false
entity_id: media_player.nesthubmax19f9
language: en-GB
message: "{{agent.response.speech.plain.speech}}"
enabled: true
mode: single
I hope you found this helpful. If you have a question about the video or the automations I shared above, don’t hesitate to reach out!
See you in the Future
Excellent Job, the kids absolutely love it. The response variable was key for me. I was about to give up before coming across your video which lead me here. Appreciate you sharing.
Awesome work, and has inspired me to implement several of my own as a result. They have encouraged my 4 year old in the mornings on the teeth brushing and listening to her parents :).
On the energy usage I took your concept but wanted it to start predicting my usage for the day given the past weeks usage and correlation to the weather and the forecast weather. So I am recording not only the kwh per day but also the min/max temp historical and rain/snow amounts. Here is my prompt:
Provide a good morning message that analyzes the past electricity usage and
weather to provide a electricity usage prediction for today based on the
forecasted weather. Historical data is provided as a set of arrays with
each value being a day. There should be a prediction for the amount of
kwh today based on the forecasted weather. You should infer the season for
[location] based on the date, temperature and if there is rain or snow
to help with the prediction. Be concise with your response, do not include
the location in the message and do not summarize the historical data in the
message.
electricity in kwh {{states('input_text.weekly_hydro_usage_json')}}
temp max celsius {{states('input_text.weekly_temperature_daily_max')}}
temp min celsius {{states('input_text.weekly_temperature_daily_min')}}
rain in mm {{states('input_text.weekly_rain_daily_amount')}}
snow in cm {{states('input_text.weekly_snow_daily_amount')}}
Weather forecast for today, temperature is in celsius, humidity is a
percentage and wind speeds in kilometers per hour -
{{daily_forecast['weather.forecast_home'].forecast[0]}}
example output responses:
Good morning, sunshine! Based on the historical electricity usage and
today's weather forecast, it looks like we're in late spring. With a
high of 23.7 degrees Celsius and a low of 15.8 degrees Celsius, plus
partly cloudy skies and no rain expected, your electricity usage for
today is predicted to be around 35 kilowatt hours. Enjoy your day, and
remember to keep those fans on standby!
----
Good morning, *****! Based on the weather forecast for today, we
have partly cloudy skies with a high of 23.7 degrees Celsius and a low
of 15.8 degrees Celsius. With no rain expected and a pleasant 40
percent humidity, it looks like a beautiful spring day ahead.
Given the historical electricity usage and today's forecast, we're
predicting an electricity usage of around 35 kilowatt hours. Enjoy
your day, and remember to keep those fans on standby for a comfortable
breeze!
The open AI config instructions I refined as well:
You are a witty, hilarious, and chipper AI that delivers messages over smart speakers in a home.
As these messages are read out loud so NEVER include emojis in your responses.
When writing measurement values in the message use the following information so they are read aloud properly: °C is degrees Celsius, kwh is kilowatt hours, km/h is kilometers per hour, mm is millimeter.
Can't wait to make some more AI automations with TTS. Super fun.