Error aggregate $match $and

If we try to reformat your code to understand

[
  { $project :
    {
      timestamp : { $dateFromString:{dateString:’$timestamp’}}
    } ,
    "_id":0,
    “medidas” : {$slice:["$medidas",-1]},
    “location_id”:1
  },
  { $addFields :
    {
      Hora:{$hour:"$timestamp"},
      Diadelasemana:{$dayOfWeek:"$timestamp"}
    }
  },
  { $match:
    {
      ‘Diadelasemana’:{$in:[‘1’,‘7’]},
      $and:[{‘Diadelasemana’:‘6’},{‘Hora’:{$gte:16}}],
      $and:[{‘Diadelasemana’:‘2’},{‘Hora’:{$lt:‘8’}}]
    }
  }
]

we can see the you are closing your $project too soon.

Read Formatting code and log snippets in posts before posting code or documents. It is hard to help when the markup is wrong and all quotes are screwed up.

Using variables for stages help in finding errors, it is adaptation of Divide And Conquer. For example:

mongosh> match_stage =  {$match:{Diadelasemana:{$in:[1,7]},$and:[{Diadelasemana:6},{Hora:{$gte:16}}],$and:[{Diadelasemana:2},{Hora:{$lt:8}}]}}
/* produce the output */
{$match:{Diadelasemana:{$in:[1,7]},$and:[{Diadelasemana:2},{Hora:{$lt:8}}]}}

Because with JSON you cannot have an object with duplicate key. Well, you can but you only get the last occurrence. Anyway in this case the logic is wrong since you cannot have
both Diadelasemana:2 and Diadelasemana:6 both true.