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
Thank you so much for showing us how to do this! Super cool! The one question I have on the weather part is as soon as I put in the "Forecasted Conditions for..." section in YAML, it breaks it and it does not work anymore. No error, no message, etc. Any idea what I am doing wrong? You mentioned in the video to use the Template section to figure out the syntax (I think that is what you meant), which is where I suspect my issue is, but I am not clear what you mean. Any ideas on this? Thanks again!
Hey, Top video. I'd appreciate your help please. In relation to the A.I for Kids, I'm getting an error in the Call a service "TTS", it's saying that the agent is undefined?? Any ideas please.