Adding X10 support

I’m using the X10 component that comes with HA. It works, but I can’t seem to switch a light off from the switch I get on the web. I can in automation or using the voice control. Dimming would be good as I’d like my landing light to come on at a lower level during the night. I’ll see if I can understand the code some time. I’ve only just set it all up, so still testing, but for just turning lights on and off it seems to be fine.

Confusingly, the x10 component I created https://github.com/clach04/home-assistant-x10 is not the one that ships with HA, even though it was published earlier.

https://github.com/clach04/home-assistant-x10 definitely works with the web interface at least with 0.27.x, I’ve not yet had chance to upgrade to 0.32. It uses switches but the underlying x10 control library can be used for dimming so that would require some work.

I believe Heyu supports dimming which is what the component that ships with HA uses. So if Heyu is working for you, hacking the official one is probably going to be the quickest path for you. If you want to take a look at the portable (runs everywhere including Windows) component that doesn’t require Heyu and add dimming, I’d be interested in Pull Requests :wink:

If I install your component will it clash with the included one as they seem to have the same name? I had to install Heyu to get this far, but it is pretty much working. I’m not against doing some testing for you if I can find the time.

No clash, they have the same (end) name but the name space is different.

I can’t edit the original post so posting current status here.

I’m using https://github.com/clach04/home-assistant-x10 with HA 0.33.0 every day with a Firecracker serial device https://www.x10.com/cm17a.html (over USB with a usb2serial adapter) on a Windows machine.

Whilst I do not use https://sourceforge.net/projects/mochad/ I’ve had a report that this works with Mochad (on a Raspberry Pi).

Posted Dimming control over X10 lights/lamps - it should avoid needing to read through the whole thread for anyone interested in x10 support without heyu.

This is really cool. Can you tell me what the ‘X10cmd’ is? Is this a script you wrote or a binary? Can you share?

X10cmd is just a shell script:

#!/bin/sh

echo "$@" | nc localhost 1099

I don’t use it anymore because I’ve switched to using the mochad component, but here is an updated example:

some_lamp:
  oncmd: "/home/hass/X10cmd rf a4 on"
  offcmd: "/home/hass/X10cmd rf a4 off"
  statecmd: "/home/hass/X10cmd st | /bin/sed -n 's/.*4=\\([0-1]\\).*/\\1/p'"
  value_template: '{{ value == "1" }}'
1 Like

i notice there is statecmd in this script for X10
i check this "statecmd: “/home/hass/X10cmd st | /bin/sed -n ‘s/.4=\([0-1]\)./`/p’”
but seems not working.
i’m trying to implement X10 motion sensor like MS10A X10 module,
but not sure whether possible?

The example is using A4 as the house code, so the “4” in the regex would need be changed to match the code of your device. I don’t use X10 motion sensors, but I believe they are listed as security devices in the status output. I’m not sure if the status differs enough to require more changes. Perhaps you could post the output after triggering your device?

It run in console "x10cmd st | /bin/sed -n ‘s/.1=([0-1])./`/p’ " and do “x10cmd rf e1 on” in other console but still doesn’t show anything
I write this script below, but it shows “Switch On” in console, however when I integrate in HA never trigger. Any idea why?

Detect Remote Control HouseUnit E1

  • name: Status Utility
    platform: command_line
    command: x10cmd15 st | grep “House E” | grep “1=1” > nul && (echo “Switch On”) || (echo “Switch Off”)
    device_class: connectivity
    payload_on: “Switch On”
    payload_off: “Switch Off”

Sorry. I missed this. Could you post the output from your X10 controller after sending it a status command? Trigger the device first so it shows up in the output as on.

Hi folks, just started playing around with HA and since I have a lot of old X10 components lying around I decided to test if I could get them up and running with HA. I installed a fresh Rasbian light image on my PI2, then Home Assistant All In One. I then installed heyu and added one lamp module for testing. In the interface it shows up - I am able to switch on the component but after a second or two the button goes back to “OFF” state. It does not seem that the HA interface remembers the state of the component - is this a known issue?

I also wonder if dimming is possible through HA/heyu setup - any tips here would be appreciated.

Thanks!

Brgds
Christian

Have you got these in a group with a switch?

I’ve found HA doesn’t quite work well like that…

E.g. if the group is turned off, and you turn a member of the group on, it’ll flick on, turning the Lamp, or whatever on, and then flick off, leaving the lamp on.

I just removed the switch element of the group, I forget the option, it was hard to Google, so if this is your problem, and you want me to go check my config, do ask.

Steve

Hi Steve & thanks for the reply.

No I do not have the switch in a group, so I do not think this is a problem. I also have some Hue bulbs integrated and these work just fine. I suspect this is related to the X10 HA integration.

Brgds
Christian

If you look at https://github.com/home-assistant/home-assistant/blob/a4f1f6e724d61a6da51cce17729418e0dd12890c/homeassistant/components/light/x10.py#L38 you can see that HA uses “heyu onstate” to get the current state of the light. This might be failing for you? Try running it manually as the HA user on your HA system and see what results you get. Don’t forget to put in the correct house/unit code, e.g. A1.

This is also the file we’d need to enhance to get dimming working.

Hi an thx for the tip.

I will try to check logs (I assume they are somehwere) then to see if there is any more information available - I am new to both HA so I have a steep learning curve ahead of me :smiley:

I have been able to switch the lamp module successfully on and off calling the service manually: light - turn_on/turn_off/toggle.

Brgds
Christian

Here is the log - to me this means nothing, maybe someone see what the issue could be?

2017-05-18 18:14:41 ERROR (MainThread) [homeassistant.helpers.entity] Update for light.hello_world fails
Traceback (most recent call last):
_ File “/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/entity.py”, line 225, in async_update_ha_state_
_ None, self.update)_
_ File “/usr/lib/python3.4/asyncio/futures.py”, line 388, in iter_
_ yield self # This tells Task to wait for completion._
_ File “/usr/lib/python3.4/asyncio/tasks.py”, line 286, in wakeup
_ value = future.result()_
_ File “/usr/lib/python3.4/asyncio/futures.py”, line 277, in result_
_ raise self.exception
_ File “/usr/lib/python3.4/concurrent/futures/thread.py”, line 54, in run_
_ result = self.fn(*self.args, **self.kwargs)_
_ File “/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/light/x10.py”, line 96, in update_
_ self.state = bool(get_unit_status(self.id))
_ File “/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/light/x10.py”, line 38, in get_unit_status

_ output = check_output('heyu onstate ’ + code, shell=True)_
_ File “/usr/lib/python3.4/subprocess.py”, line 620, in check_output_
_ raise CalledProcessError(retcode, process.args, output=output)_
subprocess.CalledProcessError: Command ‘heyu onstate a1’ returned non-zero exit status 1

Figured it out!! The Heyu state engine was not initiated. By typing command line ‘heyu engine’ everything works perfectly :slight_smile:

1 Like

This is very late…
But the switch bounce-back in the web interface of HA happens when “heyu engine” either hasn’t been started or is broken some how.
You can check it’s working by running as the user that HA is running as:
heyu onstate A1
(A1 being a valid house code)
If it’s not running it’ll tell you, run it using:
heyu engine
I’m using a systemd script I found/modified to automate this.