anotherjulien / MyHOME

MyHOME integration for Home-Assistant
GNU Affero General Public License v3.0
137 stars 54 forks source link

How to manually configure a gateway #13

Closed fcrisciani closed 3 years ago

fcrisciani commented 3 years ago

Hi, In the doc is mentioned:

Some common gateways should be auto-discovered, but it is still possible to force the inclusion of a gateway not discovered. One limitation however is that the gateway needs to be in the same network as your Home-Assistant instance.

Can you provide an example of the field to put in the configuration.yaml?

anotherjulien commented 3 years ago

Hi! I'll admit the doc is not very clear on that point... Manually adding a gateway is not possible in the configuration.yaml file.

What can be done if the off-chance case where Home Assistant does not auto-discover the gateway is to go in the "Integrations" page and click "Add Integration", then select MyHome from there. This will use the integration's own discovery mechanism that is very similar to the one used by Home Assistant, so it has the same limitations with regards to networking.

The reason for this is that going through this config flow is necessary for Home Assistant in order to create "Devices" and not just "Entities".

fcrisciani commented 3 years ago

So unfortunately the extensions finds a gateway but it's not the one that I want to use and there seems to be no way to change the ip adress from the UI itself. Right now my current workaround is to change the config_flow.py and add the gateway manually in code. I was wondering if you can think to any better way to specify a gateway manually even if there is some auto discovered.

anotherjulien commented 3 years ago

What's your gateway that is not discovered and what is the one that is?

fcrisciani commented 3 years ago

So I have 2 myhome systems that are separate from the myhome bus point of view but they share the same network with the home assistant. The gateway that is not discovered is an hold mh200 that is in the older system apartment.

<!-- G E N E R A L I N F O --> 
<date>30/07/2008</date> 
<webserver_type>MH200</webserver_type> 
<!--VERSIONE_FIRMWARE--> <ver_webserver>2.1.2</ver_webserver> <ver_webserver_hw>0</ver_webserver_hw> <!--ultima service pack installata--> <latest_sp>MH200_2_1_2.fwz</latest_sp>
<!-- G E N E R A L I N F O --> 

The other one is a new gateway f452 if I recall correctly the name

anotherjulien commented 3 years ago

Can you show me what the discovery mechanism sees? You need to run python3.8 /usr/local/lib/python3.8/site-packages/OWNd/discovery.py in the Home Assistant instance

fcrisciani commented 3 years ago

This is the only things that finds:

bash-5.0# python3 /usr/local/lib/python3.8/site-packages/OWNd/discovery.py
Address: X.X.X.139
Port: 20000
Manufacturer: BTicino S.p.A.
Model: MyHomeServer1
Firmware: 2.32
Serial: <serial>

And this is my current workaround in config_flow.py

mh200 = await OWNGateway.build_from_discovery_info({"address": "X.X.X.254",
"port": 20000, "password": <pass>, "serialNumber": "00:00:11",
"deviceType": "mh200", "friendlyName": "mh200", "manufacturer":"bticino"})
self.gateway = mh200

On Thu, May 6, 2021 at 9:41 AM anotherjulien @.***> wrote:

Can you show me what the discovery mechanism sees? You need to run python3.8 /usr/local/lib/python3.8/site-packages/OWNd/discovery.py in the Home Assistant instance

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/anotherjulien/MyHOME/issues/13#issuecomment-833625204, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAN5HCIVBIIQYNYWZ4WAFMLTMK2BZANCNFSM44GGSNAQ .

anotherjulien commented 3 years ago

This seems to indicate your MH200 has multicast traffic issues. Would you be able to capture traffic with wireshark or tcpdump while performing the same test to see if the MH200 actually sends something or not?

fcrisciani commented 3 years ago

So I checked and I guess that device does not have any multicast support (was not there in the firmware). I can see some messages from the .139 but nothing from the .254

fcrisciani commented 3 years ago

Other option is it possible to add a config to disable/ignore discovery? That should allow me to just fill up the field manually right?

anotherjulien commented 3 years ago

If the device does not support SSDP, then for all intents and purposes, it's not supported by this integration. At the moment I'm not planning on adding a fully manual setup for the gateway. But in any case, your workaround allowed you to add it, didn't it? Once it's in the device registry, you don't need to worry about the setup method again.

fcrisciani commented 3 years ago

do you know how to see the device registry in home assistant? if not it's ok, feel free to close this

anotherjulien commented 3 years ago

There's no front-end for it as far as I know, but it's in the /config/.storage/core.device_registry file.

anotherjulien commented 3 years ago

FYI, fully manual/custom setup of a gateway has been added to version 0.7.7 if you wish to give it a go!

fcrisciani commented 3 years ago

oh nice thanks! Trying it right now

fcrisciani commented 3 years ago

worked like a charm! These are the steps that I took: 1) upgrade to the latest version from hacs 2) I deleted the old integration 3) created the new one, selecting custom 4) insert the new password 5) restart home assistant

Tested that was able to turn on/off a light previously configured.

Thanks again for this change, I totally know that I will probably be the only user of it, really appreciated!

anotherjulien commented 3 years ago

Thank you for testing :-) I'm glad it works well! You're not the only one, but not very far from it ;-)

Anyway, this has the likely benefit to also cover another fringe usecase where the gateway and HA are not in the same network!

Cadorago commented 2 years ago

I have trouble to manually configure the gateway I installed version 0.8.5 trought HACS (OWNd 0.7.39) and the tried to setup integration, but i received "All MyHome gateways are already configured". I can't find the way to manually set the gateway information

thanks

Cadorago commented 2 years ago

After i commented these lines in in config_flow.py

if not local_gateways:

  #    return self.async_abort(reason="all_configured")

i finally see the "custom" field, but when i save i get "Unknown error occurred" and in the log:

2021-11-09 13:11:42 ERROR (MainThread) [aiohttp.server] Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request resp = await self._request_handler(request) File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 499, in _handle resp = await handler(request) File "/usr/local/lib/python3.9/site-packages/aiohttp/web_middlewares.py", line 119, in impl return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 98, in forwarded_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 24, in request_context_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 78, in ban_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 138, in auth_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 135, in handle result = await result File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 157, in post return await super().post(request, flow_id) File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 62, in wrapper result = await method(view, request, *args, **kwargs) File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post result = await self._flow_mgr.async_configure(flow_id, data) File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 246, in async_configure result = await self._async_handle_step(flow, cur_step["step_id"], user_input) File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 320, in _async_handle_step result: FlowResult = await getattr(flow, method)(user_input) File "/config/custom_components/myhome/config_flow.py", line 157, in async_step_custom user_input["serialNumber"] = device_registry.format_mac( File "/usr/src/homeassistant/homeassistant/helpers/device_registry.py", line 121, in format_mac if len(to_test) == 17 and to_test.count(":") == 5: TypeError: object of type 'MACAddress' has no len()

If i comment there lines: try: user_input["serialNumber"] = device_registry.format_mac( MACAddress(user_input["serialNumber"]) ) except ValueError: errors["serialNumber"] = "invalid_mac"

and set : user_input["serialNumber"] = ("b8:27:eb:14:79:b9",)

the gateway is correctly registered and i can see :

2021-11-09 12:37:40 WARNING (MainThread) [custom_components.myhome] Unknown device: WHO=4 WHERE=3 2021-11-09 12:38:09 WARNING (MainThread) [custom_components.myhome] Unknown device: WHO=4 WHERE=1 2021-11-09 12:38:10 WARNING (MainThread) [custom_components.myhome] Unknown device: WHO=4 WHERE=2 2021-11-09 12:38:10 WARNING (MainThread) [custom_components.myhome] Unknown device: WHO=4 WHERE=3 2021-11-09 12:38:38 WARNING (MainThread) [custom_components.myhome] Unknown device: WHO=1 WHERE=37 2021-11-09 12:38:39 WARNING (MainThread) [custom_components.myhome] Unknown device: WHO=4 WHERE=1 2021-11-09 12:38:40 WARNING (MainThread) [custom_components.myhome] Unknown device: WHO=4 WHERE=2 2021-11-09 12:38:40 WARNING (MainThread) [custom_components.myhome] Unknown device: WHO=4 WHERE=3 2021-11-09 12:39:09 WARNING (MainThread) [custom_components.myhome] Unknown device: WHO=4 WHERE=1 2021-11-09 12:39:10 WARNING (MainThread) [custom_components.myhome] Unknown device: WHO=4 WHERE=2 2021-11-09 12:39:10 WARNING (MainThread) [custom_components.myhome] Unknown device: WHO=4 WHERE=3 2021-11-09 12:39:38 WARNING (MainThread) [custom_components.myhome] Unknown device: WHO=1 WHERE=37 2021-11-09 12:39:39 WARNING (MainThread) [custom_components.myhome] Unknown device: WHO=4 WHERE=1

but after restarting HA i got this error and it crash:

2021-11-09 13:00:21 ERROR (MainThread) [root] Uncaught exception Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/main.py", line 331, in sys.exit(main()) File "/usr/src/homeassistant/homeassistant/main.py", line 318, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 121, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete return future.result() File "/usr/src/homeassistant/homeassistant/runner.py", line 103, in setup_and_run_hass hass = await bootstrap.async_setup_hass(runtime_config) File "/usr/src/homeassistant/homeassistant/bootstrap.py", line 131, in async_setup_hass await async_from_config_dict(config_dict, hass) is not None File "/usr/src/homeassistant/homeassistant/bootstrap.py", line 241, in async_from_config_dict await _async_set_up_integrations(hass, config) File "/usr/src/homeassistant/homeassistant/bootstrap.py", line 535, in _async_set_up_integrations await asyncio.gather( File "/usr/src/homeassistant/homeassistant/helpers/device_registry.py", line 645, in async_load await hass.data[DATA_REGISTRY].async_load() File "/usr/src/homeassistant/homeassistant/helpers/device_registry.py", line 505, in async_load connections={tuple(conn) for conn in device["connections"]}, # type: ignore[misc] File "/usr/src/homeassistant/homeassistant/helpers/device_registry.py", line 505, in connections={tuple(conn) for conn in device["connections"]}, # type: ignore[misc] TypeError: unhashable type: 'list'

Any idea? Thanks!!

robgiom commented 2 years ago

Hi @Cadorago I've the same issue. "All MyHome gateways are already configured" Did you find a way to solve it? Many thanks