Having a shot in the dark guess here on how to use else if and was wondering if someone can point me in the right direction:
test:
sequence:
- alias: Message Test
service: notify.knotty
data:
message: >
{% if is_state('sensor.door_count' > '1') %}
There are currently no doors open.
{% elseif is_state('sensor.door_count' = '1') %}
There is currently one door open.
{% else %}
There are currently {{ states("sensor.door_count")}} doors open.
{% endif %}
test:
sequence:
- alias: Message Test
service: notify.knotty
data:
message: >
{% if is_state('sensor.door_count' > '1') %}
There are currently no doors open.
{% elif is_state('sensor.door_count', '1') %}
There is currently one door open.
{% else %}
There are currently {{ states("sensor.door_count")}} doors open.
{% endif %}
test:
sequence:
- alias: Message Test
service: notify.knotty
data_template:
message: >
{% set count = states('sensor.door_count')|int %}
{% if count < 1 %}
There are currently no doors open.
{% elif count == 1 %}
There is currently one door open.
{% else %}
There are currently {{ count }} doors open.
{% endif %}
EDIT: Fixed bug - changed data: to data_template:.
You’ll notice in @pnbruckner solution above that he specifically converts the states value to an integer. In your template, you were comparing the state value to a string. Just something to keep an eye out for going forward!
I also thought that you need to use data_template: instead of data: if using a template in the data block. At least that’s what the templating docs say:
@Knottyboy, I don’t understand why your second attempt in this post, failed ?
It cannot be because elif was incorrect?
Was it because a nested if-then-elif-then-else can only handle test against a simple variable, and not a complex expression like is_state( ) ?
Or is it because there was a syntax error somewhere in your expression?
There were two reasons. First he needed to use data_template instead of data. Second, because the function is_state requires two parameters – an entity_id and a state. You can’t just decide to ignore that and use something invalid like is_state('sensor.door_count' > '1').