# Math/code problem: Where is the vacuum located?

GOAL

I want a sensor/s that tells me the cleaned percentage of the current room and the already cleaned rooms.

What I know?

I know the area of each room, the order in which they are cleaned and the total current cleaned area from the ongoing cleanup polled every 10 seconds.

Example

Suppose I have this appartment:

• A == 15sqm
• B == 10sqm
• C == 5 sqm

Order: A, B and C.

If I clean the three areas that’s pretty simple. Problem is I don’t always clean the three areas. I sometimes clean only one, sometimes B and C, sometimes A and C, etc…

I really don’t know how to get this done… any help will be appreciated.

If for example I choose rooms A and C, I know the total area is 20sqm.

Then if my total cleaned area value is 10sqm:

• Area A sensor = 66%
• Area C sensor = 0%

on the other hand, if my total cleaned area value is 17.5sqm:

• Area A sensor = 100%
• Area C sensor = 50%

I hope I’m making myself clear…

How does the vac know which areas to clean? From that set a global/flow variable as to which areas are expected to be cleaned. When the vacuum stops send the total completed and use that flow variable in a function node.

You’ll need to account for all scenarios.

``````var room = global.get("area")
var total = //msg path to total cleaned

if ( room == "a"  &&  total <= 14.9 ) {
msg.room_a = (total/15 * 100)
}
else if ( room == "a" && total > 14.9) {
msg.room_a = 100
}
else if (room == "ac" && total <= 14.9) {
msg.room_a = (total / 15 * 100)
}
else if (room == "ac" && total > 14.9) {
msg.room_a = 100
msg.room_c = (( total - 15 ) / 5) * 100
}
else {
msg.room_a = "unknown"
msg.room_b = "unknown"
msg.room_c = "unknown"
}

return msg;

``````

Yeah I understand, problem is I have 6 rooms and making every possible combination… even disregarding the 6 rooms selected option a no room selected, it would still be 62 combinations and a particular if elif else setup for each one… I hope to find a more general equation, I’ll end up doing this if there isn’t anything better though.

I appreciate!

you don’t need 32 combos, what rooms it’s cleaning? Does this display on the vacuum? If yes, post a screenshot.

I do know which rooms are being cleaned because they are set with and input boolean for every room through HA

So if room A and C and being cleaned, then:

• input_boolean.ozmaca_zona_a and input_boolean.ozmaca_zona_c ==> on
• input_boolean.ozmaca_zona_b ==> off

That is for this simplified example. I in fact have 6 inputs.

I do know the order in which they’ll always be cleaned regardless of which rooms you choose and the total area of each room as well as the total current cleaned area of the ongoing cleanup.

EDIT

The goal is to have a total cleaned area % for every area individually, a percentage that must increase as the cleanup goes on, not only 0 or 100%…

as a template sensor, assuming the other data is coming from sensors…

``````{% set rooms = [
{
'cleaning': states('input_boolean.ozmaca_zona_a') | bool(False),
'total_area': states('sensor.ozmaca_zona_area_a') | float(0),
'total_cleaned': states('sensor.ozmaca_zona_area_cleaned_a') | float(0) },
},{
'cleaning': states('input_boolean.ozmaca_zona_b') | bool(False),
'total_area': states('sensor.ozmaca_zona_area_b') | float(0),
'total_cleaned': states('sensor.ozmaca_zona_area_cleaned_b') | float(0) },
},{
'cleaning': states('input_boolean.ozmaca_zona_c') | bool(False),
'total_area': states('sensor.ozmaca_zona_area_c') | float(0),
'total_cleaned': states('sensor.ozmaca_zona_area_cleaned_c') | float(0) },
},{
'cleaning': states('input_boolean.ozmaca_zona_d') | bool(False),
'total_area': states('sensor.ozmaca_zona_area_d') | float(0),
'total_cleaned': states('sensor.ozmaca_zona_area_cleaned_d') | float(0) },
},{
'cleaning': states('input_boolean.ozmaca_zona_e') | bool(False),
'total_area': states('sensor.ozmaca_zona_area_e') | float(0),
'total_cleaned': states('sensor.ozmaca_zona_area_cleaned_e') | float(0) },
},{
'cleaning': states('input_boolean.ozmaca_zona_f') | bool(False),
'total_area': states('sensor.ozmaca_zona_area_f') | float(0),
'total_cleaned': states('sensor.ozmaca_zona_area_cleaned_f') | float(0) },
},
] %}
{% set total =  rooms | selectattr('cleaning', 'eq', True) | map(attribute='total_area') | list | sum %}
{% set total_cleaned = rooms | selectattr('cleaning', 'eq', True) | map(attribute='total_cleaned') | list | sum %}
{{ ((total_cleaned / total) * 100) | round }}
``````

I’ll have a look mate, I don’t get it at first glance.

Does this create an individual percentage of the cleaned % for every room?

As far as I understand it yields a % of the total % of the total chosen area.

``````{{ ((total_cleaned / total) * 100) | round }}
``````

That is fairly trivial to achieve, I didn’t mean that.

It just yields the total % as each room is cleaned.

I didn’t mean that…

what did you mean then?

I meant this, I quote myself

Yes, this continuously counts up as the cleaning occurs…

but does it create an individual sensor for each room?

sensor room A can be 100% but total cleanup might be 66%

I want an individual sensor for each room, each one displaying the total cleaned percentage for the given room.

ok, but that’s simple if you have the existing percentages. That’s just a current_a / total_a. There’s nothing special with those…

you’d have 7 total sensors. 1 for room a, b, c, d, e, f

This x6

``````{{ (states('sensor.a_current') | float(0) / states('sensor.a_total') | float(1) * 100) | round }}
``````

and the above template.

current_a is what I’m missing. I have total_a and total area of the ongoing cleanup which doesn’t distinguish when on room ends and another starts, it updates every 10 seconds but it shows the total cleaned area of the n number of rooms selected. It doesn’t tell the difference

ok, but to circle back to my original question…

I have no idea what information your vacuum outputs, or where it outputs said information. So, if you could post screenshots of your vacuums information (on the states page), I could help with actual templates that work out of the box.

I’m afraid I don’t understand your question then

I do not know which room is being currently cleaned, that’s something I want to know somehow and create a % of the area for that room