Can anyone advise how to create a trigger for the following scenario.
First background… My wife works shifts and if she gets home before me and goes to bed early she doesn’t want the hall light coming on when I get home.
How can I trigger the hall lights…
If I get home and she is already home dont turn the light on
If we get home together turn the light on
If she gets home (regardless of whether I am or not) turn the light on
The issue arises, as I see it, when we both arrive together and she connects to network as well as me - how can my script recognise that as different to - she was already connected to network some time ago.
Is there a way to say, when triggering that my device joined network, this other device has already been connected for at least 5 minutes?
Rather verbose, but hope I am being clear about my issue/objective?
From the above I assume that you use ping to detect a device (with a fixed ip address ?)
Regardless, you need to set up a binary sensor based on each person, but your wife’s sensor should have a delay_on: ‘00:05:00’ (say).
So if you arrive together it’s your detection that triggers the light.
Her arrival alone, will trigger the light.
But if you come home and she is already there (condition), you, stumble in the dark and break something and she has to get up and take you to hospital.
No, she’d have to wait in the dark for 5 mins
The automation should check her arrival and start a timer for five minutes (set a boolean at timer start, unset it when done, if boolean on then timer running) if you come home after timer end (check for bit) light does not come on
Do you use packages ?
Read up on packages
If so, give me the light entity, what you use for presence detection (ie the yaml configuring it (not any logo or password info)) , what your first name is (and that of your wife) and I’ll write the package fot you to insert.
I’ve built a handful of custom sensors, this tells me who out of my wife and I are currently home. Hoping it helps or puts you on the right track!
google_maps_her_and_me_ishome:
friendly_name: "Her & Me Google Maps Home Sensor"
value_template: >-
{% if is_state('device_tracker.google_maps_XXX', 'home') and is_state('device_tracker.google_maps_YYY', 'home') %}
home
{% elif is_state('device_tracker.google_maps_XXX', 'home') %}
her_home
{% elif is_state('device_tracker.google_maps_YYY', 'home') %}
me_home
{% else %}
not_home
{% endif %}
FWIW I also have built individual sensors as well, so possibly doing the same you’ll be able to easily build triggers / conditions to do what you’d like:
google_maps_her_ishome:
friendly_name: "Her Google Maps Home Sensor"
value_template: >-
{% if is_state('device_tracker.google_maps_XXX', 'home') %}
home
{% else %}
not_home
{% endif %}
google_maps_me_ishome:
friendly_name: "Me Google Maps Home Sensor"
value_template: >-
{% if is_state('device_tracker.google_maps_YYY', 'home') %}
home
{% else %}
not_home
{% endif %}
A binary_sensor is what Mark gave you above (it doesn’t say so but it is) , but don’t worry about that, read up on packages.
I’m offering you a piece of code to run on your instance. You should know what you are accepting and roughly what’s in it. Before you decide to run it.
Any issues or questions, get them answered before you do.
Going through the code will get you familiar, know what to expect, be able to puzzle out how it does it and soon you’ll be writing your own code.
Mark, you have a you sensor and you have a her sensor, then you have another sensor based on the same states. … Why ?
You already have those parts why increase overhead when you can use those directly ?
I know is only a Google api call but you are making four requests when you could get away with two. It’s more the principle involved and the efficiency of it.
Running on a NUC, so not entirely worried about overhead. Easier, for me at least, to have a combined sensor that I can use to reflect home or not_home and ensure that BOTH of us are not home in a single condition vs. having to have multiple conditions / sensors to check.
Agree it’s not the lowest overhead way to do it, but works for me…
Also, FWIW. I have these setup as SENSORS, not binary_sensors. I like the return of home / not_home vs. true / false - makes it more ‘legible’ in my automations. Personal preference…
Mutt, I’ve had a quick read on packages which I hadn’t heard of and they look a great way to organise stuff so as not to get lost on what is where and in which !include file which is where I had been in danger of going - until now.
So, I’d love to take up your offer as I will learn lots as you suggest. I am a VB/SQL programmer by background, just old and rusty to learn new languages - and even more so what is possible to do with this language.
ian & teresa , i’m just using nmap_tracker really but wifes phone is iphone so extra bit to try to avoid losing hers. She has fixed ip.
I’m certainly no expert, but my understanding was that these ‘custom’ sensors only update when the underlying device_trackers they rely upon update. Don’t believe they’re proactively requesting an update from Google Maps, but rather sitting in wait for the underlying Google Maps device_tracker to update and then updating accordingly.
With this assumption, the only additional overhead is the additional, combined sensor computation. Also trying to future-proof as my kids progress into getting their own phones so I can see who, if anyone, is home and trigger automations accordingly. Realize I could go the IP route, but w/ Google I can create zones and tell where people are based on Lat/Long vs. pinging an IP and only knowing if they’re home or not home. For example - muting my ringer at church, or trigger automations if I’m at work, etc. Anyhow, like everyone, I’m still learning and always open to a better way to do things!
Aren’t we all
I use the individual sensors if I want different automations and you’ll have that.
Regardless its best to go with what you are comfortable with I did not mean to lecture.
Cheers
So the entities these trackers create (it’s not obvious from this)?
And the light you want on?
Is this a porch light or hall light?
I’d recommend an auto off on a porch light after two mins but a hall I’d suggest you switch off manually
Okay, good to go, gimme till tomorrow, I’ll write, check then do some instructions for you. ANYTHING you are not happy about - ASK
A porch light is pretty good, helps you get your keys out, find the right one, insert it in the lock, helps even more if you’ve had a drop of the falling down water. Just saying - maybe that’s a project for another day.