Moving to OpenHAB to get Google Home support for free?

Alexa, Google Home and Siri

Moderator: leecollings

Ankan
Posts: 48
Joined: Thursday 09 November 2017 20:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Moving to OpenHAB to get Google Home support for free?

Post by Ankan »

@Gravityz

I have start my migration from MQTT 1.4 to 2.5 with help from your guide.
How do you transformate switches so you can both control them and get values from Domoticz?

I added that MQTT Binding, MQTT Broker and General MQTT Thing as in your guide. But then I guess I have to add a Switch Channel to control a switch.

As I don't use you deep kind of hierarchy I have to filter my message with for example regex on idx as I did with MQTT 1.x.
Do you have any solution for that or do you put every device in Domoticz in seperate rooms to get that hierarchy?

In MQTT 1.x I added filtered by IDX with (?s).*idx\".?.?.?123,.* and the problem was solved.

When I got this working, next step will to create correct json message to send to domoticz via mqtt.
Ankan
Posts: 48
Joined: Thursday 09 November 2017 20:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Moving to OpenHAB to get Google Home support for free?

Post by Ankan »

I think I got it working but I have to test and verify before I write it down here.
Ankan
Posts: 48
Joined: Thursday 09 November 2017 20:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Moving to OpenHAB to get Google Home support for free?

Post by Ankan »

Okey, now it's done and this is how I did it.
I started by following Gravityz instructions that I got by mail but with some modifications.

Everything is done in PaperUI when nothing else is specified

1. Add MQTT 2.x binding under Add-ons

2. Create a MQTT broker thing
2a. Add new Thing with the (+) button
2b. Select MQTT broker
2c. Give it a name, ip address and port (I'am using external MQTT mosquitto broker) I think configuration is self explained.

3. Create a MQTT binding thing
3a. Add new Thing with the (+) button
3b. Select MQTT Binding
3c. Select Add manually
3d. Select Generic MQTT Thing
3e. Give it a name and ThingID like Domoticz and select your MQTT broker as bridge

4. Create a channel (One channel for every device you want to control)
4a. Select your created MQTT Binding Thing
4b. Select Add Channel with the (+) button
4c. Select Number value
4d. Fill in the properties like this:
... Channel Id: idx123 (Where 123 is your idx number. Like you did in that item file before with MQTT 1.x)
... Label: Outdoor temperature (Name of your choice)
... MQTT state topic: domotic/out
... Incomming value transformations: REGEX:(.*\"idx\" : 117,.*)∩JSONPATH:$.svalue1

* If your device is a dimmer or a switch you choose that in step 4c.
* ... and set incomming value transformations to: REGEX:(.*\"idx\" : 14,.*)∩JS:get_state.js

get_state.js

Code: Select all

(function(i){
    var parsed = JSON.parse(i);
    if (parsed.nvalue == 0)
    {
        return "OFF"
    }
    else if (parsed.nvalue == 1)
    {
        return "ON"
    }
    else if (parsed.nvalue == 2)
    {
        return parsed.svalue1
    }
})(input);
5. We will create a roule like in the MQTT 1.x example erlier in this thread. And to get that working we need a controllable devices group
5a. Add new Item with (+) button
5b. Fill in the properties like this:
... Name: Controllable devices
... Label: gControl (This must be same as in that rule file)
... Type: Group
... Base type: None

default.rule

Code: Select all

rule "Send MQTT message on Light command"
when
        Member of gControl received command
then
        var idxStartPos = triggeringItem.name.indexOf("idx") + 3
        var idxStopPos = triggeringItem.name.length()
        var myString = ""

        if (receivedCommand.toString() == "ON" || receivedCommand.toString() == "OFF")
        {
                var cmd = receivedCommand.toString().toLowerCase.toFirstUpper()
                myString = '{\"command\": \"switchlight\", \"idx\": ' + triggeringItem.name.substring(idxStartPos,idxStopPos) + ', \"switchcmd\": \"' + cmd + '\"}'
        }
        else
        {
                myString = '{\"command\": \"switchlight\", \"idx\": ' + triggeringItem.name.substring(idxStartPos,idxStopPos) + ', \"switchcmd\": \"Set Level\", \"level\": ' + receivedCommand.toString() + '}'
        }

        val actions = getActions("mqtt","mqtt:broker:290eaf06")
        actions.publishMQTT("domoticz/in", myString)
end
6. If you are adding a temperature sensor they have to have a termostat group to get it working with Google Assistant
6a. Add new Item with (+) button
6b. Fill in the properties like this:
... Name: Outdoor (Give it a name of your choice. This is what you will see in google home)
... Label: gOutdoor_Termostat (Give your group a label of your choice)
... Type: Group
... Base type: None

7. Create items (If you migrate from MQTT 1.x to 2.x I guess you already have them but I explain it anyhow)
7a. Add new Item with (+) button
7b. Fill in the properties like this:
... Name: Outdoor temperature (Give it a name of your choice)
... Label: idx123 (Where 123 is your idx number. Like you did in that item file before with MQTT 1.x)
... Type: Number (Number if it is a temp sensor, switch if it is a switch and dimmer if it is a dimmer :-)
... Parent groups: gOutdoor_Termostat (If it is a temperature sensor it have to have a termostat group for each one of them. If it is a Controllable device add that groupname you added above like gControl)

8. Let's connect our incomming data things with our devices.
8a. Under Things, your created Domoticz Thing and all your channels you can link to corresponding item.
8b. Select (+) button to add that link and choose corresponding item.

9. To get everything running in google home, we have to add a tags like in that old .items-file
9a. Install REST Documentation User interface if you already have it installed
9b. Go in to that Rest API interface from openhab start page
9c. Under items choose GET /items and press Try it out!
9d. Select and copy the Responding Body and paste to notepad
9c. On every temperature sensor item you add the tag "CurrentTemperature"
9c. On every termostat group item you add the tag "Thermostat"
9c. On every light item you add the tag "Lighting"
9c. On every outlet switch item you add the tag "Switchable"
9d. Before you do next step. Be sure to have a backup of your items in case of.
9e. Now select all text notepad and paste into PUT /items and press Try it out!

10. Tell your google home to update my devices

Notice: It's lot of work but you can take a shortcut if you know what you are doing by using Rest API to add all items and things instead of using the PaperUI. Maybe it's possible to migrate items from the .items-file to the new builtin storage by using that Rest API. I have not tried it but maybe you can get your items, copy the body, delete them and paste and add them back like above.
I read somewhere that you can't use PaperUI in Simple mode if you want to add links and items. You find that setting under Configuration --> System --> Item Linking
Ankan
Posts: 48
Joined: Thursday 09 November 2017 20:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Moving to OpenHAB to get Google Home support for free?

Post by Ankan »

When I ask Google for temperature I get the current temperature but also information that the device is inactive and that it cannot be reached and that I may need to configure it again.
I understand why it say it is inactive. That is because I have not added that homekit:TargetHeatingCoolingMode string. But how about that last part that it cannot be reached and I may need to configure it again?

It still works and the temperature updates.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests