Been following and playing around with Mycroft and OpenHab2, A post by Tommy who worked on an integration of mycroft and openhab2 via rest api
If no one had seen it before here it is.
Been following and playing around with Mycroft and OpenHab2, A post by Tommy who worked on an integration of mycroft and openhab2 via rest api
If no one had seen it before here it is.
Hi,
the error is related to one of the dependence. Could you verify if you have installed build-essential package?
dpkg -l build-essential
Hi Mortommy,
below is the output of a vanilla picroft setup:
root@picroft:/home/pi# dpkg -l build-essential Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Architecture Description +++-=====================================================-===============================-===============================-=============================================================================================================== ii build-essential 11.7 armhf Informational list of build-essential packages
The path seems to be a bit off:
python2.7 is in /usr/local/lib/python2.7 and in /usr/local/local/lib/python2.7 rather than in /usr/lib/ directly
Hi @mortommy,
Iâm pleased to say my Mycroft 1 is now able to control my OpenHAB2 system (yay!), and am impressed with my new ability to control devices by voice!
The best part is openhab-skill connects directly to OpenHAB2 via the local REST API, without the need to go via an external MyOpenHAB portal - this architecture feels a lot more secure to me.
Iâd like to report two skill bugs which I had to patch locally to get the skill working - both are likely part of recent commits to add internationalisation.
My software engineering skills are rusty, so a github pull-request is beyond me - at least for the moment!
Bug 1 - âit-itâ test causes SyntaxError
After finding via msm, that the openhab-mycroft skill would not start, I started debugging by looking for issues in the skill log file:
$ apt list --installed |grep mycroft-core
mycroft-core/unknown,now 0.9.13 armhf [installed]
$ vim /var/log/mycroft-skills.log
18:24:02.226 - mycroft.skills.core:load_skill:163 - ERROR - Failed to load skill: openhab-mycroft
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/mycroft_core-0.9.13-py2.7.egg/mycroft/skills/core.py", line 131, in load_skill
skill_descriptor["name"] + MainModule, *skill_descriptor["info"])
File "/opt/mycroft/skills/openhab-mycroft/__init__.py", line 257
if self.lang == "it-it"
^
SyntaxError: invalid syntax
My Mark 1 is set to default âen-usâ (although Iâm British). Adding brackets around the logical test didnât fix the comparison, so I commented out the Italian language tests completely in init.py.
I added hash comments to lines 257-259 and 268-270.
This got further, but not quite success.
Bug 2 - SyntaxError: Non-ASCII character
The skill still threw an error:
vim /var/log/mycroft-skills.log
19:16:41.580 - mycroft.skills.core:load_skill:163 - ERROR - Failed to load skill: openhab-mycroft
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/mycroft_core-0.9.13-py2.7.egg/mycroft/skills/core.py", line 131, in load_skill
skill_descriptor["name"] + MainModule, *skill_descriptor["info"])
File "/opt/mycroft/skills/openhab-mycroft/__init__.py", line 265
SyntaxError: Non-ASCII character '\xc3' in file /opt/mycroft/skills/openhab-mycroft/__init__.py on line 265, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
Line 265 includes a non-ASCII unicode character (requestType == "l'umiditĂ ")
.
Based on Python PEP0263, I added a line at the top of define a source code encoding at the top of init.py](https://github.com/openhab/openhab-mycroft/blob/master/init.py).:
> # Copyright (c) 2010-2017 by the respective copyright holders.
> # -*- coding: iso-8859-15 -*-
With the work around (commenting out âit-itâ) and fix (adding encoding), the skill started, connected first time and started working. It took 10 mins and many ON / OFF tests for the novelty of speech control to wear off!
Initial tests (Hey Mycroft, list openhab items
) suggest openhab-skill is using the OpenHAB item file Item Name, rather than the Item Label which is not ideal as my item names are camel-case variables not designed for human-use, and especially hard to speak.
Experimentation continues⌠thanks for developing the binding, and hope the reports above help.
Thanks so much for reporting this in detail @FloatingBoater.
Iâm going to ping my colleague @forslund on this one, who may have more information to assist.
Again, thanks for providing so much detail - hugely appreciated.
Kind regards,
Kathy
Hi,
Thanks for the encouragement - Iâm still hacking away, although working on Xtend, Java, and Python at the same time is not to be recommended!
I now have fixes for both issues, which might get the Italian support working as originally intended. Iâm not quite ready to attempt a GitHub pull request so apologies for the attempt at a manual patch.
Edit init.py and âŚ
Bug 1 - âit-itâ test causes SyntaxError
After some reading, this is a simple Python syntax error.
Change line 257 to add brackets and a colon:
if (self.lang == "it-it"):
Change line 268 to add brackets and a colon:
if (self.lang == "it-it"):
Bug 2 - SyntaxError: Non-ASCII character
Add a new line at the top to specify encoding:
# Copyright (c) 2010-2017 by the respective copyright holders.
# -*- coding: iso-8859-15 -*-
Iâve also added a log line for the current language settings at line 57:
LOGGER.debug("self.lang :" + self.lang + ":")
supported_languages = ["en-us", "it-it"]
Seems Iâm too late to the party and all is figured out
Iâd like to recommend using
# -*- coding: utf-8 -*-
since itâll be more future-proof and can handle practically any language.
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.
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:
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!
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
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âŚ
Before working with Mycroft, Iâd suggest checking thatâŚ
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.
your OpenHAB server
:8080/rest/items"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.
Once you have tested OpenHAB (and only after youâve tested⌠), you can start on 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.
cat /etc/mycroft/mycroft.conf cat /home/mycroft/.mycroft/mycroft.conf
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.
sudo service mycroft-skills restart tail -f /var/log/mycroft-skills.log python -m mycroft.client.text.main --quiet
refresh openhab items
connectionpool
line connecting from Mycroft into OpenHAB and hear All right. I found nn items
list openhab items
Found the following items: ....
and a list of the Item names.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.