I am using an openHasp button matrix. On pressing one of the buttons, a “down” event is triggered and a variable “val” is returned whose content is the number of the button that was pressed.
The following code extract in the configuration.yaml file works fine:
event:
"down":
- service: variable.set_variable
data:
variable: thermroom
value: 'climate.trv_bed1'
but I need to set the value of the variable thermroom depending on which button of the button matrix was pushed. I am trying it this way:
event:
"down":
- service: variable.set_variable
data:
variable: thermroom
value: >
{% if val == 0 %}
'climate.trv_bed1'
{% if val == 1 %}
'climate.trv_bed2'
{% if val == 2 %}
'climate.trv_bed3'
{% endif %}
which gives me the following cryptic (at least for me as an unexperienced yaml coder) error message:
Invalid config for [openhasp]: template value should be a string for dictionary value @ data[‘openhasp’][‘plate’][‘objects’][7][‘event’][‘down’][0][‘data’]. Got OrderedDict([(‘variable’, ‘thermroom’), (‘value’, “{% if val == 0 %} ‘climate.trv_bed1’ {% if val == 1 %} ‘climate.trv_bed2’ {% if val == 2 %} ‘climate.trv_bed3’ {% endif %}”)]). (See /config/configuration.yaml, line 217).
I tried other ways of indenting the “ifs” but whatever else I tried, my StudioCodeServer editor complains about bad indentations…
Can anyone point me in the right direction with those conditional statements?
(other tests show me that the contents of the “val” are correct and correspond to the button that was pressed, so the problem is not in the “val” value)