Binary sensor time

Hello, I want to know how to make a condition be checked when an automation is triggered. So if my binary sensor 1 goes “off”, I notify telegram on the condition that sensor 2 does not change in the next 30 seconds. I have tried with the for and the telegram notification notifies me when the sensor goes from “on” to “off” state. What I want is that sensor 1 goes “off” wait 30 seconds to verify that sensor two has not changed in 30 seconds.

condition: device
device_id: edf65a03951a415ab491000338b33f91
domain: binary_sensor
entity_id: binary_sensor.movimiento0105_occupancy
for:
  hours: 0
  minutes: 1
  seconds: 50
type: is_no_motion

I think it’s best to wait for version 0.115, which will introduce wait_for trigger, which is exactly what you need. Currently, it would involve some timestamp logic etc…

2 Likes

Hello, would you know how to represent it with wait for trigger? I’m trying to get it to work without results, do you know how to help me?

try like this:

- id: '1596277325558'
  alias: xTest
  description: Test only.....
  trigger:
  - platform: state
    entity_id: binary_sensor.movimiento0105_occupancy
    to: 'on'
  action:
  - wait_for_trigger:
    - platform: state
      entity_id: binary_sensor.xxxx #<- put the second binary sensor here
      to: 'on'
      timeout: '00:00:30'
  - choose:
    - conditions:
      - condition: state
        entity_id: binary_sensor.xxxx #<- put the second binary sensor here
        state: 'off'
      sequence: 
        - servie: blalbla #<- put the action you want to take if the binary sensor didn't change
    default: []

This triggers when the the first binary_sensor changes to on, it then waits for 30 seconds and if the second binary sensor doesn’t change to on in these 30 seconds, it executes the action, otherwise nothing happens.

1 Like

I want it to change when sensor 1 goes off, but that doesn’t matter I guess. I have copied your code and the home assistant validates, but when I restart I get the following error in notifications: The following integrations and platforms could not be configured:

automation
Please check your config.

The alias xTest does not appear in automations.

Please show the logs under Developer Tools -> Logs

And please also post the full code you have for this automation.

1 Like

I cant see logs in developer tools,

- id: '1596277325558'
  alias: xTest
  description: Test only.....
  trigger:
  - platform: state
    entity_id: binary_sensor.0215
    to: 'on'
  action:
  - wait_for_trigger:
    - platform: state
      entity_id: binary_sensor.movimiento0105_occupancy #<- put the second binary sensor here
      to: 'on'
      timeout: '00:00:30'
  - choose:
    - conditions:
      - condition: state
        entity_id: binary_sensor.movimiento0105_occupancy #<- put the second binary sensor here
        state: 'off'
      sequence: 
  - service: notify.telegram2
    data:
      message: hola

You forgot the default action at the end and the service part needs to be indeted more, like this:

- id: '1596277325558'
  alias: xTest
  description: Test only.....
  trigger:
  - platform: state
    entity_id: binary_sensor.0215
    to: 'on'
  action:
  - wait_for_trigger:
    - platform: state
      entity_id: binary_sensor.movimiento0105_occupancy #<- put the second binary sensor here
      to: 'on'
      timeout: '00:00:30'
  - choose:
    - conditions:
      - condition: state
        entity_id: binary_sensor.movimiento0105_occupancy #<- put the second binary sensor here
        state: 'off'
      sequence: 
      - service: notify.telegram2
        data:
          message: hola
    default: []

I’m sorry, the logs are now under Configuration -> Logs

Tried to serve up ‘/config/www/community/custom-sidebar/custom-sidebar.js’ but it does not exist
I have the same error as before, copying the default line:
14:37:53 – /usr/local/lib/python3.8/site-packages/integrationhelper/logger.py (ERROR)

Invalid config for [automation]: [timeout] is an invalid option for [automation]. Check: automation->timeout. (See /config/configuration.yaml, line 12).

14:37:34 – config.py (ERROR)

I’m sorry, the indentation for timeout was wrong, try again like this:

- id: '1596277325558'
  alias: xTest
  description: Test only.....
  trigger:
  - platform: state
    entity_id: binary_sensor.0215
    to: 'on'
  action:
  - wait_for_trigger:
    - platform: state
      entity_id: binary_sensor.movimiento0105_occupancy #<- put the second binary sensor here
      to: 'on'
    timeout: '00:00:30'
  - choose:
    - conditions:
      - condition: state
        entity_id: binary_sensor.movimiento0105_occupancy #<- put the second binary sensor here
        state: 'off'
      sequence: 
      - service: notify.telegram2
        data:
          message: hola
    default: []
1 Like

Indeed it works, thank you very much for your time, if I have another way of evaluating you, let me know.

1 Like

You can buy me a coffee if you feel the need to :wink: