Hi everyone, I’m trying to set up an automated programme that will alert me when pir doesn’t detect a human body during a specific period of time (say between 10am and 12pm), but I’ll only be able to set it up for a specific point in time or for a specific period of time (say four hours) for now… any suggestions please?
You have to test it at the end of the time period (otherwise you are not covering the whole period). So trigger at 12pm, then see if the pir changed in the last 2 hours.
trigger:
- platform: time # trigger at 12pm
at: "12:00:00"
condition: # pir changed in the last 2 hours?
- condition: template
value_template: "{{ now() - states.binary_sensor.your_pir_here.last_changed|as_local < timedelta(hours=2) }}"
action:
- service: # trigger your alarm here
In your first post you show the home assistant automation editor. Thus indicating you wanted help with an automation.
That screen-shot above appears to be an ESPHome config, not an automation.
I’m very sorry, as a newbie I didn’t understand what you meant, so I shouldn’t add the code you provided to the yaml file, but should I do it directly in the automation configuration?
It’s a Home Assistant Automation. You can enter it via the UI or you can use YAML. What you can’t do is add it to an ESPHome device configuration.