Hi.
I am trying to make a lovelace with a vacuum, when I touch the room I would like that the Home assistant to add room’s number to list, and finally press button clean and the vacuum clean the select rooms in the list.
You can’t make temporary variables. And to top it off, you’ll run into a type issue when trying to call your vacuum service. Typically, something like this is handled with templating but because templates only return a string, you get yourself into murky waters. Your service call expects a list. So, the only option you have is a python script.
input_boolean:
room1:
room2:
room3:
room4:
vacuum_rooms.py
# Map input_boolean to room number
room_entities = {
'input_boolean.room1': 16,
'input_boolean.room2': 19,
'input_boolean.room3': 20,
'input_boolean.room4': 21,
}
ret = [] # make a list that we will add numbers to
for entity_id, number in room_entities.items(): # iterate through entity_id & number pairs
state = hass.states.get(entity_id) # get the current entity_id's state object
if state != None and state.state == 'on': # if we have a state object, and it's state is 'on'...
ret.append(number) # add the number to a list
# make data that will be sent to the service.
data = {'command': 'app_segment_clean', 'entity_id': 'vacuum.roborock', 'params': ret }
hass.services.call('vacuum', 'send_command', data) # call the service
Then just make sure each item in your picture-elements toggle one of the input booleans. You’ll have to tailor the script to your room numbers and input_boolean names.
To call the python script on your Lovelace button, the tap action should be:
Your input boolean configuration is incorrect. Compare your input_boolean configuration to mine. You’ll notice that you have extra fields and you’re mapping fields to numbers. That’s only done in the python_script.
Go to the integrations page and search python_script. Find the documentation and read how to integrate it.
I have erased the numbers in my input boolean, should the input boolean is into the configuration.yaml?
I have installed pyscript from hass and I have read where I have to make the folder and put the file.
And the last question, the name of the Lovelace button should be the same than describe in the python script?, because I don’t understand how the scrypt take de correct number and put into de “ret”
After the last botton “clean” call de python script with all the numer select. ¿no?
I have erased the numbers in my input boolean, should the input boolean is into the configuration.yaml or in another file?
And the last question, the name of the Lovelace button should be the same than describe in the python script?, because I don’t understand how the scrypt take de correct number and put into de “ret” After than that the last step “botton clean” call the python script with all the numer select. ¿Is correctly?
I’m sorry to refloat this topic, the solution was perfect but the situation has changed.
Blockquote# Map input_boolean to room number
room_entities = {
‘input_boolean.despacho’: 16,
‘input_boolean.pasillo’: 17,
‘input_boolean.entrada’: 18,
‘input_boolean.cocina’: 19,
‘input_boolean.habitacion_principal’: 22,
‘input_boolean.bano_habitacion_principal’: 21,
‘input_boolean.salon’: 20,
‘input_boolean.habitacion_sara’: 23,
‘input_boolean.habitacion_julia’: 24,
‘input_boolean.bano_pasillo’: 25,
}
ret = # make a list that we will add numbers to
for entity_id, number in room_entities.items(): # iterate through entity_id & number pairs
state = hass.states.get(entity_id) # get the current entity_id’s state object
if state != None and state.state == ‘on’: # if we have a state object, and it’s state is ‘on’…
ret.append(number) # add the number to a list
'# make data that will be sent to the service.
data = {‘command’: ‘app_segment_clean’, ‘entity_id’: ‘vacuum.roborock_s5_max’, ‘params’: ret }
hass.services.call(‘vacuum’, ‘send_command’, data) # call the service
When the map change in the app of Vacuum the number of room change too and in HA lost the configuration. Now I need use zone in this format