Home Assistant Add-On: X10 (CM11) to MQTT Gateway

Any of those should have caused Home Assistant to load the MQTT Switch’s definition and created a switch entity. If it was unable to do it then it would be reported in Logs. Have you seen any related messages in Logs?


EDIT

Just to make sure all the basics are accounted for, I assume you have the MQTT integration configured and operational?

My light configuration:

light:
#Family Room Light X10
  - platform: mqtt
    name: "Family Room Light X10"
    state_topic: "x10/stat/b3"
    command_topic: "x10/cmd/b3"
    payload_on: "ON"
    payload_off: "OFF"
    retain: true
    #optimistic: false
#Doorway Light X10
  - platform: mqtt
    name: "Doorway Light X10"
    state_topic: "x10/stat/b7"
    command_topic: "x10/cmd/b7"
    payload_on: "ON"
    payload_off: "OFF"
    retain: true
    #optimistic: false

Similar to yours except yours missing the state topic. That shouldn’t affect seeing the device. The device showing should have nothing to do with the addon.

Assuming you have the mosquito addon installed, have you already taken control of Lovelace? My understanding is that device/entity won’t show up automatically when one have taken control of Lovelace. Note I am no HA expect.

Mosquito broker appears to be running and happy with my login settings. Its logs report a connection from the IP 172.30.33.3.

The X10 MQTT Gateway reports:

[13:12:48] INFO: Configuring Heyu...
[13:12:51] INFO: CM17 is enabled
starting heyu_relay
Establishing MQTT to core-mosquitto port 1883...
(Using MQTT username vialoma)
CM17 is in use
Waiting for MQTT messages and monitoring for remote changes
Connected to MQTT broker, result code 0

BUT…

Serious issues seem to be occuring in trying to configure the device. Core log entries reveal issues adding entries for platform mqtt (sorry for all the verbage):

2021-05-06 13:12:32 ERROR (MainThread) [homeassistant.components.switch] Error adding entities for domain switch with platform mqtt
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 317, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 509, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 530, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 295, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 316, in _async_write_ha_state
    if not self.available:
  File "/usr/src/homeassistant/homeassistant/components/mqtt/mixins.py", line 328, in available
    if not self.hass.data[DATA_MQTT].connected and not self.hass.is_stopping:
KeyError: 'mqtt'
2021-05-06 13:12:32 ERROR (MainThread) [homeassistant.components.switch] Error while setting up mqtt platform for switch
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 208, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 317, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 509, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 530, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 295, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 316, in _async_write_ha_state
    if not self.available:
  File "/usr/src/homeassistant/homeassistant/components/mqtt/mixins.py", line 328, in available
    if not self.hass.data[DATA_MQTT].connected and not self.hass.is_stopping:
KeyError: 'mqtt'
2021-05-06 13:33:42 ERROR (MainThread) [homeassistant.components.switch] Error adding entities for domain switch with platform mqtt
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 317, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 509, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 530, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 295, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 316, in _async_write_ha_state
    if not self.available:
  File "/usr/src/homeassistant/homeassistant/components/mqtt/mixins.py", line 328, in available
    if not self.hass.data[DATA_MQTT].connected and not self.hass.is_stopping:
KeyError: 'mqtt'
2021-05-06 13:33:42 ERROR (MainThread) [homeassistant.components.switch] Error while setting up mqtt platform for switch
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 208, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 317, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 509, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 530, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 295, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 316, in _async_write_ha_state
    if not self.available:
  File "/usr/src/homeassistant/homeassistant/components/mqtt/mixins.py", line 328, in available
    if not self.hass.data[DATA_MQTT].connected and not self.hass.is_stopping:
KeyError: 'mqtt'

OK, as long as you understand that Mosquitto Broker is not the MQTT integration I asked about. Mosquitto broker is the centerpiece of an MQTT system whereas MQTT integration makes Home Assistant a client of an MQTT system (i.e. enables it to communicate with the broker).

It implies Home Assistant’s ability to communicate with the Mosquitto broker is suspect. That’s why I inquired about the presence and health of the MQTT configuration.

Did you do a config check from HASS? It smells like a YAML issue somewhere.

As far as the process goes, you are correct. Each X10 device will require a separate MQTT device entry. You can use either switch or light, depending on how you want it to show up in Home Assistant.

Thanks for being more specific about the MQTT integration. Looks like I disabled that a few weeks ago after my earlier attempts to get X10 stuff working.

OK, now that I have got the integration configured, and logins happy between gateway add-on, broker, and integration - the system starts up without errors.

Now I have what I thought was an unusable entity: This entity ("switch.counter") does not have a unique ID, therefore its settings cannot be managed from the UI. It is missing the on/off toggle that is typically associated with switches. Turns out the mqtt switch entity UI presents icons side by side - one is OFF and the other is ON. Configuring it as a light gives me the on/off toggle which I was expecting.

That msg appears for all my manually created mqtt sensors, lights, alerts, etc. For those, you make changes in your yaml file. The entity/device still works.

BTW, instead of the beta, I am now using Mark’s v0.2 addon.

v0.2 here as well. I was replying to the earlier thread when I referred to beta…

So I still haven’t figured out where these lights/switches appear to control them. There is no on/off toggle under Configuration > Entities. Nothing appears under Configuration > Devices. And there are no switch or lights in my HA default Lovelace cards…

Edit: I just saw that the “Counter” entity has two icons rather than a toggle. I think I am almost there. Changed the yaml to configure the entry as a light and now it has a toggle switch - AND IT WORKS.

THIS IS THE GREATEST THING SINCE SLICED BAGELS!

That will definitely cause the errors you saw because you instructed Home Assistant to create an MQTT Switch when it had no ability to communicate via MQTT (i.e. communicate with the broker).

It’s not unusable, it is simply unmanageable via the UI. If you want, you can add the unique_id option to the switch’s configuration.

I have now connected both my CM11A (actually an IBM Home Director HD11A) and the CM17A Firecracker to the USB to Serial Adapter connected to Home Assistant. I did this so I could keep the state of X10 entities up-to-date in the HA Dashboard, instead of just using HA to issue commands through the CM17A to remote control my X10 devices.

This keeps turning out better and better. I have learned that I am able to activate non-X10 Home Assistant devices and/or scenes using X10 wall controllers like my Leviton 16400 or XPT, as well as X10 RF remotes like the Palm Pad. Here is an example of an automation where a press of the ON Wall Button (X10:C6) turns ON a zigbee dimming outlet at 100%:

- id: '16204xxx65772'
  alias: X10 BBQ ON
  description: ''
  trigger:
  - platform: mqtt
    topic: x10/stat/c6
    payload: 'ON'
  condition: []
  action:
  - type: turn_on
    device_id: b0d5bffeeoiurfhoiufhwoeie4e072875
    entity_id: light.bbq
    domain: light
    brightness_pct: 100
  mode: single

Thank you, thank you, thank you Mark and others who’s responses helped me figure this out. I now have implemented Home Assistant to thoroughly integrate:

  • X10 (remotes, controllers, macros, switches, plugs)
  • WiFi IoT (Belkin. Honeywell, iRobot, Logitech, TP-Link, Tuya)
  • Zigbee (bulbs, dimming outlets, plugs, sensors, Connected Bulb Remotes)
  • Z-Wave (outdoor outlets, switches)
  • Alexa (Echo Plus and others)

My achieved goals are:

  1. Voice control for just about everything
  2. Local voice control over lights and switches
  3. Wall mounted switches for all lighting
  4. Central dashboard control panel for everything
  5. Use existing X10 ecosystem

This is great to hear, and very creative! I’m really glad others are finding the addon useful, and I’m glad the approach I used is proving more flexible than I had originally anticipated! :slight_smile:

I personally do not use the Bright and Dim commands in my setup, as I have routines with preset levels programmed into my CM11A. But others often do, and I came across this documentation which might be of use to Mark or someone else who has the ability to add bright and dim command coding to this add-on. Where the binary value for the On and Off commands are 0010 and 0011 respectively, the corresponding commands for Bright and Dim are 0100 and 0101.

X10 Addressing

A thorough explanation of X10 programming in a Linux environment is offered here:

Project WiSH

It seems like it might be a straightforward addition, but I am clueless when it comes to python and how much effort it took Mark to get to the current level.

Thanks for this. I’m not sure how I would implement a driver, since addons run in a Docker container. The advantage to running ‘heyu’ is that it is quite proven over the years, and is easy to implement since it is just an executable that can be compiled from source to support any platform supported by HassOS (i386, arm7, arm64, etc).

However, I did look a little closer at dimming recently. When I looked at the original HA X10 integration (which really just ran a locally-installed version of ‘heyu’ on the main Linux system targeting a ‘venv’ style environment), it does not support dimming. The ‘mochad’ integration, which is used for some of the newer USB modules, did.

When I originally looked at X10 dimming, it seemed that different dimmer modules supported different values for dimming. It appears some were 1-22 while others were 0-63. Some modules required going to full brightness then down to a dim level, while newer ones were directly controllable (I think?) Here are some links I found:

https://www.heyu.org/docs/New_LM465.txt
https://www.heyu.org/docs/New_WS467.txt

I’ve never worked with dimmable X10 modules before, so all of this initially seemed quite complex, however… it seems like a simple ‘heyu obdim <1-22>’ is all that is needed to support dimming.

I might give it a go if there is interest. My neighbor has some old X10 modules, I will check with him when he returns from vacation to see if he has a dimmer module to test with.

Wasn’t thinking about the driver part of this, just that the detail included the list of commands for the basic X10 modules. If you recognized the binary commands for On and Off as part of what you worked with in your python coding, I was thinking that the the Bright and Dim commands would be an additional pair of commands. It looks like the brightness level is incremented 1/16 each time one of those commands is issued.

Sorry, can’t help with testing this time. I don’t have any dimmable X10 module.

No problem @yeeCdn, appreciate that. I may have access to a dimmer module for testing once my neighbor (who still has a stash of old X10 equipment) returns from vacation next week.

hi,

I’m running this in HA runing as a virtual machine with usb to serial daptor configured ok, I think its running inside docker

to confirm… addon will not work in docker? Getting following error in log…

[s6-init] making user provided files available at /var/run/s6/etc…exited 0.
[s6-init] ensuring user provided files have correct perms…exited 0.
[fix-attrs.d] applying ownership & permissions fixes…
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts…
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[14:49:27] INFO: Configuring Heyu…
[14:49:28] INFO: CM11 is enabled
starting heyu_relay
Establishing MQTT to core-mosquitto port 1883…
(Using MQTT username mqtt-user)
Waiting for MQTT messages and monitoring for remote changes
Connected to MQTT broker, result code 0
Received: x10/cmd/g9 ON
Sending X10 command to homecode G9
Unable to send address bytes
Error running heyu, return code: 1
Device Status Update: x10/stat/g9

thanks

I just want to confirm that the X10toMQTT Gateway works perfectly happily with CM12U (the UK version) as well.

Time to get out all my old X10 devices…

Good morning,

the complete is amazing.

I’ve been with X10 for years, from Heyu bareback, to get here and this add-on makes communication bidirectional.

I have a problem that I would like to be able to correct,

I have 10 domitized blinds with X10, now I have them as lights, but in order to control the height of the window I should be able to add the brightness …

how can I do it?

I would like to be able to do a routine, that the blinds open 50% in the morning.

any ideas?