data:
title: "Koi pond..."
message: "...main pump has stopped"
and would like the word “stopped” to change between stopped, blocked and started based on the state of three separate input_booleans.
Where do I start with this?
I know that it needs to be along the lines of:
“… main pump has (if input_boolean.main_pump_stopped, “stopped”, else if input_boolean.main_pump_blocked, “blocked”, else_if input_boolean.main_pump_running, “started”)”
I struggle with the correct template syntax and formatting and haven’t yet found an idiots guide.
Hopefully you’re using the Template Editor to test out your template. There are a couple of links on that page to the documentation (the generic Jinja2 doc, as well as HA’s enhancements.)
But here’s a possible starting point for you:
data_template:
title: "Koi pond..."
message: >
{% if is_state('input_boolean.main_pump_stopped', 'on') %}
stopped
{% elif is_state('input_boolean.main_pump_blocked', 'on') %}
blocked
{% elif is_state('input_boolean.main_pump_running', 'on') %}
started
{% else %}
Um, well, not stopped, blocked or started!
{% endif %}
I did not enclose the template in double qoute characters. I used multi-line YAML instead.
Sorry I forgot the first part of the message. Try this:
data_template:
title: "Koi pond..."
message: >
...main pump is {% if is_state('input_boolean.main_pump_stopped', 'on') -%}
stopped
{% elif is_state('input_boolean.main_pump_blocked', 'on') -%}
blocked
{% elif is_state('input_boolean.main_pump_running', 'on') -%}
started
{% else -%}
Um, well, not stopped, blocked or started!
{% endif %}
The “order of precedence” is based on how the statement is constructed. First the expression after “if” is evaluated. If that’s true then “stopped” is the result. If not, then the expression after the first “elif” is evauated. If that’s true then “blocked” is the result. If not, … And if none of them evaluate to true, then the part under the “else” is the result.
would also work (for any number of characters after the last underscore.)
EDIT:
Of course, you never showed what the automation’s trigger was, or even if the snippet came from an automation. In the future it helps to post the entire automation, script, configuration, whatever, that is relavant, for this exact reason.