Skip to content

Instantly share code, notes, and snippets.

@RandomArray
Last active January 18, 2023 08:42
Show Gist options
  • Save RandomArray/c8d7d77736511c704c98234ddcd86016 to your computer and use it in GitHub Desktop.
Save RandomArray/c8d7d77736511c704c98234ddcd86016 to your computer and use it in GitHub Desktop.
Home Assistant - Script - Google Assistant TTS Speak Weather Conditions
{% set temp = states("sensor.lacrosse_tx141thbv2_0_144_t")|float|round
%}
{% set humid = states("sensor.lacrosse_tx141thbv2_0_144_h")|float|round
%}
{% if temp >=50 and temp <= 90 and humid <= 65 and (50 - temp)|abs <= 10
and (temp - 90) <= 10 or temp >=50 and temp <= 90 and humid <= 65 and
(65 - humid)|abs <= 10 %}
Yes, the current weather condition is within the recommended limits for
painting. The temperature is currently {{ temp }} degrees fahrenheit {%
if (50 - temp)|abs <= 20 %}which is {{ (50 - temp)|abs }} degree{% if
(50 - temp)|abs != 1 %}s{% endif %} above the recommended minimum.{%
elif (temp - 90)|abs < 20 %}which is {{ (temp - 90)|abs }} degree{% if
(temp - 90)|abs > 1 %}s{% endif %} within the recommended maximum.{%
endif %} The humidity is {{ humid }} percent which is {{ (65 -
humid)|abs }} percent below the recommended maximum. Proceed with
caution as the conditions are close to the recommended limits.
Temperature should be between 50 and 90 degrees fahrenheit. The humidity
should be under 65 percent.
{% elif temp < 50 and humid > 65 %}
Sorry, no, it is not a good time to start painting. Both the temperature
and humidity are beyond manufacturer recommendations. The temperature is
currently {{ temp }} degree{% if temp|abs > 1 %}s{% endif %} fahrenheit,
which is {{ (50 - temp)|abs }} degree{% if (50 - temp)|abs != 1 %}s{%
endif %} below the recommended minimum of 50 degrees fahrenheit. The
humidity is {{humid}} percent, which is {{ (65 - humid)|abs }} percent
above the recommended maximum of 65 percent. Painting is not
recommended.
{% elif temp > 90 and humid > 65 %}
Sorry, no, it is not a good time to start painting. Both the temperature
and humidty are beyond manufacturer recommendations. The temperature is
currently {{ temp }} degrees fahrenheit, which is {{ (temp - 90) }}
degree{% if (90 - temp)|abs != 1 %}s{% endif %} above the recommended
maximum of 90 degrees fahrenheit. The humidity is {{humid}} percent. The
humidity is {{ (65 - humid)|abs }} percent above the recommended maximum
of 65 percent. Painting is not recommended.
{% elif temp < 50 and humid <= 65 %}
Sorry, no, it is not a good time to start painting. The temperature is
beyond manufacturer recommendations. The temperature is currently {{
temp }} degree{% if temp|abs > 1 %}s{% endif %} fahrenheit, which is {{
(50 - temp)|abs }} degree{% if (50 - temp)|abs != 1 %}s{% endif %} below
the recommended minimum. The humidity is currently {{ humid }} percent{%
if (65 - humid)|abs <= 10 %}. The humidity is {{ (65 - humid)|abs }}
percent below the recommended maximum of 65 percent{% endif %}. Painting
is not recommended.
{% elif temp > 90 and humid <= 65 %}
Sorry, no, it is not a good time to start painting. The temperature is
beyond manufacturer recommendations. The temperature is currently {{
temp }} degrees fahrenheit, which is {{ (temp - 90) }} degree{% if (temp
- 90)> 1 %}s{% endif %} above the recommended maximum of 90 degrees
fahrenheit. The humidity is currently {{ humid }} percent{% if (65 -
humid)|abs <= 10 %} which is {{ (65 - humid)|abs }} percent below the
recommended maximum of 65 percent{% endif %}.vv
{% elif temp >= 50 and temp <= 90 and humid > 65 %}
Sorry, no, it is not a good time to start painting. The humidity is
beyond manufacturer recommendations. The humidity is currently {{ humid
}} percent which is {{ (65 - humid)|abs }} percent above the recommended
maximum of 65 percent. The temperature is currently {{ temp }} degrees
fahrenheit {% if (50 - temp)|abs <= 20 %}which is {{ (50 - temp)|abs }}
degree{% if (50 - temp)|abs != 1 %}s{% endif %} above the recommended
minimum of 50 degrees fahrenheit.{% elif (temp - 90)|abs < 20 %}which is
{{ (temp - 90)|abs }} degree{% if (temp - 90)|abs > 1 %}s{% endif %}
within the recommended maximum of 90 degrees fahrenheit.{% endif %}
{% else %}
Sorry, I have not been programmed with logic statements to handle this
situation. I show a temperature reading of {{ temp }} degree{% if
temp|abs > 1 %}s{% endif %} fahrenheit. The humidity is showing a value
of {{ humid }} percent.
{% if temp >= 50 %} The temperature is {{ (50 - temp)|abs }} degree{% if
(50 - temp)|abs != 1 %}s{% endif %} above recommended minimum of 50
degrees fahrenheit.{% endif %} {% if temp <= 90 %} The temperature is {{
(90 - temp)|abs }} degree{% if (90 - temp)|abs != 1 %}s{% endif %} below
recommended maximum of 90 degrees fahrenheit.{% endif %} {% if temp <=
50 %} The temperature is {{ (50 - temp)|abs }} degree{% if (50 -
temp)|abs != 1 %}s{% endif %} below recommended minimum of 50 degrees
fahrenheit.{% endif %} {% if temp >= 90 %} The temperature is {{ (90 -
temp)|abs }} degree{% if (90 - temp)|abs != 1 %}s{% endif %} above
recommended maximum of 90 degrees fahrenheit.{% endif %} {% if humid >=
65 %} The humidity is {{ (65 - humid)|abs }} percent above recommended
maximum of 65 percent.{% endif %} {% if humid < 65 %} The humidity is {{
(65 - humid)|abs }} percent below recommended maximum of 65 percent.{%
endif %} {% endif %}
alias: Google Assistant TTS Speak Weather Conditions
sequence:
- service: tts.google_translate_say
entity_id: media_player.kitchen_display
data_template:
message: >
{% set temp = states("sensor.lacrosse_tx141thbv2_0_144_t")|float|round
%}
{% set humid = states("sensor.lacrosse_tx141thbv2_0_144_h")|float|round
%}
{% if temp >=50 and temp <= 90 and humid <= 65 and (50 - temp)|abs <= 10
and (temp - 90) <= 10 or temp >=50 and temp <= 90 and humid <= 65 and
(65 - humid)|abs <= 10 %}
Yes, the current weather condition is within the recommended limits for
painting. The temperature is currently {{ temp }} degrees fahrenheit {%
if (50 - temp)|abs <= 20 %}which is {{ (50 - temp)|abs }} degree{% if
(50 - temp)|abs != 1 %}s{% endif %} above the recommended minimum.{%
elif (temp - 90)|abs < 20 %}which is {{ (temp - 90)|abs }} degree{% if
(temp - 90)|abs > 1 %}s{% endif %} within the recommended maximum.{%
endif %} The humidity is {{ humid }} percent which is {{ (65 -
humid)|abs }} percent below the recommended maximum. Proceed with
caution as the conditions are close to the recommended limits.
Temperature should be between 50 and 90 degrees fahrenheit. The humidity
should be under 65 percent.
{% elif temp < 50 and humid > 65 %}
Sorry, no, it is not a good time to start painting. Both the temperature
and humidity are beyond manufacturer recommendations. The temperature is
currently {{ temp }} degree{% if temp|abs > 1 %}s{% endif %} fahrenheit,
which is {{ (50 - temp)|abs }} degree{% if (50 - temp)|abs != 1 %}s{%
endif %} below the recommended minimum of 50 degrees fahrenheit. The
humidity is {{humid}} percent, which is {{ (65 - humid)|abs }} percent
above the recommended maximum of 65 percent. Painting is not
recommended.
{% elif temp > 90 and humid > 65 %}
Sorry, no, it is not a good time to start painting. Both the temperature
and humidty are beyond manufacturer recommendations. The temperature is
currently {{ temp }} degrees fahrenheit, which is {{ (temp - 90) }}
degree{% if (90 - temp)|abs != 1 %}s{% endif %} above the recommended
maximum of 90 degrees fahrenheit. The humidity is {{humid}} percent. The
humidity is {{ (65 - humid)|abs }} percent above the recommended maximum
of 65 percent. Painting is not recommended.
{% elif temp < 50 and humid <= 65 %}
Sorry, no, it is not a good time to start painting. The temperature is
beyond manufacturer recommendations. The temperature is currently {{
temp }} degree{% if temp|abs > 1 %}s{% endif %} fahrenheit, which is {{
(50 - temp)|abs }} degree{% if (50 - temp)|abs != 1 %}s{% endif %} below
the recommended minimum. The humidity is currently {{ humid }} percent{%
if (65 - humid)|abs <= 10 %}. The humidity is {{ (65 - humid)|abs }}
percent below the recommended maximum of 65 percent{% endif %}. Painting
is not recommended.
{% elif temp > 90 and humid <= 65 %}
Sorry, no, it is not a good time to start painting. The temperature is
beyond manufacturer recommendations. The temperature is currently {{
temp }} degrees fahrenheit, which is {{ (temp - 90) }} degree{% if (temp
- 90)> 1 %}s{% endif %} above the recommended maximum of 90 degrees
fahrenheit. The humidity is currently {{ humid }} percent{% if (65 -
humid)|abs <= 10 %} which is {{ (65 - humid)|abs }} percent below the
recommended maximum of 65 percent{% endif %}.vv
{% elif temp >= 50 and temp <= 90 and humid > 65 %}
Sorry, no, it is not a good time to start painting. The humidity is
beyond manufacturer recommendations. The humidity is currently {{ humid
}} percent which is {{ (65 - humid)|abs }} percent above the recommended
maximum of 65 percent. The temperature is currently {{ temp }} degrees
fahrenheit {% if (50 - temp)|abs <= 20 %}which is {{ (50 - temp)|abs }}
degree{% if (50 - temp)|abs != 1 %}s{% endif %} above the recommended
minimum of 50 degrees fahrenheit.{% elif (temp - 90)|abs < 20 %}which is
{{ (temp - 90)|abs }} degree{% if (temp - 90)|abs > 1 %}s{% endif %}
within the recommended maximum of 90 degrees fahrenheit.{% endif %}
{% else %}
Sorry, I have not been programmed with logic statements to handle this
situation. I show a temperature reading of {{ temp }} degree{% if
temp|abs > 1 %}s{% endif %} fahrenheit. The humidity is showing a value
of {{ humid }} percent.
{% if temp >= 50 %} The temperature is {{ (50 - temp)|abs }} degree{% if
(50 - temp)|abs != 1 %}s{% endif %} above recommended minimum of 50
degrees fahrenheit.{% endif %} {% if temp <= 90 %} The temperature is {{
(90 - temp)|abs }} degree{% if (90 - temp)|abs != 1 %}s{% endif %} below
recommended maximum of 90 degrees fahrenheit.{% endif %} {% if temp <=
50 %} The temperature is {{ (50 - temp)|abs }} degree{% if (50 -
temp)|abs != 1 %}s{% endif %} below recommended minimum of 50 degrees
fahrenheit.{% endif %} {% if temp >= 90 %} The temperature is {{ (90 -
temp)|abs }} degree{% if (90 - temp)|abs != 1 %}s{% endif %} above
recommended maximum of 90 degrees fahrenheit.{% endif %} {% if humid >=
65 %} The humidity is {{ (65 - humid)|abs }} percent above recommended
maximum of 65 percent.{% endif %} {% if humid < 65 %} The humidity is {{
(65 - humid)|abs }} percent below recommended maximum of 65 percent.{%
endif %} {% endif %}
cache: false
- delay:
hours: 0
minutes: 0
seconds: 45
milliseconds: 0
- service: media_player.turn_off
data: {}
target:
device_id: 1234567a89b01c2defab3cf567d89012
mode: single
icon: mdi:coolant-temperature
@RandomArray
Copy link
Author

I wanted a yes/no answer for if the current weather conditions are within the recommendations on most spray paint cans. Between 50 and 90F and under 65% humidity. The template started as a simple Yes/No along with current temperature and humidity.

I have a routine set in Google Home named "Painting Condition". The routine's action runs this script which plays the TTS response on a predefined media player. I have a number of Starters for Hey Google to start the routine.

Hey Google;

Can I paint
Can I spray paint
Can I start painting
Can I start to paint
Can we paint
I want to paint
Is it okay to paint
Is it painting weather
Let's go paint
Let's go painting
Okay to paint
Okay to spray paint
Painting Condition
Painting Conditions
Painting weather
Painting weather condition
Painting weather conditions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment