Hi - I’m using a garbage plugin to work out which bins need putting out. It’s working nicely. The next step is creating a script to alert me (when asked) as to what bins to put out. I want to build an array (or a list) of the bins to go out, so I can then announce that list. Rather than saying “the following bins need to go out. black, green” I want it more natrual sounding, so “this week, the black and green bins need to go out”.
This is what I have so far
script:
alexa_what_bin_this_week:
sequence:
- service: script.telegram_notification
data:
message: >
{% set black_bin_days = state_attr('sensor.black_bin', 'days') %}
{% set blue_bin_days = state_attr('sensor.blue_bin', 'days') %}
{% set brown_bin_days = state_attr('sensor.brown_bin', 'days') %}
{% set green_bin_days = state_attr('sensor.green_bin', 'days') %}
This week, the following bins need to go out
{% if (black_bin_days < 7) %}
black,
{% endif %}
{% if (brown_bin_days < 7) %}
brown,
{% endif %}
{% if (blue_bin_days < 7) %}
blue,
{% endif %}
{% if (green_bin_days < 7) %}
green,
{% endif %}
Ideally, it would be something like this (using random pseudo code from my head).
{% set black_bin_days = state_attr('sensor.black_bin', 'days') %}
{% set blue_bin_days = state_attr('sensor.blue_bin', 'days') %}
{% set brown_bin_days = state_attr('sensor.brown_bin', 'days') %}
{% set green_bin_days = state_attr('sensor.green_bin', 'days') %}
{% set bins = [] %}
{% if (black_bin_days < 7) %}
{% bins += "black" %} #bins["black"]
{% endif %}
{% if (brown_bin_days < 7) %}
{% bins += "brown" %} #bins["black", "brown"]
{% endif %}
{% if (blue_bin_days < 7) %}
{% bins += "blue" %} #bins["black", "brown", "blue"]
{% endif %}
{% if (green_bin_days < 7) %}
{% bins += "green" %} #bins["black", "brown", "blue", "green"]
{% endif %}
#turn the array to a list and add commas for speech
This week, the {% implode(bins) %} need to go out
Basically, I’ve been trying to find out how to create a list within the YAML template. Is it possible?? Thanks!