Item change state and wait time

You have a whole lot of errors in these rules. Some major, some minor.

  • Always use the method on the Item instead of the Action when you know the Item in the Rule. For example, luce_scale.sendCommand(ON)

  • I’m not sure why you commented out the else. In a case like this where arm_pir can only have two valid states the else is the better approach. If for some reason arm_pir.state changes while the if(arm_pir.state == ON) is executing, both if statements will be run. Also, it is causing the Rule to do extra work.

You basically already have the code already. As written you just need to add the playSound after the Thread::sleep to play it again. That will cause the sound to be played again after one minute.

One thing to realize is that every time that an event occurs, in this case pir_porta changing from OPEN to CLOSED an instance of this Rule will be triggered and start running. So if pir_porta goes to OFF during the Thread::sleep it doesn’t matter to the Rule, it is already running. BUT, if pir_porta goes to CLOSED again within that minute then the whole Rule will run again and you will have two copies of this Rule running at the same time and the sound will be played again for that one. And if this happens five times in a row, it will mean that NO other Rules will be able to run until one of these stops running. See Why have my Rules stopped running? Why Thread::sleep is a bad idea

So to solve your basic problem without using Thread::sleep use a Timer to schedule the second playSound in a minute.

rule "pir_port changed to CLOSED"
when
    Item pir_port changed from OPEN to CLOSED
then
    if(arm_pir.state == OFF) {
        playSound("movimento_porta_rilevato.mp3")
        createTimer(now.plusMinute(1), [ | playSound("movimento_porta_rilevato.mp3") ])
    }
end