If I try the second format, I get this error:
Failed to perform the action script.vestaboard_message_with_options. expected a dictionary @ data['vbml']['components'][0]. Got None
I’m not able to use the first method due to a bunch of {% if %} script I removed to keep the question simple.
{
"style": {
"justify": "center",
"align": "center",
"width": 5,
"height": 1
},
"template": "{{ words }}"
}
This block gets repeated with different inputs and different conditions. So the full payload might need 3 or 4 of these blocks to build a message. Using yaml did not allow for adding blocks to components conditionally. At least not in a way I could figure out.
Here’s the actual script, with all the conditionals. Everything works except sending double quotes:
action: vestaboard.message
metadata: {}
data:
device_id: "{{ repeat.item }}"
vbml:
props:
text: "{{ words }}"
date: "{{ as_timestamp(now())|timestamp_custom('%d') }}"
month: "{{ as_timestamp(now())|timestamp_custom('%b') }}"
hours: "{{ as_timestamp(now())|timestamp_custom('%H') }}"
day: "{{ as_timestamp(now())|timestamp_custom('%A') }}"
minutes: "{{ as_timestamp(now())|timestamp_custom('%M') }}"
temp: "{{ states(temp_source) | int }}"
temp_color: |-
{% if states(temp_source) | int <= 32 %}
{69}
{% elif states(temp_source) | int <= 55 %}
{67}
{% elif states(temp_source) | int <= 75 %}
{66}
{% elif states(temp_source) | int <= 90 %}
{65}
{% else %}
{63}
{% endif %}
alert_color: |-
{% if alert == 'none' %}
{0}
{% elif alert == 'blue' %}
{67}
{% elif alert == 'green' %}
{66}
{% elif alert == 'yellow' %}
{65}
{% elif alert == 'orange' %}
{64}
{% elif alert == 'violet' %}
{68}
{% elif alert == 'white' %}
{69}
{% else %}
{63}
{% endif %}
components: |-
[
{
{% if alert != 'none' %}
"style": {
"justify": "center",
"align": "center",
"width": 22,
"height": 1
},
"template": "{{ '{{alert_color}}' * 22 }}"
},
{
"style": {
"justify": "center",
"align": "center",
"width": 1,
"height": "{{ '3' if status_bar else '4' }}"
},
"template": "{{ ('{{alert_color}}' * 3) if status_bar else ('{{alert_color}}' * 4) }}"
},
{
{% endif %}
"style": {
"justify": "center",
"align": "center",
"width": "{{ '20' if alert != 'none' else '22' }}",
"height": "{% if alert != 'none' and status_bar %}3{% elif status_bar %}5{% elif alert != 'none' %}4{% else %}6{% endif %}"
},
"template": "{{ words }}"
{% if alert != 'none' %}
},
{
"style": {
"justify": "center",
"align": "center",
"width": 1,
"height": "{{ '3' if status_bar else '4' }}"
},
"template": "{{ ('{{alert_color}}' * 3) if status_bar else ('{{alert_color}}' * 4) }}"
},
{
"style": {
"justify": "center",
"align": "center",
"width": 22,
"height": 1
},
"template": "{{ '{{alert_color}}' * 22 }}"
{% endif %}
{% if status_bar %}
},
{
"style": {
"justify": "left",
"align": "center",
"width": 5,
"height": 1
},
"template": "{{ '{{date}}{{month}}' }}"
},
{
"style": {
"justify": "center",
"align": "center",
"width": 12,
"height": 1
},
"template": "{{ '{{day}}' }}"
},
{
"style": {
"justify": "right",
"align": "center",
"width": 5,
"height": 1
},
"template": "{{ '{{temp}}{62}{{temp_color}}' }}"
{% endif %}
}
]