Skip to content

Commit

Permalink
[mycroft] Mycroft binding - Initial contrib (#11033)
Browse files Browse the repository at this point in the history
This binding will connect to Mycroft A.I. in order to control it or react to event by listening on the message bus.

Signed-off-by: Gwendal ROULLEAU <[email protected]>
  • Loading branch information
dalgwen committed Jul 21, 2021
1 parent 487dc0e commit 4691317
Show file tree
Hide file tree
Showing 53 changed files with 2,737 additions and 0 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
/bundles/org.openhab.binding.mqtt.homeassistant/ @davidgraeff
/bundles/org.openhab.binding.mqtt.homie/ @davidgraeff
/bundles/org.openhab.binding.myq/ @digitaldan
/bundles/org.openhab.binding.mycroft/ @dalgwen
/bundles/org.openhab.binding.mystrom/ @pail23
/bundles/org.openhab.binding.nanoleaf/ @raepple @stefan-hoehn
/bundles/org.openhab.binding.neato/ @jjlauterbach
Expand Down
5 changes: 5 additions & 0 deletions bom/openhab-addons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,11 @@
<artifactId>org.openhab.binding.mqtt.homie</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.mycroft</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.mystrom</artifactId>
Expand Down
13 changes: 13 additions & 0 deletions bundles/org.openhab.binding.mycroft/NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
This content is produced and maintained by the openHAB project.

* Project home: https://www.openhab.org

== Declared Project Licenses

This program and the accompanying materials are made available under the terms
of the Eclipse Public License 2.0 which is available at
https://www.eclipse.org/legal/epl-2.0/.

== Source Code

https://github.com/openhab/openhab-addons
110 changes: 110 additions & 0 deletions bundles/org.openhab.binding.mycroft/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Mycroft Binding

This binding will connect to Mycroft A.I. in order to control it or react to event by listening on the message bus.

Possibilies include :

- Press a button in OpenHAB to wake Mycroft without using a wake word.
- Simulate a voice command to launch a skill, as if you just spoke it
- Send some text that Mycroft will say (Using its Text To Speach service)
- Control the music player
- Control the sound volume of Mycroft
- React to all the aforementioned events ...
- ... And send/receive all other kind of messages on the message bus


## Supported Things

The only thing managed by this binding is a Mycroft instance.


## Discovery

There is no discovery service, as Mycroft doesn't announce itself on the network.


## Thing Configuration

The configuration is simple, as you just need to give the IP/hostname of the Mycroft instance accessible on the network.
The default port is 8181, but you could change it if you want.

```
Thing mycroft:mycroft:myMycroft "Mycroft A.I." @ "Living Room" [host="192.168.X.X"]
```

| property | type | description | mandatory |
|---------------|---------------------------------|-------------------------------------------------------------------------|-----------|
| host | IP or string | IP address or hostname | Yes |
| port | integer | Port to reach Mycroft (default 8181) | No |


## Channels

The Mycroft thing supports the following channels :


| channel type id | Item type | description |
|------------------------------|-----------|------------------------------------------------------------------------------------------------|
| listen | Switch | Switch to ON when Mycroft is listening. Can simulate a wake word detection to trigger the STT |
| speak | String | The last sentence Mycroft speaks, or ask Mycroft to say something |
| utterance | String | The last utterance Mycroft receive, or ask Mycroft something |
| player | Player | The music player Mycroft is currently controlling |
| volume | Dimmer | The volume of the Mycroft speaker. NOT FUNCTIONNAL. [SEE THIS POST TO SEE EVOLUTION](https://community.mycroft.ai/t/openhab-plugin-development-audio-volume-message-types-missing/10576) |
| volume_mute | Switch | Mute the Mycroft speaker |
| volume_duck | Switch | Duck the volume of the Mycroft speaker |
| full_message | String | The last message (full json) seen on the Mycroft Bus. Filtered by the messageTypes properties |


The channel 'full_message' has the following configuration available :

| property | type | description | mandatory |
|---------------|---------------------------------|-------------------------------------------------------------------------|-----------|
| messageTypes | List of string, comma separated | Only these message types will be forwarded to the Full Message Channel | No |


## Full Example

A manual setup through a `things/mycroft.things` file could look like this:

```java
Thing mycroft:mycroft:myMycroft "Mycroft A.I." @ "Living Room" [host="192.168.X.X", port=8181] {
Channels:
Type full-message-channel : Text [
messageTypes="message.type.1,message.type.4"
]
}
```

### Item Configuration

The `mycroft.item` file :

```java
Switch myMycroft_mute "Mute" { channel="mycroft:mycroft:myMycroft:volume_mute" }
Switch myMycroft_duck "Duck" { channel="mycroft:mycroft:myMycroft:volume_duck" }
Dimmer myMycroft_volume "Volume [%d]" { channel="mycroft:mycroft:myMycroft:volume" }
Player myMycroft_player "Control" { channel="mycroft:mycroft:myMycroft:player" }
Switch myMycroft_listen "Wake and listen" { channel="mycroft:mycroft:myMycroft:listen" }
String myMycroft_speak "Speak STT" { channel="mycroft:mycroft:myMycroft:speak" }
String myMycroft_utterance "Utterance" { channel="mycroft:mycroft:myMycroft:utterance" }
String myMycroft_fullmessage "Full JSON message" { channel="mycroft:mycroft:myMycroft:full_message" }
```

### Sitemap Configuration

A `demo.sitemap` file :

```perl
sitemap demo label="myMycroft"
{
Frame label="myMycroft" {
Switch item=myMycroft_mute
Switch item=myMycroft_duck
Slider item=myMycroft_volume
Default item=myMycroft_player
Switch item=myMycroft_listen
Text item=myMycroft_speak
Text item=myMycroft_utterance
Text item=myMycroft_fullmessage
}
}
17 changes: 17 additions & 0 deletions bundles/org.openhab.binding.mycroft/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.addons.reactor.bundles</artifactId>
<version>3.2.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.binding.mycroft</artifactId>

<name>openHAB Add-ons :: Bundles :: Mycroft Binding</name>

</project>
10 changes: 10 additions & 0 deletions bundles/org.openhab.binding.mycroft/src/main/feature/feature.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<features name="org.openhab.binding.mycroft-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0">
<repository>mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features</repository>

<feature name="openhab-binding-mycroft" description="mycroft Binding" version="${project.version}">
<feature>openhab-runtime-base</feature>
<feature>openhab-transport-http</feature>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.mycroft/${project.version}</bundle>
</feature>
</features>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright (c) 2010-2021 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.mycroft.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.ThingTypeUID;

/**
* The {@link MycroftBindingConstants} class defines common constants, which are
* used across the whole binding.
*
* @author Gwendal ROULLEAU - Initial contribution
*/
@NonNullByDefault
public class MycroftBindingConstants {

private static final String BINDING_ID = "mycroft";

// List of all Thing Type UIDs
public static final ThingTypeUID MYCROFT = new ThingTypeUID(BINDING_ID, "mycroft");

// List of all Channel ids
public static final String LISTEN_CHANNEL = "listen";
public static final String SPEAK_CHANNEL = "speak";
public static final String PLAYER_CHANNEL = "player";
public static final String VOLUME_CHANNEL = "volume";
public static final String VOLUME_MUTE_CHANNEL = "volume_mute";
public static final String VOLUME_DUCK_CHANNEL = "volume_duck";
public static final String UTTERANCE_CHANNEL = "utterance";
public static final String FULL_MESSAGE_CHANNEL = "full_message";

// Channel property :
public static final String FULL_MESSAGE_CHANNEL_MESSAGE_TYPE_PROPERTY = "messageTypes";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) 2010-2021 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.mycroft.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* The {@link MycroftConfiguration} class contains fields mapping thing configuration parameters.
*
* @author Gwendal ROULLEAU - Initial contribution
*/
@NonNullByDefault
public class MycroftConfiguration {

public String host = "";
public int port = 8181;
}
Loading

0 comments on commit 4691317

Please sign in to comment.