I have presence detection set up via phone connection to router. I’ve created an automation when state changes to home then unlock door. The problem I’m having is if the phone drops from the router randomly and reconnects in unlocks the door in middle of the night. Are there any way around this without changing the type of presence detection?
I tried to put a condition if person was not-home for 10min, but it doesn’t seem to work because the current condition is home when it was triggered. I think the best way would be if (Condition): state changed to home in the last 3 minutes and (trigger) motion is detected (action) open the front door. But have no idea how to set up the condition for last 3 minutes.
pedolsky
(Pedolsky)
May 16, 2022, 9:24pm
2
Welcome to the community forums!
Basically, such a condition could look like the following:
condition:
- "{{ now() - states.device_tracker.me.last_changed < timedelta(minutes=3) }}"
Thank you, I tried plugging it in but I get an error when I test it.
I put it in like this
condition:
- "{{ now() - states.device_tracker.unifi_ae_2d_2f_18_e9_ee_default.last_changed < timedelta(minutes=3) }}"
Where am I making a mistake?
pedolsky
(Pedolsky)
May 17, 2022, 5:46pm
4
What kind of error?
Please post your code.
condition: template
value_template: "{{ now() - states.device_tracker.unifi_ae_2d_2f_18_e9_ee_default.last_changed < timedelta(minutes=3) }}"
Error:
template value should be a string for dictionary value @ data[‘value_template’]. Got None
pedolsky
(Pedolsky)
May 17, 2022, 7:52pm
7
Ah, ok, I didn’t think of that (I use packages for my automations). That is a bug, see here:
opened 01:22PM - 08 Apr 22 UTC
### The problem
In order to implement a somewhat more complex template conditio… n, I came across the problem that (at least testing) templates conditions do not work (anymore).
What I did:
Create a simple automation having a template condition:
```
- condition: template
value_template: "{{ 1 > 2 }}"
```
So, this is extremely simplifed. The expression should return False, but instead I get the following error when testing this expression in the condition frontend (under automatisations):
`Error handling message: template value should be a string for dictionary value @ data['value_template']. Got None (invalid_format)`
If I enter the same snippet of code in the templates section un der developer tools, it prints false.
Either there is a problem in the code just adding the template condition in the automatisation frontend or something is completely borked.
### What version of Home Assistant Core has the issue?
2022.4.1
### What was the last working version of Home Assistant Core?
_No response_
### What type of installation are you running?
Home Assistant Container
### Integration causing the issue
Automation
### Link to integration documentation on our website
_No response_
### Diagnostics information
_No response_
### Example YAML snippet
```yaml
- condition: template
value_template: "{{ 1 > 2 }}"
```
### Anything in the logs that might be useful for us?
```txt
2022-04-08 14:40:54 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140209354674720] Error handling message: template value should belue_template']. Got None (invalid_format)
```
### Additional information
_No response_
You can try to edit the automations.yaml file directly.