chrisrosset / mamaroo-mqtt

MQTT-based mamaRoo4 adapter for Home Assistant
GNU General Public License v3.0
14 stars 4 forks source link

Hacs #1

Closed deformedchild closed 2 years ago

deformedchild commented 2 years ago

Any chance you could set this up for hacs I would love have my mumaroo in Hass or a bit more in the read me on how to set it up thanks

chrisrosset commented 2 years ago

Hello there. I never really expected anyone to stumble upon this so didn't really put much thought into documentation!

I don't use HACS but I purposefully based the design around MQTT auto-discovery. If you have that integration enabled and you can spin up a docker container with my server, you should be good.

Are you familiar with docker? I could show you what my docker-compose.yml file looks like.

deformedchild commented 2 years ago

Hi unfortunately I am very much a failure when it comes to Linux and command prompt so no I'm not familiar with docker. I was also looking at using esphome as this has a ble option for esp32 it's all good thank you very much for replying. It was just something to Fiddle with with a new baby around.

chrisrosset commented 2 years ago

Congratulations! :tada:

The way the project is currently written makes it a bad fit for HACS. It could be set up as an add-on instead but I don't use these either since they I can't use them with my Home Assistant setup.

Using an ESP32 could be an option, yes, though obviously not with this code. It would have to either rewritten (probably in C) or, maybe, one could program it in ESPHome using the MQTT and BLE components.

The hardest, IMO, part (which was figuring out what's being sent over BLE) is already done. Getting the sensors (on/off, speed, and mode) would probably be easy. Controlling it seems tricker. I saw there's a Binary BLE Output component in ESPHome but didn't see one for numbers. I wonder if that means you'd have to resort to using the C++ Custom Output component?

What do you use to run your Home Assistant? How did you install it?

deformedchild commented 2 years ago

I see I setup my hass with raspberry pi 4 with ha OS. Because of my complete inability to program I use node red for my automations and mash up a bit of stolen code when I need to do things that I can't work out how to do with the nodes available. When I get some time I'm going to look through the code and esphome and see if I can create something unholy

chrisrosset commented 2 years ago

I found a spare SD Card and set up HA OS to see if I could get this up and running quick and dirty without having to make this an actual add-on.

The answer is yes, it's doable and I have it working.

Prerequisites:

  1. You need to have the MQTT integration enabled. If you don't have a broker set up already, you can install one through the add-on store ("Mosquitto broker").
  2. You need to discover the MAC address of your Mamaroo. If I remember correctly, you'll need to put it into pairing mode and then use a BLE scanner to find it. You can install a BLE scanner app on your phone and put it right against the Mamaroo.
  3. You need to have the "SSH & Web Terminal" add-on (not "Terminal & SSH"!) installed and set up.

Let me know if you need help with any of these. Once you get these installed, we can try the actual docker container setup.

deformedchild commented 2 years ago

Mate your a legend thank u so so much. I have all the things you have asked about.

chrisrosset commented 2 years ago

Note that "Protection mode" (in the SSH add-on) needs to be disabled.

  1. Open the add-on page and click "Open Web UI"
  2. Clone (copy) the code from Github with this command:
    git clone https://github.com/chrisrosset/mamaroo-mqtt 
  3. Change the current directory to the project's:
    cd mamaroo-mqtt
  4. Build the docker image with this command (this might take a while):
    docker build -t mamaroo .
  5. Create and start a container (replace the XXs with the MAC you found before):
    docker run -d --name mamaroo --restart=unless-stopped -v /var/run/dbus:/var/run/dbus mamaroo --broker localhost XX:XX:XX:XX:XX:XX

If everything goes well, you should should see new entities appear (2 selects and 1 switch) in Home Assistant.

chrisrosset commented 2 years ago

I would love to see a video of it working if you manage to set it all up. :)

deformedchild commented 2 years ago

so no luck my only thought is where do i put the mqtt server login information. Also does the docker require exclusive access to the Bluetooth radio in my raspberry pi as I already have an addon using the Bluetooth for a number of temp sensors.

chrisrosset commented 2 years ago

The "localhost" argument in the final command is the broker information. My script doesn't support any auth so the only broker info is the network location.

On Thu, Jun 2, 2022, 22:37 deformedchild @.***> wrote:

so no luck my only thought is where do i put the mqtt server login information

— Reply to this email directly, view it on GitHub https://github.com/chrisrosset/mamaroo-mqtt/issues/1#issuecomment-1145528512, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAINLPTUMDC3MA4GU6UAL2TVNFVU7ANCNFSM5XJY7HCA . You are receiving this because you commented.Message ID: @.***>

deformedchild commented 2 years ago

Does this help at all During handling of the above exception, another exception occurred:, Traceback (most recent call last):, File "/app/mamaroo_mqtt.py", line 240, in , main(), File "/app/mamaroo_mqtt.py", line 235, in main, asyncio.run(run(args)), File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run, return loop.run_until_complete(main), File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete, return future.result(), File "/app/mamaroo_mqtt.py", line 197, in run, await stack.enter_async_context(mqtt), File "/usr/lib/python3.10/contextlib.py", line 619, in enter_async_context, result = await _cm_type.aenter(cm), File "/usr/lib/python3.10/site-packages/asyncio_mqtt/client.py", line 565, in aenter, await self.connect(), File "/usr/lib/python3.10/site-packages/asyncio_mqtt/client.py", line 233, in connect, raise MqttError(str(error)), asyncio_mqtt.error.MqttError: [Errno 99] Address not available, 2022-06-03 03:39:19,843 INFO Configuration = Namespace(prefix='homeassistant', broker='localhost', serial=None, verbose=False, MAC='88:4A:EA:1F:38:07'), Device 88:4A:EA:1F:38:07 not available, 2022-06-03 03:39:19,882 INFO Connection attempt #0, Traceback (most recent call last):, File "/usr/lib/python3.10/site-packages/asyncio_mqtt/client.py", line 222, in connect, await loop.run_in_executor(, File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run, result = self.fn(*self.args, *self.kwargs), File "/usr/lib/python3.10/site-packages/paho/mqtt/client.py", line 914, in connect, return self.reconnect(), File "/usr/lib/python3.10/site-packages/paho/mqtt/client.py", line 1044, in reconnect, sock = self._create_socket_connection(), File "/usr/lib/python3.10/site-packages/paho/mqtt/client.py", line 3685, in _create_socket_connection, return socket.create_connection(addr, timeout=self._connect_timeout, source_address=source), File "/usr/lib/python3.10/socket.py", line 845, in create_connection, raise err, File "/usr/lib/python3.10/socket.py", line 833, in create_connection, sock.connect(sa), OSError: [Errno 99] Address not available, During handling of the above exception, another exception occurred:, Traceback (most recent call last):, File "/app/mamaroo_mqtt.py", line 240, in , main(), File "/app/mamaroo_mqtt.py", line 235, in main, asyncio.run(run(args)), File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run, return loop.run_until_complete(main), File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete, return future.result(), File "/app/mamaroo_mqtt.py", line 197, in run, await stack.enter_async_context(mqtt), File "/usr/lib/python3.10/contextlib.py", line 619, in enter_async_context, result = await _cm_type.aenter(cm), File "/usr/lib/python3.10/site-packages/asyncio_mqtt/client.py", line 565, in aenter, await self.connect(), File "/usr/lib/python3.10/site-packages/asyncio_mqtt/client.py", line 233, in connect, raise MqttError(str(error)), asyncio_mqtt.error.MqttError: [Errno 99] Address not available, 2022-06-03 03:40:21,572 INFO Configuration = Namespace(prefix='homeassistant', broker='localhost', serial=None, verbose=False, MAC='88:4A:EA:1F:38:07'), Device 88:4A:EA:1F:38:07 not available, 2022-06-03 03:40:21,611 INFO Connection attempt #0, Traceback (most recent call last):, File "/usr/lib/python3.10/site-packages/asyncio_mqtt/client.py", line 222, in connect, await loop.run_in_executor(, File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run, result = self.fn(self.args, **self.kwargs), File "/usr/lib/python3.10/site-packages/paho/mqtt/client.py", line 914, in connect, return self.reconnect(), File "/usr/lib/python3.10/site-packages/paho/mqtt/client.py", line 1044, in reconnect, sock = self._create_socket_connection(), File "/usr/lib/python3.10/site-packages/paho/mqtt/client.py", line 3685, in _create_socket_connection, return socket.create_connection(addr, timeout=self._connect_timeout, source_address=source), File "/usr/lib/python3.10/socket.py", line 845, in create_connection, raise err, File "/usr/lib/python3.10/socket.py", line 833, in create_connection, sock.connect(sa), OSError: [Errno 99] Address not available, During handling of the above exception, another exception occurred:, Traceback (most recent call last):, File "/app/mamaroo_mqtt.py", line 240, in , main(), File "/app/mamaroo_mqtt.py", line 235, in main, asyncio.run(run(args)), File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run, return loop.run_until_complete(main), File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete, return future.result(), File "/app/mamaroo_mqtt.py", line 197, in run, await stack.enter_async_context(mqtt), File "/usr/lib/python3.10/contextlib.py", line 619, in enter_async_context, result = await _cm_type.aenter(cm), File "/usr/lib/python3.10/site-packages/asyncio_mqtt/client.py", line 565, in aenter, await self.connect(), File "/usr/lib/python3.10/site-packages/asyncio_mqtt/client.py", line 233, in connect, raise MqttError(str(error)), asyncio_mqtt.error.MqttError: [Errno 99] Address not available,

chrisrosset commented 2 years ago

The log is helpful and confirmed my suspicion. Turns out I skipped a step in replicating your setup and used my real MQTT broker instead of the one from the add-on. My bad, I'm sorry.

In my setup, I don't use username/password authentication but the official add-on requires it.

I'll have to make some changes to the code to support this.

deformedchild commented 2 years ago

sorry im being so much trouble but thank you so much for you help

chrisrosset commented 2 years ago

Would it be possible for us to get on some sort of live chat to speed this process up? :)

chrisrosset commented 2 years ago

https://meet.jit.si/CertainEventsSellDefinitely

deformedchild commented 2 years ago

What a legend got it working with the home assistant default build you need to add a password and username to the logon for the mosquitto

chrisrosset commented 2 years ago

I've added support for user/pass auth and compiled the notes from this exchange into the project's README in case someone else ever stumbles upon this.

tmeekes commented 2 years ago

I've definitely stumbled upon it... working through setup of my MQTT broker to see if I can get this running or not (between work and feedings... XD).

I'm on HA Core though... so I don't have addons (only HACS) and am installing everything manually in docker. Will see if I can get it operating and report back on results.