Google to capture data in variable

Anyone knows if there is a way for google to save in a variable anything I tell him? For example I have currently a rule that opens my blinds at 7 am but I want each night before to adjust the time accordingly to my next day agenda by telling google to do that. I am thinking my rule to run from the time set in a variable but not sure how to do google to listen to this time and save it in a variable

That's why some of us would like to see google calendar integration. .ics calendar support

1 Like

You can do that through IFTTT. That has a trigger of an event from any calendar, a specific calendar or matching a specific search can be a trigger to so anything you want in IFTTT. I have a calendar to manage my vacation mode for my thermostat while I'm on business trips.

2 Likes

Use IFTTT with the Google Calender service. When the event from search starts (such as the keyword "open blinds"), then close a virtual switch in Hubitat. Create a RM rule with the virtual switch as your trigger to open the blinds.

1 Like

You could set up multiple GA routines to respond to your voice and trigger the appropriate virtual switch. But this approach is only practical if you have a manageable number of time options (eg. 7am, 7.15, 7.30, 7.45, 8am etc) otherwise it's cumbersome with too many routines to set up.

thanks for the suggestions. I tried today before coming work with the IFTTT and it worked but the trigger happened when I received the reminder which was 5 minutes before the time I set the calendar event. I will try further later today once back home but I guess I have to tell google not to create a reminder when creating my event right?

1 Like

Correct. I create dummy accounts with calendars that don’t conflict with my regular calendar for things like this so I can turn off those options and not worry about it

If create dummy accounts then how could Google know in which calendar(or account) to save the event?

Sorry, don't know. I use a single "dummy" calendar with Alexa. I know they both support multiple, but not sure if it's possible to add events to multiple calendars. There are user profiles on both Google Home and Echo, but I gather that it's a bit of a mess at this time.

It's possible to sync events from one calendar to another, but I'm not certain you could filter out the shade events. Maybe, but it's been some time since I've looked at that level of sync. There's probably an app out there that will allow filtering of event syncing if it's not natively possible.

ok, will take a look to options, thanks

It doesn't work with time, but I have delayed off/on switches set up so I can say "turn on X switch for 20 mins" and that passes the command to HE. I use a combo of the IFTTT recipe with number component, the maker API and a custom driver I wrote. If it's something you're interested in, shoot me a PM.

hey @ryan780 actually originally I was only looking for triggering things at a specific time such as open my blinds at different times everyday for which IFTTT looks to be a solution but now that you mention the way you are doing I think I can achieve much more other things and as well would be interesting to ask google to turn specific switch for a specific period of time. Could you share more info ?

Sure. Now, some of this is very customized to me and there are several limitation to this implementation. The biggest is that the scheduling is not maintained after a hub reboot. I don't save any of the scheduling in state variables so once the hub is rebooted your schedules are lost. This works for me because I only use this for short term things (a couple hours max). Also, you must issue the commands from a place that allows you to set the parameters each time. This can be done from the device edit page, from IFTTT or from an app like HTTP Shortcuts for Android.

So, the first piece is a custom driver I wrote.

/*
 * Programmed Delay Switch
 *
 * Has functions to either turn a switch on and then off
 * after a set number of minutes or to turn a sitch on 
 * after a delay of a set number of minutes or hours
 * based on the command issued.  Timed changes to the
 * switch's state will read as Physical to allow for
 * notifications when this occurs. All other changes
 * will appear as programmatic. 
 * 
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
metadata {
    definition(name: "Programmed Delay Switch", namespace: "ryan780", author: "Ryan780") {
        capability "Actuator"
        capability "Switch"
        capability "Sensor"
		command "delayedOff", ["minutes"]
		command "delayedOn", ["minutes"]
		command "delayedOffHours", ["hours"]
		command "offDelayedOn", ["minutes"]
		command "offDelayedOnHours", ["hours"]
		command "delayedOffDelayedOn", ["number", "number"]
        command "onP"
        command "offP"
        command "refresh"
    }
}

preferences {
    section() {
        input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true
		input name: "maxOn", type: "bool", title: "Enable Max On Time", defaultValue: false
		input name: "maxOnTime", type: "integer", title: "Max Number of Hours On", defaultValue: "0"
		input name: "maxOff", type: "bool", title: "Enable Max Off Time", defaultValue: false
		input name: "maxOffTime", type: "number", title: "Max Number of Hours Off", defaultValue: "0"
	}
}

def logsOff() {
    log.warn "debug logging disabled..."
    device.updateSetting("logEnable", [value: "false", type: "bool"])
}

def initialize(){
    updated()
}

def installed(){
    initialize()
}

def refresh(){
    unschedule()
}

def updated() {
    log.info "updated..."
    log.warn "debug logging is: ${logEnable == true}"
    if (logEnable) runIn(1800, logsOff)
}

def parse(String description) {
    if (logEnable) log.debug(description)
}

def on() {
    unschedule()
    if (logEnable) {log.debug "Turned On"}
    sendEvent(name: "switch", value: "on", isStateChange: true)
	if (maxOn) {
		if (logEnable) log.debug("Turning off in "+maxOnTime+" hours")
		def delayOff=(maxOnTime.toInteger())*3600
		runIn (delayOff, offM)
	}
}

def off() {
	unschedule()
    if (logEnable){ log.debug "Turned Off"}
	sendEvent(name: "switch", value: "off")
	if (maxOff) {
		if (logEnable) log.debug("Turning On in "+maxOffTime+" hours")
		def delayOn=(maxOffTime.toInteger())*3600
		runIn (delayOn, onM)
	}
}

def delayedOff(delay){
	unschedule()
	on()
	if (logEnable) log.debug "Turned On"
	myDelay=(delay.toInteger())*60
	if (logEnable) log.debug ("Turning off in:"+myDelay)
	runIn(myDelay, offP)
}

def delayedOn(delay){
	unschedule()
	myDelay=(delay.toInteger())*60
	if (logEable) log.debug ("Turning on in:"+myDelay)
	runIn(myDelay, onP)
}
def onP() {
    unschedule(onM)
    if (logEnable) log.debug "Turned On-Delayed"
    sendEvent(name: "switch", value: "on", type: "physical")
} 
def offP() {
    unschedule(offM)
    if (logEnable) log.debug "Turned Off-Delayed"
    sendEvent(name: "switch", value: "off", type: "physical")
}

def onM() {
    if (logEnable) log.debug "Turned On-Delayed"
    sendEvent(name: "switch", value: "on", type: "physical")
} 
def offM() {
    if (logEnable) log.debug "Turned Off-Delayed"
    sendEvent(name: "switch", value: "off", type: "physical")
}



def delayedOffHours(delay){
	unschedule()
	on()
	if (logEnable) log.debug "Turning On"
	myDelay=(delay.toInteger())*3600
	if (logEnable) log.debug ("Turning off in:"+myDelay)
	runIn(myDelay, offP)
}

def offDelayedOn(delay){
	unschedule()
	off()
	if (logEnable) log.debug "Turning Off"
	myDelay=(delay.toInteger())*60
	if (logEnable) log.debug ("Turning on in:"+myDelay)
	runIn(myDelay, onP)
}

def offDelayedOnHours(delay){
	unschedule()
	off()
	if (logEnable) log.debug "Turning Off"
	myDelay=(delay.toInteger())*3600
	if (logEnable) log.debug ("Turning on in:"+myDelay)
	runIn(myDelay, onP)
}

def delayedOffDelayedOn (off,on){
	unschedule()
	if (logEnable) log.debug ("Turning off in "+off+" mins then on in "+on+" mins.")
	def offDelay=(off.toInteger())*60
	def onDelay=(on.toInteger())*60
	runIn(offDelay,offP)
	runIn(onDelay,onP)
}

A lot of the functions in here could be rewritten better but I'm not a programmer by training and I was able to patch this together from things I've learned by looking through other people's drivers and reading a lot online.

This driver gives you several custom commands each with a number value to be passed with it. Each command will unschedule any other events that are to take place and then do/schedule the prescribed action. So, for example, if I command the device with "delayedOff" with a parameter of 30, the switch will turn on and then 30 minutes later turn off again. If I issue the same command with a parameter of 10, the switch would turn on for 10 minutes and then back off.

If I issued the command delayedOn with a parameter of 5, the switch would turn off and then back on in 10 minutes. Does that all make sense?

The next piece is the IFTTT piece. The first step of this is to add the Virtual Device you created with the custom driver to the Maker API, get it's device number and your URL from that app. With that info, you have to build the url you will use in IFTTT. The url will be:
whatever the maker api outputs up through the command, you will use whatever command you want to use from IFTTT and the second command will be "{{NumberField}}" (without the quotes). So, an example from mine is:
https://cloud.hubitat.com/api/54sdf55ss65g6s-s5s1s6s-s51sd6sdf5s/apps/56/devices/411/delayedOff/{{NumberField}}?access_token=1234568465165165165165416+1+6

Obviously the hub ID (after API) and the token have been changed to protect my hub. :slight_smile:

Now, you will take that URL and you're going to build an IFTTT applet. The IF part you will pick is Google Assistant and then "Say a phrase with a number".

image

You will build your applet as follows, substituting the number sign where you will speak the number. You can build up to 3 different ways to say the command.

For the then, you will select the Makerwebook and then send a request. You will use the URL we created up above but you will substitue in the number field from the Google Assistant. Do this by pasting in the URL we created earlier and selected application type Json and leaving it at Get. Make sure you have NO spaces around the number field, this will cause it to not work. If you add by "add ingredient", it will auto-add spaces around NumberField. Just make sure there are no spaces there.

That's it! You can now use that command via Google Assistant (on your phone or Google Home device) to pass that command with that number off to HE.

Please note, this only works with whole number as far as I know. I've never tried (and wouldn't advise) using decimals. If it recognizes the number wrong, just issue the command again and it will unschedule the incorrect one. Let me know if you have questions.

Thanks for sharing this @Ryan780. I will give a try during the weekend and see if I can find any way to keep schedules saved even after reboot because now we know that very often there are new hub version releases that reboots the hub. Thanks

It's REALLY complicated. In order to schedule the event, the only way I've figured out how to do it is to receive the date/time and then convert that to epoch. Also convert the current date/time into Epoch time. Then subtract the future time from the current time and then schedule the event in that many seconds. To get future dates to work after reboot it would take a lot of effort.

Edit: Apparently whatever testing I did on this driver originally was incorrect. I just tested it again and the schedule was retained across a reboot. Now, I don't know what would happen if the event was supposed to happen while the hub was off. I'd have to test that scenario too.

Also, i forgot to mention....the driver uses the physical change parameter to detect the difference between those changes made by the user and those changes made by the timer. All the timer changes are "physical" changes since those are the 'special' ones. So, if you wanted it to notify you when a programmed change was made, you could subscribe to the physical events in RM and send a notification. It wouldn't notify you if you turned it on/off via a dashboard but would when the hub does the change automatically.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.