Hello good people and YAML adepts. As the title suggests I am trying to present a “modular” inline_keyboard
for my configuration inside an alert:
, and it is not being accepted by the Telegram API as according to it “Bad button data” are provided.
The code is as follows:
alert:
my_alert:
name: 'My alert'
entity_id: group.alpha
state: 'off'
repeat: 90
can_acknowledge: true
skip_first: false
notifiers:
- telegram.person_a
title: 'Some title'
message: 'Some message'
data:
inline_keyboard: >-
{% set ns = namespace(items=[ 'Option1:/optionone' ]) %}
{% if is_state('input_boolean.boolean2', 'off') %}
{% set ns.items = ns.items + [ 'Option2:/optiontwo' ] %}
{% endif %}
{% if is_state('input_boolean.boolean3', 'off') %}
{% set ns.items = ns.items + [ 'Option3:/optionthree' ] %}
{% endif %}
{% if is_state('input_boolean.boolean4', 'off') %}
{% set ns.items = ns.items + [ 'Option4:/optionfour' ] %}
{% endif %}
{{ ns.items }}
As a sanity check I have performed the following steps:
- Took the
inline_keyboard
snippet and put it in the front-end “TEMPLATE” sub-menu in Developer tools to see what it dynamically produces (seems correct). - Continuing from step 1 I took the output which was in the following format
['Option1:/optionone', 'Option2:/optiontwo', 'Option3:/optionthree', 'Option4:/optionfour']
and hardcoded it to the code above - which in turn made the alert work (although not dynamically as intended.
3. Took the exact above logic (code included) and fashioned an automation with it. No changes whatsoever. I let the automation execute and the automation worked with that code without problems.
What could be the issue here? I’ve been at it for days. Any help would be greatly appreciated.