cancel
Showing results for 
Search instead for 
Did you mean: 

Script editor: Use my phone home.state as a starter

JacobWaterweg
Community Member

I have created an automation that turns on certain lights when I come home in the dark (between sunset and sunrise). I used the following starter:

starters:
type: home.state.HomePresence
state: homePresenceMode
is: HOME

It works fine, but I have only one problem: when my wife is at home and already went to bed, her phone is also home and the automation doesn't start, because home state is already 'home', based on my wife's phone. So when I come home in this situation, I still come home in a dark house.

Is there a possibility to use the state of only my phone (home/away), to start this automation?

1 Recommended Answer

JacobWaterweg
Community Member

Thanks for your reply, Sandawg,

I didn't know yet that the Google home app could have a starter based just on the location of a cell phone. Maybe I never looked well enough or maybe it's not so long available (in Europe)? I don't know. But that knowledge set me on the right track to solve the problem for me.

First I defined an outlet in the Google Home Playground (https://home-playground.withgoogle.com/) which I named TriggerPhoneIsHome.

Then I made an automation in Google Home on my cell phone based on the location of that cell phone coming home, which turns on that dummy outlet.

Finally I made a YAML script with a starter based on that dummy outlet turning on. And here you have the conditions available to do this only between sunset and sunrise. At the end of this script I switch off the dummy outlet. 

I still have to think when I want to turn off the dummy outlet if I come home during daylight. In Google Home on my cell phone I made a second automation that turns the dummy outlet off, when I leave  my house. That should do the trick, but I noticed that sometimes my phone leaving isn't picked up by Google. So maybe I define another automation that switches the outlet off every sunset. But first I am going to see if it works like this.

I hope this helps you too.

View Recommended Answer in original post

12 REPLIES 12

15624980
Community Member

Well, one solution I had was to create a virtual switch on Smartthings, for example: me at home. And in Smartthings I created the location routine and whenever I'm getting home the switch turn on and run the routine I created on Google Home, even if Google Home is home activated. It's a solution.

GlenYYC
Community Member

Have you figured out a solution to this

No, not yet.

keezy88
Community Member

I'm trying to find a way to do this as well. My nest keeps going to Eco when I'm home because we have it in a hallway that I don't walk past while I'm working in my office. Trying to create an automation to check if my phone is home and it will kick it back to On.

Sandawg
Community Member

I am having the Same problem.  I am trying to write a Google home script that turns on my bedroom scene (specific color brightness) when ONLY I get home and ONLY when it is dark (between sunset and sunrise).
I want the script to know My position based on my cell phone/.   not home or away status, from home.state.Homepresence. My  wife, son is already home so the state is already set to "home". The home.presnce starter depends on multiple devices such as my wife and son's cell phone and also motion sensors on Nest thermostats, cameras, and smoke alarm.
  Interestingly Google Home app on the Phone allows starters to based on individual device, but it then cannot allow conditions like After sunset and before sunrise. Conversely  Google home script on the web allows conditions, but does not allow the location status of individual devices like my cell phone.
  I wrote a IFTT script that does the same thing (turn on my bedroom scene based on my cell phone's location data entering a radius close to my house, and it is after sunset), it works perfectly. But it costs 5 dollars a month to use IFTT beyond basic (that is where you have to write a personal script) and not too keen giving data to 3rd person.
  Let  me know if you understand my problem and hasve  a simple elegant solution (no third party like IFTT, Smart things or Home assistant etc)

Sandawg
Community Member

I can share my IFTT script which does the same thing if you want. It will trigger your lights when you get home based on your cell phone data and only after dark.

JacobWaterweg
Community Member

Thanks for your reply, Sandawg,

I didn't know yet that the Google home app could have a starter based just on the location of a cell phone. Maybe I never looked well enough or maybe it's not so long available (in Europe)? I don't know. But that knowledge set me on the right track to solve the problem for me.

First I defined an outlet in the Google Home Playground (https://home-playground.withgoogle.com/) which I named TriggerPhoneIsHome.

Then I made an automation in Google Home on my cell phone based on the location of that cell phone coming home, which turns on that dummy outlet.

Finally I made a YAML script with a starter based on that dummy outlet turning on. And here you have the conditions available to do this only between sunset and sunrise. At the end of this script I switch off the dummy outlet. 

I still have to think when I want to turn off the dummy outlet if I come home during daylight. In Google Home on my cell phone I made a second automation that turns the dummy outlet off, when I leave  my house. That should do the trick, but I noticed that sometimes my phone leaving isn't picked up by Google. So maybe I define another automation that switches the outlet off every sunset. But first I am going to see if it works like this.

I hope this helps you too.

I did what you suggested. I created a outlet on google playground (I did not know that existed and you can create virtual outlets)  and called it DummyOutlet. However when  I go to write hte YAML script on teh script editor it does not recognize the "Dummy Outlet" shows as error. Thank you. Scipt below:

metadata:
name: Evening scene turns on if arriving after Sunet
description: Turn on evening scene when the dummy switch is on.
automations:
- starters:
- type: device.state.OnOff # The basic on and off functionality for any device that has binary on and off, including plugs and switches as well as many future devices.
device: DummyOutlet
state: on
is: true
condition:
type: time.between
after: SUNRISE
before: SUNSET
actions:
- type: device.command.ActivateScene
devices:
- EveningScene
activate: true
- type: device.command.OnOff
devices:
- DummyOutlet
on: false

Do you see the dummy outlet in Google Home? Have you connected the playground to Google Home? Like all other third party devices the playground has to be connected to Google Home.

Thank you!  I figured it out . Dummy outlet is connected  to google home and I can view the device in the script editor. I tested the routine by manually turning on the  Dummy outlet (instead of Dummy outlet turned on by being  triggered by  me returning home), and it did activate the scene in my bedroom, but only if it is after sunset (just as I wanted)!
 Now I have to see if the action of coming home  triggers the dummy outlet to turn on as I set up that routine as well, and if the state transition of off to one, triggers the above script.   Now I want to do a reverse of that which is to switch OFF my bedroom lights when I leave hte house but only if it is daytime (i.e before sunset).  I will just create a Dummy outlet 2, and reverse this. Just have to be careful if there are days I leave the house AFTER sunset, i.e at evening. I don't want the routine to turn off the lights in my bedroom in that circumstance.
Any idea how to automatically turn off my Nest Hub Max camera  in my bedroom On when I leave the house, and OFF when I return? Again Google has an inbuilt HOME and AWAY routine that does that but that depends on the location of multiple people (i.e AWAY is triggered when everyone is away, and HOME is triggered when first person not necessarily me  comes home). Unlike lights or scenes there is no option in Google home  to control the camera on the nest hub max, except within  the inbuilt home/away routines.
  This is a workaround, but google should build an interface  in the Home app where people can  add conditions like time of day (Home Android  app already has  phone location based starters) Or modify the scripting language  where there is  Phone.location can be allowed as a starter, in addition to Home.presence.  This script is really easy to write in IFTT, can't believe it took so many steps for such a simple thing.
 Did you figure out the method using dummy outlet yourself?


  

Dirti
Community Member

I am trying to do something similar, which I can kind of already do with the Google Home app using the Personal Routines, since it lets you trigger on locations "When the user arrives at". However, I wanted to add some more to it that isn't currently possible in the app so I was wondering if it is maybe possible to convert a Google Home app routine into a script?

 

Here is a screenshot of the Google Home app version:

Screenshot 

Sandawg
Community Member

There is another way to this something Google.assistant. command. You can write a script and get a Google Home or Nest Mini or one of those speakers/displays to run any command you want via the Google.assistant.command in the script.