Writing a simple script that would concatenate which bins are to be collected, and tts_say’ing the response to Google Assistant:
bin_fairy_which_bins:
alias: "Which bins will be collected"
icon: mdi:delete-empty
mode: single
sequence:
- variables:
message: >
{%- set messageToSay = "The following bins will be collected: ") %}
{%- if states('sensor.sua_bincollection_next_includes_recycling') == 'true' %}
{%- set messageToSay = messageToSay + "Recycling, " %}
{%- endif %}
{%- if states('sensor.sua_bincollection_next_includes_garden_waste') == 'true' %}
{%- set messageToSay = messageToSay + "Garden Waste, " %}
{%- endif %}
{%- if states('sensor.sua_bincollection_next_includes_general_refuse') == 'true' %}
{%- set messageToSay = messageToSay + "General Refuse, " %}
{%- endif %}
{%- set messageToSay = messageToSay + "and Food waste." %}
{{ messageToSay }}
- alias: "TTS for speaker voice command"
service: script.google_home_voice
data:
use_resume: true
action:
- alias: "Send TTS message"
service: tts.google_cloud_say
data:
message: "{{ message }}"
volume: 35
When loading the script, the following error shows in the logs:
Invalid config for [script]: invalid template (TemplateSyntaxError: unexpected ')') for dictionary value @ data['sequence'][0]['variables']['message']. Got None. (See /config/configuration.yaml, line 11).
Injecting a manual string on the line where I return {{ messageToSay}}
makes the script load successfully, so I’m assuming {{ messageToSay }}
is “null” at this point? The 4 sensors (sensor.sua_bincollection_next_includes_*) are just true/false values, so I’ve tried:
without apostrophes:
{%- if states('sensor.sua_bincollection_next_includes_recycling') == true %}
with single = :
{%- if states('sensor.sua_bincollection_next_includes_recycling') = 'true' %}
(but thinking about it now, that probably doesn’t matter since at the very end I set a value for messageToSay
, (i.e. “and Food waste.”) regardless of some condition, so I would expect it to have a value.
Am I returning {{ messageToSay }}
incorrectly?