mKeRix / room-assistant

Presence tracking and more for automation on the room-level
https://www.room-assistant.io
MIT License
1.27k stars 122 forks source link

Hass.io #36

Closed grantalewis closed 6 years ago

grantalewis commented 6 years ago

I'd love to try this out. Any thoughts on creating an add-on for Hass.io users?

https://home-assistant.io/hassio/installing_third_party_addons/

mKeRix commented 6 years ago

I will try and get this accepted into the hassio community addon repository, but it may take 2 or 3 weeks until I can actually work on that (exams are keeping me busy).

Sorry to keep you waiting!

grantalewis commented 6 years ago

Thanks!

stickystyle commented 6 years ago

@mKeRix You don't have to get it listed in any specific repository, you can create your own config.json file in this github repo and we can utilize it directly.

https://home-assistant.io/developers/hassio/addon_development/

mKeRix commented 6 years ago

I spent a couple hours trying to figure this out today - and I still haven't got it working. I think my new Dockerfile should be correct for Hass.io usage, but I'm running into issues with the node dependencies. Some libraries won't compile in the alpine containers and I can't seem to find the missing libraries.

I have to put this on ice for a while, I'll take another look at this in the future. My current idea is moving away from the alpine base images proposed by all the examples, because then I can get around all the dependency issues. Or someone else with more hass.io know-how comes along. Sorry. :(

escoand commented 6 years ago

Is there any code in this repo we can use for further trying?

mKeRix commented 6 years ago

@escoand I just uploaded my local stash to the hassio branch: https://github.com/mKeRix/room-assistant/tree/hassio

escoand commented 6 years ago

Got it working: https://github.com/mKeRix/room-assistant/pull/50

grantalewis commented 6 years ago

Nice! Great work!

mKeRix commented 6 years ago

Quick update: I sat down and played with this stuff for a bit, but currently I'm stuck at an issue with Travis - the arm images get stuck in the build process (just freeze, no error).

It works locally though, so possibly I'll just have to complete the hass.io images manually.

jptrsn commented 6 years ago

Any update on the progress of this? I'd love to get room assistant running on my pi 3 as well, since I've already got the hardware and it would free up a pi zero for a different room.

escoand commented 6 years ago

It's already working. Download the hassio branch, put it in a subdirectory of addons and remove the line with "image". Then you should see the room-assistant add-on in the web interface.

jptrsn commented 6 years ago

It took me a little searching to find the right line to remove. It's in the base directory config.json file, here.

@mKeRix would it be okay to make a pull request against the readme.md file for this branch? I would be happy to add it as a sub-section, unless there are imminent plans for publishing.

escoand commented 6 years ago

Yes, I've feared it wasn't exactly enough but it was late and I was tired. :-) Good that you were able to find it after all...

mKeRix commented 6 years ago

After some digging I found the issue blocking the armhf and aarch64 builds before and managed to push out a release manually today. A dependency we used didn't continue their versioning correctly, so to get an updated working version I had to pull directly from their git page.

I created a repository for my builds here: https://github.com/mKeRix/hassio-repo - if people could test it and let me know if it works for them (and on which hardware) that would be awesome :)

Once I have the time to get the automatic releases working and clean up I will make this add-on official. Thanks for all the help & wait guys :)

escoand commented 6 years ago

I've error messages when enabling ble scanning on RPi3 (armhf):


module.js:538
    throw err;
    ^
Error: Cannot find module '../build/Release/binding.node'
    at Function.Module._resolveFilename (module.js:536:15)
    at Function.Module._load (module.js:466:25)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/room-assistant/node_modules/bluetooth-hci-socket/lib/native.js:3:15)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
mKeRix commented 6 years ago

I could reproduce the error, but unfortunately now I'm back to the issue I've had before (can also be seen on the latest Travis CI build). Despite no changes to the files since the last successful compilation the builds for armhf and aarch64 are now stuck at the the node-gyp configure stage for the usb module. :/

escoand commented 6 years ago

Where do they build the official addons? Maybe there we can have a look how they do it...

escoand commented 6 years ago

Can you please remove the image parameter of the config.json in the repo in the meanwhile? So everybody is able to install it by compiling locally.

escoand commented 6 years ago

Forget about it, its not working without all the other files...

mKeRix commented 6 years ago

Just a quick update: I've just started rewriting room-assistant from scratch, since the current code is somewhat messy. Hopefully I'll be able to fix these Hass.io issues on the way!

escoand commented 6 years ago

I'm not much familiar with node.js but is it really necessary to have nearly 600MB for just so less functionality?

REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
mkerix/room-assistant      latest-rpi          79837e848605        2 months ago        579MB
mKeRix commented 6 years ago

No, definitely not - that image still utilizes old build processes that I want to redo in the new version. The hass.io versions of the image are around 100MB big, which is much more reasonable.

Speaking of which: I deployed a new version of room-assistant to my Hass.io repository! It uses my new rewritten software, which already includes console, mqtt, ble and ibeacon functionality. It installs and runs fine on my Hass.io Raspberry, but I don't have a Bluetooth antenna to check whether the ble output runs correctly. Could anybody help me test this?

Use this repo: https://github.com/mKeRix/hassio-repo

Configuration is similar and mostly self explanatory name wise. Only important change you have to note is that instead of putting "enabled": true everywhere you now need to specify the components you want in the services array, e.g. ["console", "mqtt", "ble"]. The ibeacon component has been merged into the ble component.

Note: Be patient when room-assistant is starting, it's installing dependencies for the modules you activated in the background. As long as Hass.io shows it is running everything is fine. I built a cache system that skips installations after the first start, but unfortunately that does not seem to be working on Hass.io yet.

EDIT: The builds are updated to also support shell commands and gpio, although those will probably not be of much use on Hass.io. Overall I'm quite happy with the current state, I will test drive this at home for a bit and do some clean up work, then the new version should be ready for release. Only feature left to be implemented from my point of view are the regular Docker files.

MatsNl commented 6 years ago

Hi!

Also looking to try this out on Hassio (running rpi model 3). Running into 2 seemingly unrelated issues:

On the repo: I cannot add it as the schema in config file appears to be wrong:

WARNING (MainThread) [hassio.addons.data] Can't read /data/addons/git/6e66619d/room-assistant/config.json: expected string or buffer @ data['schema']['gpio']['ports'][0]. Got {'channel': 'str', 'pin': 'int', 'retain': 'bool?'}
expected string or buffer @ data['schema']['shell']['commands'][0]. Got {'channel': 'str', 'command': 'str', 'cron': 'str', 'regexp': 'str?', 'number': 'bool?', 'retain': 'bool?'}

Building as local repo with removed schema also has issues:

mKeRix commented 6 years ago

@MatsNl you can ignore the errors, the failing usb bindings module is optional.

As far as the schema goes: the current version in my Hass.io repo is running the rewritten alpha of room-assistant, which has a slightly different schema than described in the current README. I'm working on updating the configuration, until then here is an example for how you configure gpio and shell:

{
  "gpio": {
    "ports": [
        {
          "channel": "channel-to-post-in",
          "pin": 4,
          "retain": true
        }
    ]
  },
  "shell": {
    "commands": [
        {
          "channel": "channel-to-post-in",
          "command": "echo abc",
          "cron": "0 * * * * *",
          "regexp": "optional-regex-syntax",
          "number": false,
          "retain": false
        }
    ]
  }
}

The explanation for the options can be found in the current docs mostly, as the logic is similar. Only differences are that GPIO does not need to be polled anymore (reacts on changes automatically) and shell commands run using a cron schema with 6 stars (so * on each would mean every second). The GPIO component now also uses different pin numbering (BCM).

I fixed the schema issue, but currently pushes to Docker Hub from the branches are disabled. Until I release the official beta could you please grab the rewrite branch and build it locally? :)

MatsNl commented 6 years ago

No luck, when I press start once addon is installed, nothing happens and the config resets to default (empty) config.

also, gpio requires [""], otherwise the schema throws an error (i.e. cannot save, config not valid)

any suggestions? :)

mKeRix commented 6 years ago

Could you try re-adding my repo from above and trying the new image that should be available now? I re-enabled pushes for my alpha version and disabled the schema checks Hass.io does because they seem problematic together with the config schema we use. At least on my local raspi it worked when I checked it quickly.

MatsNl commented 6 years ago

Same issues, maybe the images arent refreshed before version number is incremented? I still get the config reset and error on gpio, also after deleting and reinstalling everything.. (actually did the re-add twice :) ) Any other thoughts?

after filling config, save, start, it returns to this: not a valid value for dictionary value @ data['options']. Got {'services': [], 'room': 'default-room', 'mqtt': {'url': 'mqtt://localhost', 'username': '', 'password': '', 'rejectUnauthorized': True}, 'ble': {'channel': 'room_presence', 'useAddress': False, 'whitelist': [], 'maxDistance': 0, 'updateFrequency': 0, 'processIBeacon': True, 'onlyIBeacon': False, 'majorMask': '0xFFFF', 'minorMask': '0xFFFF'}, 'gpio': [], 'shell': []}

and then after putting [""] for gpio:

18-07-10 22:17:15 INFO (SyncWorker_15) [hassio.docker.interface] Remove docker mkerix/room-assistant-armhf with latest and 1.0.0-alpha
18-07-10 22:17:18 INFO (MainThread) [hassio.addons.addon] Remove Home-Assistant addon data folder /data/addons/data/6e66619d_room-assistant
18-07-10 22:17:54 INFO (MainThread) [hassio.addons.git] Remove custom addon repository https://github.com/mKeRix/hassio-repo
18-07-10 22:20:05 INFO (MainThread) [hassio.addons] Load addons: 62 all - 0 new - 1 remove
18-07-10 22:21:08 INFO (MainThread) [hassio.addons.git] Clone addon https://github.com/mKeRix/hassio-repo repository
18-07-10 22:21:11 INFO (MainThread) [hassio.addons] Load addons: 63 all - 1 new - 0 remove
18-07-10 22:21:23 INFO (MainThread) [hassio.addons.addon] Create Home-Assistant addon data folder /data/addons/data/6e66619d_room-assistant
18-07-10 22:21:23 INFO (SyncWorker_18) [hassio.docker.interface] Pull image mkerix/room-assistant-armhf tag 1.0.0-alpha.
18-07-10 22:24:50 INFO (SyncWorker_18) [hassio.docker.interface] Tag image mkerix/room-assistant-armhf with version 1.0.0-alpha as latest
18-07-10 22:28:26 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/aiohttp/web_protocol.py", line 378, in start
    resp = await self._request_handler(request)
  File "/usr/lib/python3.6/site-packages/aiohttp/web_app.py", line 341, in _handle
    resp = await handler(request)
  File "/usr/lib/python3.6/site-packages/aiohttp/web_middlewares.py", line 88, in impl
    return await handler(request)
  File "/usr/lib/python3.6/site-packages/hassio/api/security.py", line 56, in token_validation
    return await handler(request)
  File "/usr/lib/python3.6/site-packages/hassio/api/utils.py", line 33, in wrap_api
    answer = await method(api, *args, **kwargs)
  File "/usr/lib/python3.6/site-packages/hassio/api/addons.py", line 156, in options
    body = await api_validate(addon_schema, request)
  File "/usr/lib/python3.6/site-packages/hassio/api/utils.py", line 92, in api_validate
    data = schema(data)
  File "/usr/lib/python3.6/site-packages/voluptuous/schema_builder.py", line 267, in __call__
    return self._compiled([], data)
  File "/usr/lib/python3.6/site-packages/voluptuous/schema_builder.py", line 587, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/usr/lib/python3.6/site-packages/voluptuous/schema_builder.py", line 379, in validate_mapping
    cval = cvalue(key_path, value)
  File "/usr/lib/python3.6/site-packages/voluptuous/validators.py", line 204, in _run
    return self._exec(self._compiled, value, path)
  File "/usr/lib/python3.6/site-packages/voluptuous/validators.py", line 249, in _exec
    return func(path, v)
  File "/usr/lib/python3.6/site-packages/voluptuous/schema_builder.py", line 769, in validate_callable
    return schema(data)
  File "/usr/lib/python3.6/site-packages/voluptuous/schema_builder.py", line 267, in __call__
    return self._compiled([], data)
  File "/usr/lib/python3.6/site-packages/voluptuous/validators.py", line 204, in _run
    return self._exec(self._compiled, value, path)
  File "/usr/lib/python3.6/site-packages/voluptuous/validators.py", line 282, in _exec
    v = func(path, v)
  File "/usr/lib/python3.6/site-packages/voluptuous/schema_builder.py", line 769, in validate_callable
    return schema(data)
  File "/usr/lib/python3.6/site-packages/hassio/addons/validate.py", line 214, in validate
    options[key] = _nested_validate_list(typ[0], value, key)
  File "/usr/lib/python3.6/site-packages/hassio/addons/validate.py", line 275, in _nested_validate_list
    c_options = _nested_validate_dict(typ, element, key)
  File "/usr/lib/python3.6/site-packages/hassio/addons/validate.py", line 287, in _nested_validate_dict
    for c_key, c_value in data_dict.items():
AttributeError: 'str' object has no attribute 'items'
mKeRix commented 6 years ago

My bad, I forgot to upload my changes to the hassio-repo last night... shouldn't have done it in a hurry, sorry. 😅 Removing the add on, readding the repository and then installing it again pulls everything completely new, at least according to the logs. Unfortunately I am now seeing a different issue: the command it is using to launch the container is incorrect. I am a bit limited today with testing/fixing, but I want to get all this fixed and a beta out tomorrow. So could you maybe wait a day before continuing? :)

Fyi: The Alpha images are available for regular Docker too now, under the rewrite and rewrite-arm32 tags!

MatsNl commented 6 years ago

Got it, another won't hurt I guess! 👍 Will try the new images on other Pis today then, and let you know if I run into anything

mKeRix commented 6 years ago

@MatsNl I actually found some additional time for debugging the Hass.io issue today and pushed a fix out. The version off my repo at least starts for me now. Would now appreciate any feedback on how GPIO and BLE services are running!

MatsNl commented 6 years ago

Cool,will give it a shot today! didn't have time yesterday unfortunately.

fyi, I 'm only able to test BLE in my setup

update- everything seems to be working! Scanning on hassio, regular raspbian and pizero raspbian now. Now to find out whether the mayor hassio freeze was due to roomassistant, if so there's some performance issue to be solved. Will let you know more later

mKeRix commented 6 years ago

Version 1.0 is officially out, including Hass.io support! 🎉

After spending today testing room-assistant across all the devices I have and making some final touches on the documentation I felt confident enough. :) If you find any issues let me know!