[SOLVED] Google Assistant responding to question about garage door

sensor
googleassistant
Tags: #<Tag:0x00007fe066323450> #<Tag:0x00007fe066323310>

(Peter Boivin) #1

I have been able to create a rule that Google Assistant will tell me if my garage door is open. I will be traveling for a few weeks this summer. I want to be able to ask Google Assistant from my phone if the the garage door is open or not. Any suggestions.


(Vincent Regaud) #2

Use a Switch item to reflect the garage door state. ON if open and OFF if closed. Tag the item as [" Lighting "] then ask GA “Is my garage door ON?”


(Stefan Haupt) #3

I didn’t even know google can answer such questions :wink:
Using the shortcuts you can even ask correctly: is my garage door open?
but I assume if it will respond back saying something like, lamp garage door is turned on.


(Vincent Regaud) #4

Correct it only supports switches so far


(Peter Boivin) #5

I tried changing Contact to Switch, but then the sensor is always off. I can’t query the relay because only in the off then on position will it trigger the garage to open. Using a rule I need to switch the relay switch to off. If it is in the on position, it doesn’t allow the physical garage button to work.
This code works for me to check if it is open. But how do I query Assistant to trigger this query?
rule “close Main reminder”
when
Time cron “0 */30 * ? * *”
then
logInfo(“org.openhab.rules”,“checking open garage door every 30 minutes”)
if (MainDoorSensor.state.toString == “OPEN”) {
say (“The main garage door has been left open”)
}
end


(Vincent Regaud) #6

You need another item. Changing your item to switch won’t work as you found out.


(Peter Boivin) #7

What do you mean? Do I need to add one that is a duplicate of my sensor?
Contact MainDoorSensor “Door Sensor [%s]” { gpio=“pin:16 debounce:10 activelow:yes” }


(Stefan Haupt) #8

I think he means you will need a dummy switch that will be toggled on/off by a rule depending on your contact status.


(Peter Boivin) #9

I’ll try that. Thanks.


(Peter Boivin) #10

I got it to work.
This is for anyone else who comes this way with same problem.

Switch MainDoorSensorDummy "Door Sensor Dummy" [ "Switchable" ]
//Garage Door Sensor Dummy rule
rule "Manual: Set Door Sensor Dummy to true Door Sensor position"
when
    Item MainDoorSensor changed
then
    if(MainDoorSensor.state.toString == "OPEN") {  
        logInfo("org.openhab.rules","Changing Main Garage dummy sensor to open because real sensor is open")    
        MainDoorSensorDummy.sendCommand(ON)
    } else 
    {
        logInfo("org.openhab.rules","Changing Main Garage dummy sensor to open because real sensor is closed")
        MainDoorSensorDummy.sendCommand(OFF)
    }
end

(Vincent Regaud) #11

Glad you got it!
Couple of bits, because your else clause doesn’t have a test, the switch could be turned off if OH restarts or the item file is updated so I have added the first line.
Also because your proxy item doesn’t have a binding, a postUpdate in sufficient.
Finally because the item MainDoorSensor is a Contact Item, OPEN is a valid state so you don’t need the toString and the quotes in your if statement.

//Garage Door Sensor Dummy rule
rule “Manual: Set Door Sensor Dummy to true Door Sensor position”
when
    Item MainDoorSensor changed
then
    if (MainDoorSensor.state == NULL) return; // Avoid running the rule on restart or update of item file
    if (MainDoorSensor.state == OPEN) {
        logInfo("org.openhab.rules","Changing Main Garage dummy sensor to open because real sensor is open")
        MainDoorSensorDummy.postUpdate(ON)
    } else {
        logInfo("org.openhab.rules","Changing Main Garage dummy sensor to open because real sensor is closed")
        MainDoorSensorDummy.postUpdate(OFF)
    }
end

Last but not least, when publishing code, please use the codes fences, thanks.