Automation conditional

I want to do an automation with the following parameters:
-Sensor1 must go from “on” to “off”
-Sensor2 is in “off” and will have to be “off” for the next 30 seconds "
-If this is true, you must send a message by telegram.

The sensor1 will be your trigger and then your sensor2 will be a condition for the automation with an added for:.

Example in YAML:

  - alias: My First Automation
    mode: single
      - platform: state
        entity_id: binary_sensor.sensor1
        from: 'on'
        to: 'off'
      - condition: state
        entity_id: binary_sensor.sensor2
        state: 'off'
          seconds: 30
      - service: notify.<TELEGRAM_NOTIFIER_NAME>
          title: "Status Update"
          message: "Sensor 1 when to Off while sensor2 has been off for at least 30 seconds"


You need to configure the Telegram integration and setups the notify service for your Telegram account and chat ids.

If the trigger happens but sensor2 has not been off for at least 30 seconds this automation will run the action because the condition hasn’t been met. Also, even it sensor2 does meet the condition the automation has stopped so that will not matter.

I’m not sure that the the for: condition works like this. I think it works like this:
Automation triggered -> check if sensor was off in the last 30 seconds -> if true send message

But that’s not what OP wants, OP wants:
Automation triggered -> if sensor is off and stays off for 30 seconds after trigger -> send message

I think OP needs a wait_for_trigger as I explained to him in a different topic, but didn’t have the time to test and reply yet. @Rodrigo_Michineau_Ro please be a bit more patient and don’t open a second topic with the same question.

1 Like

The for is in the condition.

Also, link the other topic? :slight_smile:

Yeah, but it doesn’t work like this. It will not check 30 seconds after the trigger, it checks at the moment of the trigger.

I posted the solution here.

Maybe I’m misunderstanding the the second condition of the sensor2 being off for 30 seconds. Does it need to be off for 30 seconds or does it need to be off for 30 seconds after the trigger occurs for sensor1?

The condition I posted should work, the question is what is needed.

Based on your solution and @Rodrigo_Michineau_Ro response, I did not understand the intent. But the important thing is @Rodrigo_Michineau_Ro has a solution that meets the need. :slight_smile:

From how I understood OP it needs to be off 30 seconds AFTER the trigger. Your condition works for the other case.