Keep in mind, I do not understand the template. You are setting x to āā, then appending ā6,ā if the boolean is on, then returning only the first part (6). So I just return ā6ā if the boolean is onā¦
Youāre right, he most likely uses button-card (and maybe lovelace_gen).
The former uses JS templates, not jinja as per OP.
So TS need to read the docs as I have to agree that the logic is a bit unclear and it needs to be redesigned as Iām not sure at all if itās possible to combine JS templateās output with lovelace_gen (which operated pythonās data).
Thanks for the solution! I used the first one with script:
vacuum_clean_zone:
alias: Pulisci zona
sequence:
- service: vacuum.send_command
data_template:
command: "{{command}}"
entity_id: "{{entity_id}}"
params:
act: start
content: >
{%- set x = "" %}
{% if is_state('input_boolean.clean_kitchen_boolean', 'on') %}
{% set x = x + "0," %}
{% endif %}
{% if is_state('input_boolean.clean_living_boolean', 'on') %}
{% set x = x + "2," %}
{% endif %}
{% if is_state('input_boolean.clean_lunch_boolean', 'on') %}
{% set x = x + "10," %}
{% endif %}
{% if is_state('input_boolean.clean_disimpegno_boolean', 'on') %}
{% set x = x + "3," %}
{% endif %}
{% if is_state('input_boolean.clean_little_bathroom_boolean', 'on') %}
{% set x = x + "5," %}
{% endif %}
{% if is_state('input_boolean.clean_bathroom_boolean', 'on') %}
{% set x = x + "4," %}
{% endif %}
{% if is_state('input_boolean.clean_bedroom_boolean', 'on') %}
{% set x = x + "6," %}
{% endif %}
{% if is_state('input_boolean.clean_little_bedroom_boolean', 'on') %}
{% set x = x + "9," %}
{% endif %}
{{x[:-1]}}
count: "{{count}}"
type: "{{type}}"
- service: input_boolean.turn_off
data:
entity_id: input_boolean.clean_kitchen_boolean
- service: input_boolean.turn_off
data:
entity_id: input_boolean.clean_living_boolean
- service: input_boolean.turn_off
data:
entity_id: input_boolean.clean_lunch_boolean
- service: input_boolean.turn_off
data:
entity_id: input_boolean.clean_disimpegno_boolean
- service: input_boolean.turn_off
data:
entity_id: input_boolean.clean_little_bathroom_boolean
- service: input_boolean.turn_off
data:
entity_id: input_boolean.clean_bathroom_boolean
- service: input_boolean.turn_off
data:
entity_id: input_boolean.clean_bedroom_boolean
- service: input_boolean.turn_off
data:
entity_id: input_boolean.clean_little_bedroom_boolean
The template is needed in order to build a string (1,2,3) with the concatenation of all room numbers that the service needs in order to do a spot clean. Iām using this UI in order to do that:
Firstlly I select the room and then I click to āPulisciā button (it means clean )
@jocnnor solution 1 is interesting, love the idea!
@Gabriele_Mandalari and Jim: it looks like the command parameter is unnecessary as itās not used in the code so Iād suggest to remove it
Also, I believe you can avoid using that long content template by putting all your input_booleans in a group and then filtering it by state and producing a list. Havenāt tried it but I think itās an option.
That will possibly make your system easier to expand/modify as youāll mainly need to add a new input_boolean in that group to have a new room cleaned (I know you donāt get a new one every month but stillā¦ )
It defines a list called rooms where each item in the list is yet another list containing the roomās name and value.
It defines a global variable ns.x to store the selected room values.
It iterates through the rooms list but only for items whose corresponding input_boolean is on.
An eligible room has its value appended to ns.x. A comma is appended to the value but not if itās the last value.
It reports the variable ns.x.
NOTE:
The tilde character (~) is used to indicate concatenation. The plus character (+) can be ambiguous because it can add numbers or, if one of the values is a string, concatenate them. Ideally, use tilde when you want concatenation and use plus when you want addition.
I just have a question, I would like my vacuum cleaner to vacuum the rooms in the order I choose, by clicking on the buttons(inputs boolean) of the rooms in the order I want.
However, your code always puts the part numbers in ascending order, even if I click on the parts (numbers) that are not in ascending order.
How can I get it to clear them in the order I selected?