Hello,
Have a nice day 2025 to all.
I have a variable that i want to pass trough an automatisation.
At the beginning of the automatisation i set this:
variables:
comm: descendre
then i want it to check the variable with the “choose” option:
choose:
- conditions:
- condition: template
value_template: '{{ comm == descendre }}'
But the result is always false.
1 Like
Mayhem_SWE
(Magnus Helin)
January 8, 2025, 6:59pm
2
Your code as written is comparing a variable comm
, which does indeed contain the string "descendre"
, against another variable descendre
, which is not defined.
The string to compare against must be marked as such with quotes, and the customary way in HA is to encase the template in double quotes and mark the strings within using single quotes. Thus:
choose:
- conditions:
- "{{ comm == 'descendre' }}"
Thanks for your reply.
I try the code bellow but it still doesn’t work.
- conditions:
- condition: template
value_template: "{{ comm == 'descendre' }}"
It’s weard, in execution history the quote are not place the same as in yaml file
Mayhem_SWE
(Magnus Helin)
January 8, 2025, 8:43pm
4
You will have to post the entire automation YAML for a real verdict, but based on the screenshot only I would guess your problem is variable scope .
It looks like you are using a choose:
right before to decide between several variables:
to be set, but those variables will only ever live within their enclosing sequence:
. Once you exit the sequence:
those variables are gone.
For that to work, you need to eliminate the choose:
and set your variables:
at the top level. The conditions that determine which values to assign to the variables instead need to be written as templates.
1 Like
alias: 3-VOLET-Voletvelux
description: ""
triggers:
- entity_id: input_button.volet_velux
id: bouton aveugle
trigger: state
- entity_id: binary_sensor.cp_velux_contact
to: "on"
id: Stop
trigger: state
- entity_id: input_button.volet_velux_stop
id: Stop
trigger: state
- entity_id: sensor.telecommande_volet_velux_action
to: 1_single
id: Monté télécommande
trigger: state
- entity_id: sensor.telecommande_volet_velux_action
to: 3_single
id: Déscente télécommande
trigger: state
- entity_id: sensor.telecommande_volet_velux_action
to: 2_single
id: Stop
trigger: state
conditions: []
actions:
- target:
entity_id:
- switch.switch_cave_zigbe_l1
- switch.switch_cave_zigbe_l2
data: {}
action: switch.turn_off
- choose:
- conditions:
- condition: trigger
id: bouton aveugle
- condition: state
entity_id: binary_sensor.cp_velux_contact
state: "off"
- condition: state
entity_id: input_boolean.volet_velux
state: "off"
sequence:
- variables:
comm: descendre
- conditions:
- condition: trigger
id: Déscente télécommande
- condition: state
entity_id: binary_sensor.cp_velux_contact
state: "off"
sequence:
- variables:
comm: descendre
- conditions:
- condition: trigger
id: bouton aveugle
- condition: state
entity_id: binary_sensor.cp_velux_contact
state: "off"
- condition: state
entity_id: input_boolean.volet_velux
state: "on"
sequence:
- variables:
comm: monter
- conditions:
- condition: trigger
id: Monté télécommande
- condition: state
entity_id: binary_sensor.cp_velux_contact
state: "off"
sequence:
- variables:
comm: monter
- conditions:
- condition: trigger
id: Stop
sequence:
- variables:
comm: stop
- choose:
- conditions:
- condition: template
value_template: "{{ comm == 'monter'}}"
sequence:
- target:
entity_id: a01f5b18a3c4d958558fda05b36fa2cc
data: {}
action: switch.turn_on
- target:
entity_id: input_boolean.volet_velux
data: {}
action: input_boolean.turn_off
- delay:
hours: 0
minutes: 0
seconds: 50
milliseconds: 0
- target:
entity_id: a01f5b18a3c4d958558fda05b36fa2cc
data: {}
action: switch.turn_off
- conditions:
- condition: template
value_template: "{{ comm == 'descendre' }}"
sequence:
- target:
entity_id: ffa7e3c63fc27f5c8ec98e418a105963
data: {}
action: switch.turn_on
- target:
entity_id: input_boolean.volet_velux
data: {}
action: input_boolean.turn_on
- delay:
hours: 0
minutes: 0
seconds: 50
milliseconds: 0
- target:
entity_id: ffa7e3c63fc27f5c8ec98e418a105963
data: {}
action: switch.turn_off
mode: restart
Mayhem_SWE
(Magnus Helin)
January 8, 2025, 9:01pm
6
Well, like I said, variable scope. You need to replace the whole first choose:
block with the logic inside a variable template instead:
- variables:
comm: >-
{%- if trigger.id == 'bouton aveugle' and
is_state('binary_sensor.cp_velux_contact', 'off') and
is_state('input_boolean.volet_velux', 'off') -%}
descendre
{%- elif trigger.id == 'Déscente télécommande' and
is_state('binary_sensor.cp_velux_contact', 'off') -%}
descendre
{%- elif trigger.id == 'bouton aveugle' and
is_state('binary_sensor.cp_velux_contact', 'off') and
is_state('input_boolean.volet_velux', 'on') -%}
monter
{%- elif trigger.id == 'Monté télécommande' and
is_state('binary_sensor.cp_velux_contact', 'off') -%}
monter
{%- elif trigger.id == 'Stop' -%}
stop
{%- endif -%}
2 Likes