Simple way to use Google Home with IFTTT and myopenHAB

voicecontrol
ifttt
googlehome
Tags: #<Tag:0x00007f6d099c9b18> #<Tag:0x00007f6d099c5dd8> #<Tag:0x00007f6d099bdc78>

(Rob Nielsen) #1

I figured out how to simplify my IFTTT configuration and now I can use Google Home to control all lights in my house with a single IFTTT applet. I accomplished this by sending commands from IFTTT to a item called VoiceCommand using the example at https://github.com/openhab/openhab/wiki/Controlling-openHAB-with-your-voice. After exposing the VoiceCommand item, I created an applet by doing the following:

  1. From "My Applets", select "New Applet"
  2. Press "this", search for "Google Assistant" , and select it
  3. Select "Say a phrase with a text ingredient"
  4. Under "What do you want to say?", enter "Turn $" and then press "Create Trigger"
  5. Now press "that", search for "openHAB", and select it
  6. Select "Send a command"
  7. Under "Which item", select "VoiceCommand", under "Command to Send" enter "Turn {{TextField}}" and press "Create Action"
  8. Press the "Finish" Button.

Other phrases that I have implemented are Open and Close. I don't have dim working yet since i want to say something like "OK Google, Dim the kitchen lights to 50%", and haven't figured how to parse out the numeric value.


IFTTT - First Test
HueEmulation and Google Home support
Google Home - Actions (API) now available!
(Matthew Valeri) #2

Interesting. I haven't tried using VoiceCommand as a trigger. I simply created a applet for each light (2 for each actually, one for on and one for off).


(Rob Nielsen) #3

That's what I also did originally, an added benefit is the same voice commands work with the Android app.


(Matthew Valeri) #4

I was researching VoiceCommand and watching this tutorial:

It seems like the process simply takes the work off of making multiple applets in IFTTT and instead creating multiple individual rules. I don't see how this makes it any more or less convenient. Am I missing something? I very may well be, I'm not familiar at all with the VoiceCommand option.


(Rob Nielsen) #5

I created a single rule with multiple if statements. I found this simple and easier to maintain than many applets.


(Matthew Valeri) #6

Ok, thanks. I wasn't sure if I was missing something. To me IFTTT is just a temporary setup until (hopefully) Google opens up direct actions and OpenHab can tie in directly.


(Mark Avenius) #7

This may seem silly, but did you have to do anything special to get VoiceCommand to appear in myopenhab.org? I have used it with IFTTT for over a year with my.openhab, but since the switch, I can't get it to appear. I have added to openhabcloud:expose=, and the one other item that I have exposed is appearing.

Thanks in advance!


(Rob Nielsen) #8

I'm using OH1 and in my .items file I have:

String VoiceCommand

And in in openhab.cfg I have:

openhabcloud:expose=VoiceCommand

You might need to restart OH1 also.


(Mark Avenius) #9

Yep, exactly the same, and I've restarted several times. Thanks.


(Mark Avenius) #10

Well, one more restart and then forcing a value into it seems to have fixed it. Thanks, @ranielsen!


(Rob Nielsen) #11

Sorry, I missed that. I had to force value also.


(Matthew Valeri) #12

I'm thinking about trying this for OH2. How do you force a value into VoiceCommand?


(Rob Nielsen) #13

I have a startup rule:

rule Startup
    when 
        System started
    then
        VoiceCommand.postUpdate("----")
end

(Matthew Valeri) #14

Thanks, got it working. When items are exposed to myopenhab.org they will only show up once there has been an update to the item. That's why a forced value was needed. I believe there should be no reason to force a value anymore once the items is fully exposed.

Like you said, this creates a problem with items that contains numbers (dimmers, thermostat setpoints, volume). I'm not sure which way is better due to that.

I can't admit to understand, but have you looked at the git page here:

The rules seem to have a way to parse for numbers, be it decimals or percent. I'm more of a copy and paste coder but maybe there is a way to use these in conjunction so that Google Assistant pushes to text phrase but the rule parses out the number.


(Rob Nielsen) #15

An update...

I tried switching to HueEmulation with Google Home, but IFTTT is as responsive and works better in general. I also have more control of what happens with rules vs names of devices. I was surprised since there are a couple of additional hops with IFTTT.


(Rob Nielsen) #16

FYI, this also works with Google Assistant on android phones.


(p0lar) #17

@ranielsen or anyone, would you mind sharing your rule that you use for processing? I have found a few examples but they all error out on me.

I have the data getting from my Google Home to IFTT and to MyOpenHAB and to my local install but it dies on the rule


(Rob Nielsen) #18

@p0lar, here's part of my rule:

rule "Voice control"
when
    Item VoiceCommand received command
then
    // https://github.com/openhab/openhab/wiki/Controlling-openHAB-with-your-voice
    var String command = VoiceCommand.state.toString.toLowerCase
    logInfo("voice control","VoiceCommand received " + command)

    var String cmd = null
    if (command.contains("on")) {
        cmd = "ON"
    } else if (command.contains("off")) {
        cmd = "OFF"
    } else if (command.contains("open")) {
        cmd = "OPEN"
    } else if (command.contains("close") || (command.contains("shut")) {
        cmd = "CLOSE"
    }

    if (cmd == "ON" || cmd == "OFF") {
        // main floor
        if (command.contains("living room") || command.contains("main floor")) {
            sendCommand(mLivingLights, cmd)
            sendCommand(mLivingLamp, cmd)
        }

        if (command.contains("dining room") || command.contains("main floor")) {
            sendCommand(mDiningLights, cmd)
        }
    } else if (cmd == "OPEN" || cmd == "CLOSE") {
        // garage
        if (command.contains("garage door")) {
            if (cmd == "OPEN") {
                sendCommand(garageDoorOpen, ON)
            } else if (cmd == "CLOSE") {
                sendCommand(garageDoorClose, ON)
            }
        }
    }
end

New Binding: Hue Emulator - Amazon Echo integration
(p0lar) #19

Cool Thanks. that works better :slight_smile:
now to write one that does not need an IF for each word :slight_smile:


(Rob Nielsen) #20

Glad it helps, Please share the one that doesn't use an if for each word!