Can't run Mochad

Hi everyone,

I’m very new in Hassio and I have everything up and running on a PI4 with version 0.108.1 (HassOS 3.12).

I’m trying to setup some old X10 stuff with mochad but I’m getting some errors after reboot and can’t get them to work.
My equipment (CM15PRO) is compatible with mochad, I’ve already tested with raspbian and I it works fine.

In the configuration file I have:

# X10 Controller
mochad:
  host: 127.0.0.1
  port: 1099

switch:
  platform: mochad
  devices:
      - address: a2
        name: light
        comm_type: pl
      - address: a4
        name: fan
        comm_type: pl

And after reboot I see this error on the log:

Error while setting up mochad platform for switch
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 178, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/mochad/switch.py", line 34, in setup_platform
    add_entities([MochadSwitch(hass, CONTROLLER.ctrl, dev) for dev in devs])
  File "/usr/src/homeassistant/homeassistant/components/mochad/switch.py", line 34, in <listcomp>
    add_entities([MochadSwitch(hass, CONTROLLER.ctrl, dev) for dev in devs])
AttributeError: 'NoneType' object has no attribute 'ctrl'

Can anyone give some advice?

Thanks

Looks like you’re missing the - in front of platform.

 # Example configuration.yaml entry
 switch:
   - platform: mochad
     devices:
       - address: a1
       - address: a5

Hi @lviperz, thanks for you answer.

I’ve tried different combinations and I also get issues. Now I only have one device and the configuration looks like this:

# X10 Controller
mochad:
  host: 127.0.0.1
  port: 1099

switch:
  - platform: mochad
    devices:
    - address: a2
      name: light

The error is the following:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 178, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/mochad/switch.py", line 34, in setup_platform
    add_entities([MochadSwitch(hass, CONTROLLER.ctrl, dev) for dev in devs])
  File "/usr/src/homeassistant/homeassistant/components/mochad/switch.py", line 34, in <listcomp>
    add_entities([MochadSwitch(hass, CONTROLLER.ctrl, dev) for dev in devs])
  File "/usr/src/homeassistant/homeassistant/components/mochad/switch.py", line 52, in __init__
    self._state = self._get_device_status()
  File "/usr/src/homeassistant/homeassistant/components/mochad/switch.py", line 96, in _get_device_status
    status = self.switch.get_status().rstrip()
  File "/usr/local/lib/python3.7/site-packages/pymochad/device.py", line 55, in get_status
    return self.controller.read_data().lower()
  File "/usr/local/lib/python3.7/site-packages/pymochad/controller.py", line 83, in read_data
    data = self.socket.recv(4096)
ConnectionRefusedError: [Errno 111] Connection refused

Any ideas?

Thanks

Not sure but maybe try replacing 127.0.0.1 with localhost?

# Example configuration.yaml entry
mochad:
  host: localhost
  port: 1099

Didn’t work.

With ´nc localhost 1099´ it just returns to the bash without any output so it seems that mochad isn’t running.
I’ve searched the web and some say that “Updating pymochad to 0.2.0 fixes the issue”.
Does anyone knows how I can do that?

I’m unable to run pip3.

Thanks

Is the mochad daemon running? If mochad was setup correctly the daemon should auto start when the cm-15pro in plugged in to the usb.

I run some x-10 stuff but I’m using heyu with a cm-11a for powerline and a wgl w800usb for wireless. I do have a cm-15pro and tried mochad but had better results with the heyu method. I do slightly remember when I attempted the mochad route that I had to install mochad myself. I believe HA just integrates with mochad. You still have to set it up so HA has something to connect to.

I’m running HA core on ubuntu in a venv. I’m not sure how to get mochad installed on hassio, sorry.

I believe the mochad isn’t running but how can I check on hassio?

The cm-15pro works fine with mochad on raspbian.

Thanks

If you are running home assistant on hassos, it probably is not running, and now way to install. You will need to run home assistant supervised ( previously known as hassio on generic Linux) on raspbian to install mochad.

Thanks @francisp for your answer.

Yes I’m running HA on hassio and I see mochad in the integration list on the UI.
Do you know if it’s possible to check if the daemon is running?

Ssh to the host and run systemctl status mochad
Ssh to the host:

Thanks for the info.

You’re right, the daemon is not running.
Unit mochad.service could not be found.

Any way to install it or activate it?

I guess it should be already installed because it’s on the integration list right?

That it is on the integration list does not imply it is installed on hassos. There are many ways to run home assistant, home assistant on hassos (previously know as hassio) is just one of them. Eg MQTT is on the integration list, but mosquitto is not installed on hassos. If you want to use MQTT on hassos, you have to install the mosquitto add-on.

There are 2 ways to do what you need :
1/ install the portainer add-on, and see if you can use it to install a container containing mochad
2/ take a snapshot of your current home assistant, copy it to your PC, install raspbian, install mochad, install home assistant supervised on raspbian, restore your snapshot.

Hi @francisp, thanks a lot for your help, I guess i’m almost there.
I’ve followed your advice and installed a container with mochad using portainer add-on(https://github.com/jshridha/docker-mochad) and in that container console I can not send X10 commands like:
echo "pl a1 off" | nc localhost 1099
I can also send these commands in the terminal (normal ssh to port 22), specifying the container IP.

What I can’t do for now is configure in configuration.yaml. Added the configuration as mentioned on https://www.home-assistant.io/integrations/mochad/ using the IP of the container, but I still get the same error of my first post.
Do I need a different configuration?

Your second suggestion will be my plan B if I give up on this aproach.

So finally it’s working!
With the docker-mochad container running (needed to add it to the correct network and set a static ip) I can finally use mochad on hassio.
Also in the configuration I use the container IP instead of localhost.

In fact, due to some issues in the configuration.yaml I’ve had in the beginning I also tried the switch.command_line and it also works that way, useful to use the covers with the cover template.

Thanks everyone for the help.

It’s the custom of this community to mark the post containing the solution, or key information leading to the solution, with the Solution tag. In other words, it was the post made by francisp that provided the solution and should be marked accordingly. Give credit where credit is due.

What you’ve done is marked your own post as the Solution (when all it does is confirm the suggested solution works).

Hi @123,

Sure no problem, already corrected.
I marked mine because i’m validating and providing more detailed info on how to implement one of Francis suggested solutions.

I’m having intermittent failures of Mochad Integration. I’m running Mochad outside of HASS on another machine (RPI). It has worked for the last 2 years without a problem. This has only become a problem since v108.0. After repeated restarts of HA it will function flawlessly until HA is restarted again. It looks like a timeout during initialization. Is there any way to increase the timeout parameter? The error logs I’m seeing are:

Logger: homeassistant.components.switch
Source: components/mochad/switch.py:34
Integration: Switch ([documentation](https://www.home-assistant.io/integrations/switch), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+switch%22))
First occurred: 8:26:06 PM (1 occurrences)
Last logged: 8:26:06 PM

Error while setting up mochad platform for switch

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 178, in _async_setup_platform await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT) File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for return fut.result() File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/usr/src/homeassistant/homeassistant/components/mochad/switch.py", line 34, in setup_platform add_entities([MochadSwitch(hass, CONTROLLER.ctrl, dev) for dev in devs]) File "/usr/src/homeassistant/homeassistant/components/mochad/switch.py", line 34, in <listcomp> add_entities([MochadSwitch(hass, CONTROLLER.ctrl, dev) for dev in devs]) AttributeError: 'NoneType' object has no attribute 'ctrl'

Config is:

mochad:
  host: 192.168.1.219
  port: 1099`

light 3:
  - platform: mochad
    devices:
      - address: c1
        name: Bedroom_Dresser
        comm_type: pl
      - address: c2
        name: Bedroom_Side_Table
        comm_type: pl

Hi @JPA,

I sometime have that issue using 108.4, now very often and usually one reboot fixes it.

If you use switches a simple workaround that works flawless for me is using command_line to control it. See the config below.

Anyway maybe you can open a bug if that still happens in the latest version (108.9 today).

switch:
  - platform: command_line
    switches:
      x10_cmd_a4:
        command_on: 'echo "pl a4 on" | nc 172.30.33.250 1099'
        command_off: 'echo "pl a4 off" | nc 172.30.33.250 1099'
        command_state: 'echo "st" | nc 172.30.33.250 1099'
        value_template: '{{ "4=1" in value }}'
        friendly_name: Room cover   
1 Like

Thanks. I’ll give that a try.