Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Home Assistant Addon Implementation #1087

Closed
15 tasks done
angelnu opened this issue Jan 22, 2021 · 197 comments
Closed
15 tasks done

Home Assistant Addon Implementation #1087

angelnu opened this issue Jan 22, 2021 · 197 comments
Assignees
Labels
💡 enhancement-ideas New feature or change request 🙏 help wanted Extra attention is needed

Comments

@angelnu
Copy link
Contributor

angelnu commented Jan 22, 2021

Describe the solution you'd like
Being able to run RaspberryMatic on Home Assistant OS (https://github.com/home-assistant/operating-system) as an installable Addon

cf. home-assistant/addons#1751

Add-on status

Installation/Test HOWTO

!! The following HOWTO is highly experimental. Use at your own risk !!

Please find here a short howto for installing the latest developer versions of Home-Assistant OS for testing the RaspberryMatic HomeAssistant Add-on integration and functionality related to a RPI-RF-MOD or HM-MOD-RPI-PCB connected either via GPIO on a RaspberryPi/Tinkerboard or via a HB-RF-USB-2/HB-RF-ETH.

Installation HOWTO:

  1. Download the latest haos_XXXX-6.0.. file for your hardware platform from
    https://github.com/home-assistant/operating-system/releases
  2. Perform a fresh install on microSD card (via Etcher) or import fresh OVA in your virtual environment
  3. If you use a RaspberryPi, Tinkerboard or ODROID and want to use a RPI-RF-MOD/HM-MOD-RPI-PCB directly connected to the GPIO bus, make sure to...
    • either mount the flashed sd card locally to be able to access the config.txt file located on the boot partition.
    • or use a SSH Login later on to log in via SSH remotely
    • or connect a HDMI Monitor+keyboard and login in the console
    • On RaspberryPi: edit the /mnt/boot/config.txt file and uncomment the following lines at the bottom:
    # Uncomment this to enable GPIO support for RPI-RF-MOD/HM-MOD-RPI-PCB
    enable_uart=1
    dtparam=i2c_arm=on
    dtoverlay=miniuart-bt
    dtoverlay=rpi-rf-mod
    • On Tinkerboard or ORDOID: edit the /mnt/boot/haos-config.txt file and uncomment the following lines at the bottom:
    # Uncomment this to enable GPIO support for RPI-RF-MOD/HM-MOD-RPI-PCB
    overlays=rpi-rf-mod
  4. Boot-up HAos and wait until basic installation is finished and the system is accessible via http://homeassistant.local:8123/
  5. Switch to Supervisor -> Add-on store and select Repositories by clicking on the three vertical dots on the top right corner.
  6. Add the URL https://github.com/jens-maus/ha-addon-raspmatic as a new experimental add-on store
  7. Scroll down and make sure to install the normal (non-strict) version of RaspberryMatic HA add-on
  8. Enable the sidebar
  9. Make sure you disable protection mode to allow the add-on to access all necessary hardware resources
  10. If you want to use a HB-RF-USB or HB-RF-USB-2 to connect your HomeMatic RF module via USB connect it now.
  11. Start the add-on and monitor the bootup messages where during the Identifying Homematic RF-Hardware... step it should identify the RPI-RF-MOD/HM-MOD-RPI-PCB rf module accordingly.
  12. If you want to use a HB-RF-ETH to connect your Homematic RF-Hardware via Ethernet make sure to follow the documentation here: https://github.com/jens-maus/RaspberryMatic/wiki/Experten-Features#hb-rf-eth-anbindung
  13. Enjoy full HomeMatic/homematicIP dualstack support.
  14. Give some feedback!

Tasks

Latest Screenshot

109651634-12a75d80-7b5f-11eb-9711-cbf448ae7ef7

@jens-maus jens-maus added 💡 enhancement-ideas New feature or change request 🙏 help wanted Extra attention is needed labels Jan 22, 2021
@jens-maus jens-maus added this to the future release milestone Jan 22, 2021
@jens-maus jens-maus pinned this issue Jan 22, 2021
@jens-maus
Copy link
Owner

Thank you @angelnu for getting this started! The WIP repository already looks quite promising. One question regarding the future location of that addon comes up immediatly, thought:

Do you think it might be possible to move all this into the main RaspberryMatic repository? If possible, I would like to have all this in the main RaspberryMatic GitHub repository so that it can directly act as a home assistant addon repository. AFAIK all you need is a repository.json file in the top-level directory and then we put, e.g. a "home-assisant-addon" directory where we put all the addon configuration/setup. In my understand this should then be enough to be able to use the RaspberryMatic respository as a home assistant addon repository, right?

And now that you have started to work on this and seem to have got the RaspberryMatic docker booted : What do you mean by "does not work with HA nginx!"?

BTW: I will try to work on the home assistant OS kernel driver integration ASAP and keep you updated in here.

@jens-maus jens-maus changed the title Home Assitant Add-on Home Assistant Addon Implementation Jan 22, 2021
@angelnu
Copy link
Contributor Author

angelnu commented Jan 22, 2021

Do you think it might be possible to move all this into the main RaspberryMatic repository?

@jens-maus - yes, I am intending to do so - the thing is that we need to have this already there during the WIP since I need to put the URLs in different config files and what to test that the remote access works (and not just when you manually check out the add-on to local). Would you consider giving me write access while this is WIP?

In my understand this should then be enough to be able to use the RaspberryMatic respository as a home assistant addon repository, right?

I need to check if HA would get confused when other folders that are not addons are in the github repository. If it works then yes, it would be good to keep it in a single place.

What do you mean by "does not work with HA nginx!"?

The Rega UI does not feel to play well with reverse proxy. Home Assistant integration in the bar required being able to rewrite so the Rega / becomes /raspberrymatic/ . Another area that breaks even without rewrite (tested in my K8S where I have virtual hosts) is when you try to upload a backup file - you do not get back the pop-up to confirm it is about to reset that comes up when I access Rega without reverse proxy.

@jens-maus
Copy link
Owner

Do you think it might be possible to move all this into the main RaspberryMatic repository?

@jens-maus - yes, I am intending to do so - the thing is that we need to have this already there during the WIP since I need to put the URLs in different config files and what to test that the remote access works (and not just when you manually check out the add-on to local). Would you consider giving me write access while this is WIP?

While I fully trust you (I do!) I really want to keep direct write access to this repository limited as much as possible - especially I am already in the phase of preparing the next release. So can't you simply prepare the necessary major changes (repository.json, etc.) via PRs or maintain these changes in a fork for the time being? Or do you think this would introduce too much hassle or burden on your work? If so, I could indeed reconsider giving you direct write access until the basic addon layout is done.

In my understand this should then be enough to be able to use the RaspberryMatic respository as a home assistant addon repository, right?

I need to check if HA would get confused when other folders that are not addons are in the github repository. If it works then yes, it would be good to keep it in a single place.

Then this should be the first thing todo IMHO. Because if there are really some things that hinder the use of this repository, I could then generate a new "RaspberryMatic-HA-Addon" repository to which I could of course then also grant you direct write access.

What do you mean by "does not work with HA nginx!"?

The Rega UI does not feel to play well with reverse proxy. Home Assistant integration in the bar required being able to rewrite so the Rega / becomes /raspberrymatic/ . Another area that breaks even without rewrite (tested in my K8S where I have virtual hosts) is when you try to upload a backup file - you do not get back the pop-up to confirm it is about to reset that comes up when I access Rega without reverse proxy.

This sounds like some additional lighttpd config tuning within RaspberryMatic could help to actually solve these reverse proxy problems. In fact, I know of many people perfectly using a nginx based reverse proxy to access their CCU/RaspberryMatic from outside. So it should work in principle IMHO.

@angelnu
Copy link
Contributor Author

angelnu commented Jan 22, 2021

While I fully trust you (I do!) I really want to keep direct write access to this repository limited as much as possible - especially I am already in the phase of preparing the next release. So can't you simply prepare the necessary major changes (repository.json, etc.) via PRs or maintain these changes in a fork for the time being? Or do you think this would introduce too much hassle or burden on your work? If so, I could indeed reconsider giving you direct write access until the basic addon layout is done.

I understand it (I leader lager teams in my day job so know how important the maintainer accountability is). Let me find if it gets a blocker - since you are very responsible incorporating PRs it might work out without me having write access to the main repo. Just be prepared for multiple PRs ;-)

Then this should be the first thing todo IMHO. Because if there are really some things that hinder the use of this repository, I could then generate a new "RaspberryMatic-HA-Addon" repository to which I could of course then also grant you direct write access.

Yes, I will try it out first - the only think is that I need to figure out if the 2 docker dev environments (one for the exportroot and another for the HA add-on). Most likely not an issue but it is a first time for me trying.

This sounds like some additional lighttpd config tuning within RaspberryMatic could help to actually solve these reverse proxy problems. In fact, I know of many people perfectly using a nginx based reverse proxy to access their CCU/RaspberryMatic from outside. So it should work in principle IMHO.

Any examples to compare?

I got it to mostly work by:

  • using virtual host instead of URL paths
  • increasing max allowed POST size
  • increasing timeouts (some REGA requests take multiple seconds to respond)

but as I said the restore CCU backup does not work: you click on the restore (step 3 in the UI) and it does nothing - I debugged in browser and I see the push completing with 200 BUT I do not see anything in the response. When I do it directly I see the response having some data (I do not remember out of my memory cache...).

If you try the HA add-on (it works without HW) then you can see you do not even come to the REGA login page. When you click on the Raspberrymatic add-on in the side bar it sends to http://localhost:7123/local_raspberrymatic (which should be mapped to the REGA /) and then it goes to http://localhost:7123/pages/index.htm?sid=@fGM3q1NqQt@ instead of http://localhost:7123/local_raspberrymatic/pages/index.htm?sid=@fGM3q1NqQt@

@jens-maus
Copy link
Owner

jens-maus commented Jan 22, 2021

I understand it (I leader lager teams in my day job so know how important the maintainer accountability is). Let me find if it gets a blocker - since you are very responsible incorporating PRs it might work out without me having write access to the main repo. Just be prepared for multiple PRs ;-)

No problem. I am prepared to receive your PRs and acknowledge them ASAP.

Then this should be the first thing todo IMHO. Because if there are really some things that hinder the use of this repository, I could then generate a new "RaspberryMatic-HA-Addon" repository to which I could of course then also grant you direct write access.

Yes, I will try it out first - the only think is that I need to figure out if the 2 docker dev environments (one for the exportroot and another for the HA add-on). Most likely not an issue but it is a first time for me trying.

For me as well. I do have, thought, less experience with HA and HAos, so we both have to learn a few things here. But I am sure we will manage together to get this going. Perhaps you can write some basic documentation on the docker dev environments and how to build this as I have never uses VSCode here.

This sounds like some additional lighttpd config tuning within RaspberryMatic could help to actually solve these reverse proxy problems. In fact, I know of many people perfectly using a nginx based reverse proxy to access their CCU/RaspberryMatic from outside. So it should work in principle IMHO.

Any examples to compare?

Not really, I am afraid. All I know is, that users are using reverse proxies themselves to access their CCU/RaspberryMatic from the outside and the CloudMatic service is providing the very same to their users. So there must be a way to get this going.

If you try the HA add-on (it works without HW) then you can see you do not even come to the REGA login page. When you click on the Raspberrymatic add-on in the side bar it sends to http://localhost:7123/local_raspberrymatic (which should be mapped to the REGA /) and then it goes to http://localhost:7123/pages/index.htm?sid=@fGM3q1NqQt@ instead of http://localhost:7123/local_raspberrymatic/pages/index.htm?sid=@fGM3q1NqQt@

Can you perhaps provide me a quick howto to get your current state of affairs regarding the HA RaspberryMatic Addon running here on my environment? As said, I do have very less experience with HA and especially regarding development for HA. So I would have to learn first a good bunch of things, I guess. And if you could point me at resources and provide a quick howto and show how I can get your current Addon going, that would be highly appreciated!

EDIT: Ok, I managed to get the Add-on installed at least and the RapberryMatic docker seems to start correctly. Still some things to do, but this is a good starter 👍

@angelnu
Copy link
Contributor Author

angelnu commented Jan 22, 2021

I am glad you got it working - did you see the link to the dev instructions in the Add-on repo? It used Visual Code and a container. I will move this into the dev readme as we merge the repros.

Are you able to repro the problem? You need to enable the nginx access in the add-on settings once you install it -> you then see the icon on the left to access the REGA UI where you will see the problem.

@jens-maus
Copy link
Owner

Are you able to repro the problem? You need to enable the nginx access in the add-on settings once you install it -> you then see the icon on the left to access the REGA UI where you will see the problem.

Yes, I can see the problem and I partly debugged it already. There is no "nginx", at leaset I can't find any nginx running on the HAos machine. The process listening on 8123 is a python process. Then I tried the "HomeMatic CCU" Addon the HA developers provide themselves and there the OCCU WebUI is perfectly shown. So this does not seem to be a general issue. Perhaps this is a lighttpd conf issue within the RaspberryMatic docker.

@angelnu angelnu mentioned this issue Jan 22, 2021
7 tasks
@angelnu
Copy link
Contributor Author

angelnu commented Jan 22, 2021

I checked that it is possible to combine the Add-On repo with the Raspberrymatic main repo -> submitted PR.

I also added the dev documentation for building both the Add On and RaspberryMatic inside a container.

Now, for persistence, I did not find a way to map /data which is the folder passed by HA for add on persistency to /usr/local so I will have to add an env variable to tell Raspberrymatic that is running in HA and use that info to bind or symlink /data to /usr/local

EDIT:

  • I added a fix in RaspberryMatic to bind /data to /usr/local
  • I added SYS_ADMIN to be able to mount within containers
  • since we are not able to mount the /dev_orig we might get problems later when we need to dynamicall create devices.

@jens-maus
Copy link
Owner

Hi @angelnu. I am still fighting with the Ingress setup of the home-assistant addon. On all the other HA Add-ons I have found the HA devs use a nginx configuration for creating a reverse proxy to get the ingress support going.

However, as we don't have nginx within the RaspberryMatic docker (and I don't have plans to add it!), I first tried to setup a similar reverse proxy setup with the already existing lighttpd server RaspberryMatic comes with. As I had to learn, the lighttpd server does not allow to modify http responses like nginx does using the sub_filter statements in the nginx config of the homematic occu add-on (see here: https://github.com/home-assistant/addons/blob/master/homematic/rootfs/etc/nginx/nginx.conf). So after have learned that lession, I am currently working on getting a similar reverse proxy implemented using the http-proxy-middleware nodejs class since nodejs v12 already exists in RaspberryMatic.

Here is the current state of the reverse proxy server setup for the ingress proxying:

const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');

const apiProxy = createProxyMiddleware('/', {
  target: 'http://127.0.0.1:80',
  changeOrigin: true, // for vhosted sites,
  logLevel: 'debug',
  selfHandleResponse: true,
  onProxyRes (proxyRes, req, res) {
    console.log(req.headers['x-ingress-path']);
    console.log(proxyRes.statusCode);
    console.log(proxyRes.headers);
    console.log(req.headers);

    if(typeof(proxyRes.headers.location) !== 'undefined') {
      var redirect = proxyRes.headers.location;
      console.log('Received code ' + proxyRes.statusCode + ' from API Server for URL - ' + redirect);
      redirect = req.headers['x-ingress-path'] + redirect;
      console.log('Manipulating header location and redirecting to - ' + redirect);
      proxyRes.headers.location = redirect;
    }

    const bodyChunks = [];
    proxyRes.on('data', (chunk) => {
        bodyChunks.push(chunk);
    });
    proxyRes.on('end', () => {
        const body = Buffer.concat(bodyChunks);

        // forwarding source status
        res.status(proxyRes.statusCode);

        // forwarding source headers
        Object.keys(proxyRes.headers).forEach((key) => {
            res.append(key, proxyRes.headers[key]);
        });

        // modifying html content
        //if (proxyRes.headers['content-type'] && proxyRes.headers['content-type'].includes('text/html'
            let html = body.toString();

            // do whatever you want
            html = html.replace(/\/api\//g, req.headers['x-ingress-path']+'/api/');
            html = html.replace(/\/webui\//g, req.headers['x-ingress-path']+'/webui/');
            html = html.replace(/\/ise\//g, req.headers['x-ingress-path']+'/ise/');
            html = html.replace(/\/pda\//g, req.headers['x-ingress-path']+'/pda/');
            html = html.replace(/\/config\//g, req.headers['x-ingress-path']+'/config/');
            html = html.replace(/\/pages\//g, req.headers['x-ingress-path']+'/pages/');
            html = html.replace(/\/jpages\//g, req.headers['x-ingress-path']+'/jpages/');
            html = html.replace(/\/esp\//g, req.headers['x-ingress-path']+'/esp/');

            res.send(new Buffer.from(html));
        //} else {
        //    res.send(body);
        //}

        res.end();
    });
  },
});

const app = express();
app.use(apiProxy);
app.listen(8099);

While this nodejs-based proxy seem to start well and also seem to serve certain static files (*.png) perfectly fine, I am still getting some 502 errors sporadically here. So can you give this nodejs-based proxy a test and see if you can spot some obvious problem compared to the nginx proxying the homematic occu add-on authors are using? I am probably missing something here. And help would be highly appreciated because I think, if we can get this ingress integration running it would be great for the home-assistant-addon. And starting this nodejs-based reverse proxy would be of course quite easy within RaspberryMatic...

@angelnu
Copy link
Contributor Author

angelnu commented Jan 27, 2021

I can repro the problem and I think I know where it comes:

http://localhost:7123/api/hassio_ingress/tNpfBcSADiKR0wRpRDdtfPT07h5ljGGFb2DVEK9C0ss/api/homematic.cgi

fails. This is because the /api part comes twice in the url. So I think the regular exp match is to greedy. I cannot confirm since it is late - can check tomorrow again.

I am trying to find a way to tag containers without rebuilding... can you ckeck the k8s issue? I have some updates/questions

@jens-maus
Copy link
Owner

I can repro the problem and I think I know where it comes:

http://localhost:7123/api/hassio_ingress/tNpfBcSADiKR0wRpRDdtfPT07h5ljGGFb2DVEK9C0ss/api/homematic.cgi

fails. This is because the /api part comes twice in the url. So I think the regular exp match is to greedy. I cannot confirm since it is late - can check tomorrow again.

I don't think it is just related to the double /api/ part in the URL. Also this URL fails:

http:/xxxxx:8123/api/hassio_ingress/Y1kh_Az9FKqWQqkvmk14b_CHuapceDYgnTxTyTucKWk/webui/style.cgi

To me, this looks like all *.cgi scripts are causing this exception. Really strange.

jens-maus added a commit that referenced this issue Jan 28, 2021
coming from the home assistant webui via its ingress inteerface. This
should finally enable a working RaspberryMatic WebUI to be embedded in
the HA WebUI itself. This refs #1087.
@jens-maus
Copy link
Owner

Ok, I think I got the nodejs-based proxy working now. So the HA ingress is now able to access the RaspberryMatic WebUI here. So I think it is time to test this mit actual rf hardware.

@angelnu
Copy link
Contributor Author

angelnu commented Jan 28, 2021

Cool you got it working! I will give it a try on my side tomorrow.

I am curious how it goes when you propose to PR to the HA code - they are very careful on what code they add there...

@jens-maus
Copy link
Owner

I am curious how it goes when you propose to PR to the HA code - they are very careful on what code they add there...

You mean for the required kernel modules changes in the HAos to support this RaspberryMatic Add-on? I still hope they will accept it because for them it could be an interesting development/enhancement as well.

But if not (or as an alternative strategy?!?) I already thought about permanently forking the HAos project just for HomeMatic purposes. That would, in principle, (and I am open for that idea!) allow to think about moving towards using HAos as a complete new base system for RaspberryMatic (while calling it "OpenMatic") since it has a better UI, integration, etc. etc. Then we could distribute this HAos-based "OpenMatic" generation with the directly integrated and enabled Add-On so that the CCU WebUI is directly integrated and accessible. But this is just some loose idea currently with no ETA in mind, whatsoever...

@angelnu
Copy link
Contributor Author

angelnu commented Jan 29, 2021

I indeed was thinking in a "plan B" -> they support passing the kernel modules (and I think headers) to the add-on. We could use this to include the modules in the add-on.

I was also thinking on having a common container to load the kernel modules in any host - we would use for HA, K8s, etc. Something like https://github.com/multiarch/qemu-user-static

@angelnu
Copy link
Contributor Author

angelnu commented Jan 30, 2021

@jens-maus - this is the PoC for building and loading the kernel modules via container https://github.com/angelnu/pivccu-modules-container

I plan to use it for my Kubernetes system but it might also come handy for the Home Assistant if we need to keep the sources out of the main project.

We could also use it for the deployer.sh so it avoids downloading each time from apt.

@jens-maus
Copy link
Owner

I am not quite sure if I understand that correctly yet? What would be the exact process of that additional container? And how could that be actually integrated into the HA add-on? So please elaborate a bit more on the procedure you are suggesting so that I understand all that a bit better.

@angelnu
Copy link
Contributor Author

angelnu commented Jan 31, 2021

The process would be to start the new container before RaspberryMatic using the add-on option kernel_modules: true. This way we would get the kernel modules available into the new container. I have to see if there is an option to also make the kernel sources available to the add-on since it is so limited what folders can be provided to the add-on. Worst case, since this container is privileged, it could just mount the host root disk with the kernel sources itself.

But in general my intention with this extra container is decoupling the task of building and adding the modules to the host. This way instead of depending on the Host being a debian distro the dependency is only to have the kernel sources and docker in the host. This would, for example, enable users of non-debian OSes (NAS, fedora, etc) to load the modules.

@jens-maus
Copy link
Owner

What does this kernel_modules: true option do in HA? Didn't know it exists. So that would mean that before starting the RaspberryMatic Add-on a user would have to manually start that extra kernel module add-on? Did I get this right? And for the "normal" docker container implementation it would be then the same? A user first would have to manually start this docker container for getting the kernel modules build and installed? And then we expose /lib/modules to the RaspberryMatic docker container so that the container could modprobe the kernel modules itself?

@angelnu
Copy link
Contributor Author

angelnu commented Jan 31, 2021

What does this kernel_modules: true option do in HA?

It is document at https://developers.home-assistant.io/docs/add-ons/configuration

So that would mean that before starting the RaspberryMatic Add-on a user would have to manually start that extra kernel module add-on?

exactly

And for the "normal" docker container implementation it would be then the same?

if with "normal" you mean the "deployer.sh" or other non-HA then yes.

And then we expose /lib/modules to the RaspberryMatic docker container so that the container could modprobe the kernel modules itself?

We would not need to expose the modules to the RaspberryMatic container -> once they are added to the host by running the new "install-modules" container then they are automatically loaded once of the devices is detected.

Please notice that the "install-modules" container needs to be exec at least once when the host kernel is updated to build the modules for the new kernel. I configured it that if the kernel modueles are already installed it does nothing.

UPDATE
@jens-maus - have you installed the home assistant on real HW or virtual machine (not as container) - if so could you plese check if you have the kernel sources there in /usr/src or at least the includes to build kernel modules under /lib/modules/*/build ?

If they are there I would continue trying to add the modules via container. If they are not then there is no "plan B" and the only way to add the modules would be at build time of the home assistant.

@jens-maus
Copy link
Owner

jens-maus commented May 12, 2021

It's because the supervisor missing an option that only gets set on the next container recreating.

Thanks for clearing that up @pvizeli . So what is then the suggested upgrade path for existing users coming with old HAos/HA installations and wanting to use HAos 6.0+ with the new supervisor CPU runtime options? Or is a complete fresh installation the only path (can't be?!?)?

@agners
Copy link

agners commented May 12, 2021

Hm I see. Ideally we should force recreate the container on OS upgrade (or downgrade). Not sure if we know on OS level if its the first run after an upgrade. I'll have a look at that.

@stefangries
Copy link

@noxhirsch As workaround: temporarily switch supervisor to dev channel via ssh and update. This triggers a recreation.

@noxhirsch
Copy link

@stefangries Thanks for the tip! That worked wonderfully 👍

@stefangries
Copy link

After experimenting a bit, I found a few bugs. As I use a restored config from my previous charly, it should be validated if those problems also exist on an fresh install. First bug is encoding errors with umlauts and degree values (red). Second bug is, that the Hinzufügen-button is not working (green). On the browser-console you can see an error for each click on the button. For me, it looks like the "api/hassio_ingress"-part of the request URL is missing.

rspmatic_ha_1
rspmatic_ha_2
rspmatic_ha_3

@jens-maus
Copy link
Owner

After experimenting a bit, I found a few bugs.

Then please open separate issues for these bugs and don't stuff this into the current issue. I am about to close this issue here as soon as HAos 6.0 is released!

@noxhirsch
Copy link

Yesterday I noticed that when the RaspberryMatic addon is running HA can't access my Deconz stick over ZHA anymore. Today I reinstalled the NUC to rule out that it has something to do with the dev version of the supervisor, but the problem still remains (OS 6.0.RC1 / supervisor-2021.04.3 / core-2021.5.3).
Could this rather be a problem of this addon, the supervisor or the OS? (so where should I open the issue?)
Or is this a known limitation, that I somehow missed?

ZHA error in the log
2021-05-13 13:25:18 ERROR (MainThread) [homeassistant.components.zha.core.gateway] Couldn't start deCONZ = dresden elektronik deCONZ protocol: ConBee I/II, RaspBee I/II coordinator
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/zha/core/gateway.py", line 157, in async_initialize
    self.application_controller = await app_controller_cls.new(
  File "/usr/local/lib/python3.8/site-packages/zigpy/application.py", line 69, in new
    await app.startup(auto_form)
  File "/usr/local/lib/python3.8/site-packages/zigpy_deconz/zigbee/application.py", line 66, in startup
    self.version = await self._api.version()
  File "/usr/local/lib/python3.8/site-packages/zigpy_deconz/api.py", line 455, in version
    (self._proto_ver,) = await self[NetworkParameter.protocol_version]
  File "/usr/local/lib/python3.8/site-packages/zigpy_deconz/api.py", line 420, in read_parameter
    r = await self._command(Command.read_parameter, 1 + len(data), param, data)
  File "/usr/local/lib/python3.8/site-packages/zigpy_deconz/api.py", line 305, in _command
    return await asyncio.wait_for(fut, timeout=COMMAND_TIMEOUT)
  File "/usr/local/lib/python3.8/asyncio/tasks.py", line 501, in wait_for
    raise exceptions.TimeoutError()
asyncio.exceptions.TimeoutError

@stefangries
Copy link

stefangries commented May 13, 2021

Yesterday I noticed that when the RaspberryMatic addon is running HA can't access my Deconz stick over ZHA anymore. Today I reinstalled the NUC to rule out that it has something to do with the dev version of the supervisor, but the problem still remains (OS 6.0.RC1 / supervisor-2021.04.3 / core-2021.5.3).
Could this rather be a problem of this addon, the supervisor or the OS? (so where should I open the issue?)

I'm running the Conbee II with deCONZ addon instead of ZHA without any problems next to the RaspberryMatic Addon (HassOS 6.0.RC1 / supervisor-2021.05.dev1204 / core-2021.5.3). Therefore I think it's not an OS issue.

Does your problem only happen when RaspberryMatic is running, or also when the addon is installed but stopped?

@noxhirsch
Copy link

noxhirsch commented May 13, 2021

@stefangries It only happens when RaspberryMatic is running.
I also tried removing and adding back the ZHA integration (while RaspberryMatic is running), but that also doesn't work. It lists the ConBee 2 stick, but can't connect.

EDIT: When I disable "Start on boot" for RaspberryMatic and start it later, I can still for example switch on my Zigbee lights but get an error "Failed to call light/turn_on" (but it turns on the light)

@stefangries
Copy link

I would report it to the core team, as running addons should never impact core functionality.

@hpsteff
Copy link

hpsteff commented May 13, 2021

I have updated HAOS 6.0.RC1 today and have also raspberrymatic add on running. I also use the Conbee II stick with ZHA Integration with no problem. This is on raspi4 64bit.

Check if you may have running cuxd on raspberrymatic as well. I would remove it to avoid any interference from there. There is anyway IMHO no benefit of running CUXD in raspberrymatic when using home assistant.

@jens-maus
Copy link
Owner

Check if you may have running cuxd on raspberrymatic as well. I would remove it to avoid any interference from there. There is anyway IMHO no benefit of running CUXD in raspberrymatic when using home assistant.

This is indeed a good hint. So please check if you guys have the CUxD CCU add-on installed within RaspberryMatic. However, there is no reason to completely uninstall it because you can add USB/tty device exceptions to the cuxd configuration so that it ignores devices which might be necessary for other purposes.

@noxhirsch
Copy link

Check if you may have running cuxd on raspberrymatic as well. I would remove it to avoid any interference from there. There is anyway IMHO no benefit of running CUXD in raspberrymatic when using home assistant.

Thank you very much @hpsteff - that is the solution to my problem 👍

@stefangries
Copy link

Check if you may have running cuxd on raspberrymatic as well. I would remove it to avoid any interference from there. There is anyway IMHO no benefit of running CUXD in raspberrymatic when using home assistant.

Thank you very much @hpsteff - that is the solution to my problem 👍

As I figured out, CUxD is trying to connect to the conbee. Maybe there is a way to prevent this.
image

@noxhirsch
Copy link

noxhirsch commented May 16, 2021

@stefangries As I have read, it switches from "device auto detection" to "whitelist ony" as soon as one device is configured. So I added a non existing device under setup:
TTYPARAM=ttyACM10
Maybe there's also an option to disable the auto detection completely, but I didn't find this option. My "hack" seems to work and I can't see any drawbacks so far.

@jens-maus
Copy link
Owner

jens-maus commented May 16, 2021

@noxhirsch According to the CUxD documentation (https://homematic-forum.de/forum/download/file.php?id=87959) you should be able to disable the tty grabbing in CUxD via the following config option in cuxd.ini: TTYPARAM=NONE

@chillje
Copy link

chillje commented May 19, 2021

I have some problems to discover my devices in HA directly. I followed all the steps including the configuration in ha (configuration.yml) and changed the hostname and password in the config snippet (and tried also the IP instead of the hostname).

My device is a rpi4 with a HM-MOD-RPI-PCB. I installed the HA 6 RC1 64Bit on my new memory-card.
The raspberrymatic on HA is fresh configured and I added two new devices to it. After this I changed the security settings to "widely open" for testing purposes (ports open, all accessible, IP range access for the hole priv-network and for docker aka "172.17.0.0/8"). My fresh installed Node Red system on this HA host can connect the raspberrymatic and control the two new devices.
But the new HA 6 RC1 64Bit itself cant find the devices and cant connect the raspberrymatic proxy.
In the HA logs i can see some warnings about that but I have no idea what I can do here..

ServerThread.jsonRpcLogin: Unable to open session.
18:15:03 – (WARNUNG) /usr/local/lib/python3.8/site-packages/pyhomematic/_hm.py
Error handling request
18:15:02 – (FEHLER) /usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py - Die Nachricht ist zum ersten Mal um 18:15:02 aufgetreten und erscheint 2 mal
Skipping init for homeassistant-raspberrymatic
18:15:00 – (WARNUNG) /usr/local/lib/python3.8/site-packages/pyhomematic/_hm.py
Failed to initialize proxy for homeassistant-rf
18:15:00 – (WARNUNG) /usr/local/lib/python3.8/site-packages/pyhomematic/_hm.py - Die Nachricht ist zum ersten Mal um 18:14:58 aufgetreten und erscheint 3 mal
2021-05-19 18:14:58 WARNING (SyncWorker_2) [pyhomematic._hm] Failed to initialize proxy for homeassistant-rf
2021-05-19 18:14:59 WARNING (SyncWorker_2) [pyhomematic._hm] Failed to initialize proxy for homeassistant-hmip
2021-05-19 18:15:00 WARNING (SyncWorker_2) [pyhomematic._hm] Failed to initialize proxy for homeassistant-groups
2021-05-19 18:15:00 WARNING (SyncWorker_2) [pyhomematic._hm] Skipping init for homeassistant-raspberrymatic
2021-05-19 18:15:02 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 314, in data_received
messages, upgraded, tail = self._request_parser.feed_data(data)
File "aiohttp/_http_parser.pyx", line 546, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'invalid HTTP method'"
2021-05-19 18:15:02 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 314, in data_received
messages, upgraded, tail = self._request_parser.feed_data(data)
File "aiohttp/_http_parser.pyx", line 546, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'invalid HTTP method'"
2021-05-19 18:15:03 WARNING (SyncWorker_0) [pyhomematic._hm] ServerThread.jsonRpcLogin: Unable to open session.

Any suggestions for that?

@hpsteff
Copy link

hpsteff commented May 20, 2021

what is the log in the raspberrymatic add-on? if the add on starts and the logs are ok then also you need to make sure that HA connects to the add on. after a server reboot, the raspberrymatic add-on is not ready when the homematic integration tries to load. this has been mentioned earlier:

#1087 (comment)

when the log in the add-on itself is ok, additional configuration steps are required to ensure the proper connection to HA.

Maybe this is the issue.

@chillje
Copy link

chillje commented May 20, 2021

what is the log in the raspberrymatic add-on? if the add on starts and the logs are ok then also you need to make sure that HA connects to the add on. after a server reboot, the raspberrymatic add-on is not ready when the homematic integration tries to load. this has been mentioned earlier:

#1087 (comment)

when the log in the add-on itself is ok, additional configuration steps are required to ensure the proper connection to HA.

Maybe this is the issue.

This sounds like a possible problem.

My raspberrymatic log looks good

Mounting /data as /usr/local (Home Assistant Add-On): OK
Starting watchdog...
Identifying onboard hardware: oci, OK
Initializing RTC Clock: no hardware found
Running sysctl: OK
Checking for Factory Reset: not required
Checking for Backup Restore: not required
Initializing System: OK
Starting logging: OK
Init onboard LEDs: init, OK
Starting irqbalance: OK
Starting network: eth0: link up, fixed, firewall, inet up, 172.30.33.2, OK
Identifying Homematic RF-Hardware: ....HmRF: HM-MOD-RPI-PCB/GPIO, HmIP: HM-MOD-RPI-PCB/GPIO, OK
Updating Homematic RF-Hardware: HM-MOD-RPI-PCB: 2.8.6, OK
Starting hs485dLoader: disabled
Starting xinetd: OK
Starting eq3configd: OK
Starting lighttpd: OK
Starting ser2net: disabled
Starting ssdpd: OK
Starting sshd: OK
Starting ha-proxy: OK
Starting NUT services: disabled
Initializing Third-Party Addons: OK
Starting LGWFirmwareUpdate: ...OK
Setting LAN Gateway keys: OK
Starting hs485d: disabled
Starting multimacd: .OK
Starting rfd: .OK
Starting HMIPServer: .............OK
Starting ReGaHss: .OK
Starting CloudMatic: OK
Starting NeoServer: disabled
Starting Third-Party Addons: OK
Starting crond: OK
Setup onboard LEDs: booted, OK

Can be a race condition.

Could someone else get the ha recognition to work?

@chillje
Copy link

chillje commented May 20, 2021

what is the log in the raspberrymatic add-on? if the add on starts and the logs are ok then also you need to make sure that HA connects to the add on. after a server reboot, the raspberrymatic add-on is not ready when the homematic integration tries to load. this has been mentioned earlier:

#1087 (comment)

when the log in the add-on itself is ok, additional configuration steps are required to ensure the proper connection to HA.

Maybe this is the issue.

Perfect.
I have implemented this: https://www.home-assistant.io/integrations/homematic/#detecting-lost-connections
Starting with "Create a string variable V_Last_Reboot on the CCU"
This realized the working ccu after it is fully started and then my HA setup detects all devices on it.
Thank you for the hint :)
PS: In step 3 you have to change the entity_id with yours (like homematic.raspberrymatic) two times ;)

@jens-maus
Copy link
Owner

@chillje As we lack some own detailed documentation on the homematic integration part here, would you please be so kind in addition the necessary documentation steps to https://github.com/jens-maus/RaspberryMatic/wiki/Installation-HomeAssistant#home-assistant-integration-setup so that users can follow your steps in getting the homematic integration going without having to wade through this issue ticket? thanks!

@jens-maus
Copy link
Owner

Now that 3.57.5.20210525 has been released and seems to run significantly stable enough with recent HAos 6.0rc versions I am going to close this issue and would like to ask anyone to open up new dedicated issues in case problems / enhancement ideas might arise for the ha-addon platform.

And of course thanks to anyone having contributed to the overall success of the ha-addon integration of RaspberryMatic. Special thanks have to go to @angelnu for the initial work on converting RaspberryMatic into a docker container which paved the way to get the ha-addon story going. But of course also thanks to all testers in here! Hope you all have a great HomeAssistant experience with RaspberryMatic as an add-on!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💡 enhancement-ideas New feature or change request 🙏 help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests