When the humidity in the bathroom is to high i want to open my window. Only when there is no one in the bathroom for 5 minutes, otherwise its to cold in the
I think the problem is with the timing, once the automation triggers (humidity above 76) then it is waiting for a change from motion to no motion to be detected, so it will not work if the humidity triggers when no person is in the room.
You could fix this using a template (within your binary_sensor.yaml file) and reference this within the wait_for_trigger step of your automation:
no_motion:
friendly_name: "No Motion for 5 Mins"
device_class: occupancy
value_template: >-
{{is_state('binary_sensor.badkamer_bewegingsmelder_occupancy', 'off') }}
delay_on: "00:05:00"
The automation action would be:
action:
- wait_for_trigger:
- type: state
entity_id: binary_sensor.no_motion
to: 'on'
This would mean if someone left the room 3 mins before the humidity went above 76 then the actions would continue a further 2 minutes later which is what I think you are trying to achieve.
There are cases where the waits are needed because a specific sequence of events needs to happen, but for most automations a good place to start is to use the event closest in time to your actions as your trigger.
alias: Badkamer_vochtigheid te hoog
description: ""
trigger:
- platform: state
to: 'off'
entity_id: binary_sensor.badkamer_bewegingsmelder_occupancy
for:
hours: 0
minutes: 5
seconds: 0
condition:
- condition: numeric_state
entity_id: sensor.badkamer_vochtigheid
above: 76
action:
- action to turn on fan