I have not deconstructed your rest980, so without knowing how and/or how much you wrap the dorita980, we do know the region number and in theory, link that to a room. So I started a proof of concept. The rest API is called from one automation, so I just put a step in there to set an input_text value to the date for each of the rooms. I will share where I am at, just keep in mind this is a work in progress and I am not trying to optimize anything. So don’t laugh too hard at the code.
A little context of my thought. You have an input_text and input_boolean for each room. The format is vaccum_clean_‘RoomName’. So I created an input_text with that same format and added date for the last time it was run for that room.
There are two python scripts.
One (vacuum_set_last_run_date.py) runs during the clean room automation. It is after the rest api is called and before any of the booleans are changed. It reads the input_text.current_rooms and sets the current date to what is stored there.
The other (vacuum_test_and_run.py) takes 3 parameters ({‘rooms’:‘front_bar_area,living_room’,‘days’:‘3’,‘one_room_only’:‘false’}). Then it will loop through the ‘rooms’ and anything equal to or older than ‘days’ will toggle the input_boolean.vacuum_clean’RoomName’. Once toggled on, then the clean room automation can be trigger via a service call. So the “no one home” automation, can call the ‘vacuum_test_and_run.py’ python script, then trigger clean room. I added the ‘one_room_only’ thinking that you could pass the room list in a “priority to clean” order and the loop would exit as soon as it turns on one.
I could see the issue if the clean room is called and there are no rooms to clean. If that is an issue, we could just call the rest API from the python script.
Again just thinking out loud and picking all the brains on this thread.
vacuum_set_last_run_date.py
logger.info("Start - vacuum_set_last_run_date")
rooms = hass.states.get('input_text.vacuum_rooms').state.split(',')
logger.info("Rooms selected:" + str(rooms))
current_time = datetime.datetime.now()
date = f'{current_time.month:02}' + "/" + f'{current_time.day:02}' + "/" + f'{current_time.year:04}'
#date = '{}'.format(curent_time,'%m/%d/%Y')
logger.info("Will set date to: " + date)
for room in rooms:
logger.info("Running set for " + room)
if len(room)>0:
service_data = {"entity_id": "input_text.vacuum_clean_" + room + "_date", "value": date}
hass.services.call("input_text", "set_value", service_data, False)
logger.info("Finish - vacuum_set_last_run_date")
vacuum_test_and_run.py
logger.info("Start - vacuum_test_and_run")
rooms = data.get('rooms').split(',')
days = data.get('days')
one_room_only = data.get('one_room_only')
logger.info("Rooms to selected: " + str(rooms) + ", if more than " + days + " day(s) old, and do one room only: " + str(one_room_only).lower() + ".")
current_time = datetime.datetime.now()
for room in rooms:
logger.info("Testing " + room + " room")
if len(room)>0:
room_last_run = hass.states.get("input_text.vacuum_clean_" + room + "_date").state
room_last_run_date = datetime.datetime.strptime(room_last_run, '%m/%d/%Y')
days_diff = (current_time-room_last_run_date).days
if days_diff >= days_diff:
#service_data = {"entity_id": "input_boolean.vacuum_clean_" + room, "value": 'false'}
service_data = {"entity_id": "input_boolean.vacuum_clean_" + room}
logger.info("Service data: " + str(service_data))
hass.services.call("input_boolean", "turn_on", service_data, False)
if str(one_room_only).lower() == 'true':
break
else:
logger.info(room + " not run: " + str(days_diff))
logger.info("Finish - vacuum_test_and_run")