Hi,
I needed to send custom commands to custom devices, so I found a trick to achieve this.
I experienced this with a gate that can be either fully opened either ~20% open for pedestrians by the original remote. To bypass the remote I have mounted two relays on the gate to be able to control it. To control the relays I have an ESP8266 that OpenHAB can send any commands to, as I interpret them in the ESP82SS code. But it will work with any device supported by OpenHAB and not by Google Assistant.
The main difficulty was to be able to talk to Google Assistant (will be referred as GA from now) and catch the event in my OpenHAB to sent custom commends afterwards.
What you need before going further :
- Some custom device to send commands to (for me it’s the ESP8266, but as said earlier any device will work).
- There’s a great tuto here on how to connect devices to OpenHAB
- Install the openHAB Cloud Connector add-on (Paper UI => Add-Ons => MISC. ==> openHAB Cloud Connector)
- Make it work with GA. (It’s all explained here)
The trick now is pretty simple, you will need to add a proxy item in your .items
:
Rollershutter Gate_Rollershutter "Gate" {ga="Garage"}
-
Rollershutter
=> this is supported by GA. -
"Gate"
=> the name you will see in your GA’s app. -
{ga="Garage"}
=> make it available in your GA configuration.
Next step, create the rule to catch events and send custom commands.
rule "RuleGate"
when
Item Portail_Rollershutter received command
then
switch(Portail_Rollershutter.state) {
case 0: {
//Open
Test_Relay.sendCommand("OPEN")
}
case 100: {
//Close
Test_Relay.sendCommand("CLOSE")
}
case 80: {
//Something else
Test_Relay.sendCommand("SOMETHING_ELSE")
}
}
end
Explanation is pretty straight forward, when the proxy item receive a command, it triggers the switch
and then sends a command "OPEN"
or "CLOSE"
to Gate_Relay
which is defined in my .items
file as :
Number Test_Relay {channel="mqtt:topic:**********:*******"}
But here you can define whatever Item
you want. You can also add multiple lines in one case
to have multiple commands sent when the GA’s routine is triggered.
Talking about GA’s routine, the next step is to create a routine inside GA’s app to trigger the commands in the rule. For this example, one of the routines will be
This will trigger the case 80
in my .rules
.
And that’s it. Now you can customize this example to have multiple commands sent by the .rule
to any device by saying whatever you want to GA.
I encountered many issues while working on this trick. So feel free to ask if you have yourself an issue, or if I’m nor clear enough, I will edit this tuto. If you need help with the ESP8266 part I might help too.