Mycroft - OpenHab2 Skill

Seems I’m too late to the party and all is figured out :slight_smile:

I’d like to recommend using

# -*- coding: utf-8 -*-

since it’ll be more future-proof and can handle practically any language.

1 Like

Hi @FloatingBoater , thank you for your post. If you won’t add a PR, could you please open a new issue in the official repo?
thank you.

Changed applied, thank you again for your contribution.

Hi @mortommy,

Thanks for applying the changes - unfortunately, I’m not (yet) up to creating a branch and a PR myself.

Would you mind checking the change to line 269 again please?

The first bracket is in the wrong place:

(if self.lang == "it-it"): 

My code has:

if (self.lang == "it-it"):

The githib code gives an error:

File "/opt/mycroft/skills/openhab-mycroft/__init__.py", line 269
(if self.lang == "it-it"):
^
SyntaxError: invalid syntax

Fix applied. Thank your for your contribution.
About the list of items and your request of having listed the labels instead of the items name, could you crate a new issue?
Thank you.

1 Like

Hello,
I’m struggeling with the usage of the openhab2 skill. Installation went fine on my picroft but I cant figure out how to correctly define items in openhab. I used the item definitions from the skill example but mycroft always replies that the openhab items are unknown.
An help much appreciated

Thank you

Could you post an example of your items definition in openHAB?

I have defined these two items (besides others).

Switch GoodNight “Good Night” [ “Switchable” ]
Switch Sonos “Sonos” [ “Switchable” ]

Hi,

I suggest we take this one step at a time.

Can you switch these Items on/off in a SiteMap with default config?
e.g.:

# Your install may have a slightly different path to conf/
# /opt/openhab/conf/sitemaps/ohtest.sitemap

sitemap ohtest label="OpenHAB Test" {
    Frame label="OpenHAB Mycroft Test" {
        Switch item=GoodNight
        Switch item=Sonos
    }
}

The items you show are missing the binding configuration which would only work if these are dummy items designed to trigger a state change in a rule:
https://docs.openhab.org/configuration/items.html

Switch GoodNight “Good Night” [ “Switchable” ] {channel="details of binding"}

If that works, as the Mycroft binding is similar to Homekit / Alexa, I followed those instructions:
https://docs.openhab.org/addons/ios/alexa-skill/readme.html
https://docs.openhab.org/addons/ios/homekit/readme.html

From the three main tag types, I have Lighting and Switchable working:

  • Lighting - Switch, Dimmer, Color
  • Switchable - Switch, Dimmer, Color
  • CurrentTemperature - RO Number

I would then ssh into Mycroft and use the debug console to look what is happening - you can also type in speech commands:

python -m mycroft.client.text.main --quiet

One suggestion is to define multiple Items bound to the same Channel/ Thing, each with different label text to make it easier to speak a command.

With this item, I can say ‘switch on bedside radio’:

Switch Bed_Radio "Bedside Radio" <radio> ["Switchable"] {channel="zwave:detail removed"}

I’m going to add some debug code to my local copy of the skill to understand if the intent is parsed from the Item Name (e.g. Bed_Radio) or the Item Label (e.g. Bedside Radio) as the speech Hey Mycroft, list openhab items lists the non-human-readable Item Names.

Hi @mortommy,

After some testing, I’ve confirmed that the binding uses the OpenHAB Item Label, and not the OpenHAB Item Name for speech/ intent recognition.

The test to prove this is pretty simple - add a test Item to the OpenHAB *.items file with a very different Name and Label text:

Switch fish "bicycle" ["Switchable"] {channel="binding detail removed"}

Then, fire up the Mycroft test console, refresh the Items from OpenHAB and try turning on fish and bicycle:

python -m mycroft.client.text.main --quiet

At the prompt, simulate saying text whilst watching the logs (same as saying Hey Mycroft…):

refresh openhab items

The skill pulls the list of items with tags and reads the out the Names.
The Name is a variable name so often non-human readable - useful for debug, but not very ‘speakable’!
This is what made me suspect the skill was using Name rather than Label!

Say the Name - fish

Mycroft recognises the intent, parrots back the command, but NOTHING HAPPENS. This is slightly misleading, but could well be the Mycroft intent parser, rather than the OpenHAB binding.

turn on fish
>> turn on fish

Say the Label - bicycle

turn on bicycle
>> switch on bicycle

Mycroft recognises the intent from the Label, fires a call to the OpenHAB REST API to turn on the Item named ‘fish’ correctly:

requests.packages.urllib3.connectionpool - DEBUG - http://openhab.home:8080 "POST /rest/items/fish HTTP/1.1" 200 0

So, that seems to work well, and as expected.

My testing so far works for ["Switchable"] and ["Lighting"], but I’ve not managed to ask for the temperature of a ["CurrentTemperature"] sensor. When I ask, what is radiator temperature, the Weather skill gives me a forecast!

So, the issue is more of an improvement request…

Thanks again!

First: Thank you very much for your detailed response!
I think the skill is somehow not correctly installed.
When i ask: "Hey Mycroft, refresh openhab items"
The reply is : "All right. I found 0 items. "
Which is not true, because i have plenty of items.

Maybe you can confirm that my configuration is (in)correct (which I added manually)
in mycroft.conf /usr/local/lib/python2.7/site-packages/mycroft_core-0.9.14-py2.7.egg/mycroft/configuration/

// =================================================================
// All of the follow are specific to particular skills and will soon
// be removed from this file.
// =================================================================

“wifi”: {
“setup”: false
},
“openHABSkill”: {
“host”: “192.168.1.244”,
“port”: “8080”
},
“ConfigurationSkill”: {
“max_delay”: 60
},

Thanks again for your support

Hi,

My experience of many years of integrating complex systems is that breaking tasks down into individual steps, each checked with testing of some sort, is the best approach. Finding where a log file is, and looking to see what it contains tests your understanding.

More often than not, logs have shown a component didn’t work the way I thought, and I learned something. It’s also motivating to see a part of a complex system work - even if it’s a small part.

With that in mind, here’s a step-by-step…

Configure and test OpenHAB

Before working with Mycroft, I’d suggest checking that…

  • Does your OpenHAB install work?
  • Can you switch your desired Items on or off via an OpenHAB SiteMap?
  • Can you see status changes on an OpenHAB web interface, and see the changes on the ESH console?

I say that particularly as the Item definitions you gave earlier don’t include any binding information, and the Sonos binding has many Channels to control (i.e. not just on/ off, like a simple switch). Start simple - confirm you understand and have tested on /off of one device in OpenHAB.

In case you’ve not seen then, there are quite good confg docs here:
https://docs.openhab.org/configuration/index.html

I access the OpenHAB console by SSH’ing into my server, and then SSH’ing a second time locally into OpenHAB. If you use OpenHABian, this may be simpler with a web-based log viewer.
https://docs.openhab.org/administration/console.html

Before moving to Mycroft, you can also manually test the interface Mycroft will use - REST.

  • test the openHAB REST interface by manually opening a web browser and going to: http://your OpenHAB server:8080/rest/items
  • This should show a JSON formatted list of all your items which is not easy to read, but very useful.
  • Do the same as Mycroft will do, and use CONTROL-F in the browser to search for Switchable or Lighting tags.
    You should see Items with :
"tags":["Switchable"],
"tags":["Lighting"],

Your last post suggests you should be able to browse to:
http://192.168.1.244:8080/rest/items

If you don’t get a list of items, check the OpenHAB console, any firewalls (none on a RPi, but you might be using a PC/ Mac), if the software is running, and your IP addresses.

Configure and test Mycroft OH2 binding - based on a Mark 1

Once you have tested OpenHAB (and only after you’ve tested… :slight_smile: ), you can start on Mycroft.

  • Update, install and test Mycroft and the OH2 binding by SSH’ing into Mycroft:
sudo msm update
msm search openhab
msm info openhab-skill
msm install openhab-skill
msn list

I didn’t see msm list the openhab-skill as installed, but it was there and worked.

  • Mycroft skill config seems to be in two places:
cat /etc/mycroft/mycroft.conf
cat /home/mycroft/.mycroft/mycroft.conf
  • I found adding openHABSkill params into /home/mycroft/.mycroft/mycroft.conf worked for me.
cat /home/mycroft/.mycroft/mycroft.conf
{
  "tts": {
    "mimic": {
      "path":"/usr/local/bin/mimic"
    }
  },
  "SkillInstallerSkill": {
    "path": "/usr/local/bin/msm"
  },   <<<<<<======= N.B. this extra comma!
  "openHABSkill": {
    "host": "youropenhabservername",
    "port": "8080"
  }
}

N.B - note the extra comma before the new openHABSkill block.

  • Restart the skills and watch the logs:
sudo service mycroft-skills restart

tail -f /var/log/mycroft-skills.log
python -m mycroft.client.text.main --quiet
  • You should see lots of scrolling debug information, either by tailing the log file directly, or by using python to open the Mycroft console. The console allows you to type in a spoken command - ideal for testing.
  • Speak (or type into the console) refresh openhab items
  • You should see a connectionpool line connecting from Mycroft into OpenHAB and hear All right. I found nn items
  • If you don’t - check the OH2 REST interface via a browser again, and look for errors in both OH2 and Mycroft logs.
  • Speak (or type into the console) list openhab items
  • You should hear Found the following items: .... and a list of the Item names.
  • If the list isn’t what you’ve tagged in the OH2 config, check the OH2 *.items config - again, use the manual browser test above to look for the tags Mycroft is looking for (Switchable, Lighting).

You should now be able to say something like… turn on mydevice light, and see Mycroft connect to OpenHAB and the Item turn on.

I hope this helps you (and hopefully others…) get Mycroft turning your home automation on and off via OpenHAB.

1 Like

First a big thank for this impressive and comprehensive guide. Will help me a lot.
Sadly it was all my fault. In the end restarting openhab did the trick for me.

1 Like

Hi. I do have a boatload of rest/items, skill installed, mycroft.conf modified. A wonderfully large working openhab install but once I try to boot the mark1 it never gets beyond the yellow lights. Any help would be great!

Thanks
Guy

Hi there @oakguy, saw your post in another category. If your Mark 1 is stuck at Yellow Eyes there are a couple things we can try. This is not necessarily related to the OpenHAB2 Skill.

  • First, we stop and start the Skills service by doing;

sudo service mycroft-skills stop && sudo service mycroft-skills start

  • The other thing to try is an update of the device

sudo apt-get update && sudo apt-get install

  • Next, if these don’t work, try a couple of “hard reboots” - pull the power out, leave 10 seconds then power back in.

Please let me know how you go.

Just to add some links that may help…

@oakguy, as you mention installing lots of skills, and editing mycroft.conf, you’re probably no stranger to the command line and using it to update.

For reference, there is a list of diagnostic eye colours here:

It is worth mentioning that the most recent update (18.2.0) is different, and for my Mark One at least, took MANY reboots for both packages, display firmware, and skills.

After running several previous updates, the extra steps came as a surprise - including a period with yellow eyes. The new eye colours with scrolling progress messages on the face LED matrix are actually pretty good, so to help set your expectations, here’s the official Mycroft upgrade instruction video:

From memory, custom config moved from /home/mycroft/.mycroft/mycroft.conf to /etc/mycroft/mycroft.conf

Worst case, unscrew the case, and re-image the uSD card:

Fresh installs generate a new device ID so you’ll need to re-register on https://home.mycroft.ai/ .

Good luck…

1 Like

Thank you! Downloaded the current image, paired and on my way again with Openhab!

Guy

1 Like

Thank you very much for that very comprehensive documentation. It helped me a lot to get openhab skill working on mycroft.

@mortommy I’ve got the skill installed on mycroft and it recognizes two .items (thermostat target and current temp) but won’t adjust or read temp from it - here’s .items and dump from skill log - any ideas? It does list the items in response to ‘list openhab items’

Openhab panel and paper UI do successfully control the thermostat.

.items:

Group Thermostat “Main Thermostat” [“Thermostat”]
Number ThermostatSetPoint “Thermostat Target [%.1f F]” (Thermostat) [“TargetTemperature”] {channel=“nest:thermostat:XXX:set_point”}
Number MainThermostatCurrentTemp “Indoor Temperature [%.1f F]” (Thermostat) [“CurrentTemperature”] {channel="nest:thermostat:XXX:temperature}

and dump from skills.log:

20:57:12.008 - SKILLS - DEBUG - {“data”: {“session”: “xxx”, “utterance”: “hey jarvis”}, “context”: null, “type”: “recognizer_loop:wakeword”}
20:57:15.037 - SKILLS - DEBUG - {“data”: {“session”: “xxx”, “utterances”: [“adjust main thermostat to 80 degrees”], “lang”: “en-US”}, “context”: {“client_name”: “mycroft_listener”, “ident”: “xxx”}, “type”: “recognizer_loop:utterance”}
20:57:15.047 - SKILLS - DEBUG - {“data”: {“skill_id”: “openhab-mycroft.openhab”, “utterances”: [“adjust main thermostat to 80 degrees”], “lang”: “en-US”}, “type”: “skill.converse.request”, “context”: null}
20:57:15.060 - SKILLS - DEBUG - {“data”: {“skill_id”: “openhab-mycroft.openhab”, “result”: false}, “type”: “skill.converse.response”, “context”: {}}
20:57:15.216 - SKILLS - DEBUG - {“data”: {“openhab_mycroft_openhabThermostatStatusKeyword”: “regulate”, “confidence”: 0.3333333333333333, “target”: null, “openhab_mycroft_openhabItem”: “main thermostat”, “tags”: [{“from_context”: false, “end_token”: 0, “key”: “adjust”, “entities”: [{“data”: [[“regulate”, “openhab_mycroft_openhabThermostatStatusKeyword”]], “confidence”: 1.0, “match”: “adjust”, “key”: “adjust”}], “start_token”: 0, “match”: “adjust”}, {“from_context”: false, “end_token”: 2, “key”: “main thermostat”, “entities”: [{“data”: [[“main thermostat”, “openhab_mycroft_openhabItem”]], “confidence”: 0.5, “match”: “main thermostat”, “key”: “main thermostat”}], “start_token”: 1, “match”: “main thermostat”}, {“from_context”: false, “confidence”: 0.5, “end_token”: 4, “key”: “80”, “entities”: [{“data”: [[“80”, “openhab_mycroft_openhabTempValue”]], “confidence”: 0.5, “match”: “80”, “key”: “80”}], “start_token”: 4, “match”: “80”}], “utterance”: “adjust main thermostat to 80 degrees”, “openhab_mycroft_openhabTempValue”: “80”, “intent_type”: “openhab-mycroft.openhab:SetTemp_StatusIntent”}, “type”: “openhab-mycroft.openhab:SetTemp_StatusIntent”, “context”: {“target”: null, “ident”: “xxx”, “client_name”: “mycroft_listener”}}
20:57:15.221 - openhab-mycroft_openhab - ERROR - Item not found!
2

Hi,
are you looking for the item by name or by label? Since name in items definition can be not human language oriented, items are searched by label.