Is there an addon for Heyu (x10)?

Did anyone get this working?

I got the addon put together and tried to install it from the interface but get the following error:

ERROR (SyncWorker_2) [hassio.docker.addon] Can’t build local/armhf-addon-heyu:1: Please provide a source image with from prior to commit

I am not too familiar with docker but I found this docker-error
and the solution was: ‘‘FROM’’ must be the first instruction into the Docker file.
Does anyone know how to reslove this? Thanks!

Hi all, I just tried this and got it to install but now am at a loss of what to do next.

It built, installed as an add-on, and lets me start it. Doesn’t throw any errors that I can tell in the logs (hassos log).

But I can’t find anything that it should have installed. I can ssh into my hass.io (which is how I made the local add-on) but no “heyu” or config files anywhere in there.

Any thoughts on where the config file would be and how to access it? I’m running a VM (x86) with a Hassos image, Hass.io, and Home Assistant.

I figured out that it would start and exit, but no errors in the error log.

To confirm this, I dropped to a login prompt in Hass.os (“login” from the CLI) and played around with a few Docker commands. I got it to list the active containers and all the add-ons were there except the Heyu one I just installed.

Log file shows the right output on startup (copying config files); but it just doesn’t stay running and I can’t find any of the files it supposedly copied. Still going to play around with it some more. Might try a manual install of heyu on the hass.io container just to make sure I can get it working by hand, then figure out how to containerize it so it survives updates and such.

I’d welcome an addon for x10. Did this get resolved?

1 Like

Rather than messing around with an add-on I just created a new Docker image that includes heyu. Dockerfile is here: https://gist.github.com/swilson/d096a161059a5da0ff7ce4e020c559fd

Note I’m running on x86; don’t know if it will work on ARM.

@swilson, can this method be used with hass.io or just a dockerized home assistant install?

I don’t use hass.io so I’m not sure.

Ok, so first of all big thx to all of you for sharing above information and a VERY big thx to Kevin!
I’ve finally got it working and this is how i did it (in Hasio latest version).

First i installed the portainer and the terminal addon.
Then i got into terminal and run the following commands:

cd \addons
md heyu-addon
cd heyu-addon
nano Dockerfile

(copy and paste the following from here:)

FROM alpine

RUN apk -U add curl build-base \
 && mkdir /build \
 && cd /build \
 && curl -LsSO https://github.com/msoap/shell2http/releases/download/1.12/shell2http1.12.linux.arm.tar.gz \
 && tar xzf shell2http-1.12.linux.arm.tar.gz shell2http \
 && mv shell2http /usr/local/bin \
 && curl -LsSO http://www.heyu.org/download/heyu-2.11-rc1.tar.gz \
 && tar xzf heyu-2.11-rc1.tar.gz \
 && cd heyu-2.11-rc1 \
 && ./configure --sysconfdir=/etc \
 && make \
 && make install \
 && cd / \
 && apk --purge del curl build-base \
 && rm -rf /build /etc/ssl /var/cache/apk/* /lib/apk/db/*

RUN cp -r /etc/heyu /etc/heyu.default \
 && mkdir -p /usr/local/var/tmp/heyu \
 && mkdir -p /usr/local/var/lock \
 && chmod 777 /usr/local/var/tmp/heyu \
 && chmod 777 /usr/local/var/lock

VOLUME /etc/heyu
EXPOSE 80

COPY heyu-run.sh /usr/local/bin/heyu-run
CMD heyu-run

(till here then ctrl + x and anwser with y)
then i made the file config.json:
nano config.json

(copy and paste the following from here:)

{
  "name": "heyu",
  "version": "1",
  "slug": "heyu",
  "description": "heyu addon",
  "arch": ["armhf", "armv7", "aarch64", "amd64", "i386"],
  "startup": "before",
  "boot": "auto",
  "devices": ["/dev/ttyUSB0:/dev/ttyUSB0:rwm"],
  "privileged": ["SYS_ADMIN"],
  "full_access": true,
  "kernel_modules": true,
  "options": {},
  "schema": {}
}

(till here then ctrl + x and anwser with y)
then i made the file heyu-run.sh

nano heyu-run.sh

(copy and paste the following from here:)

#!/bin/sh

if [ ! -f /etc/heyu/x10.conf ]; then
  cp /etc/heyu.default/* /etc/heyu
  echo "x10config.sample and x10.sched.sample have been copied to your config directory."  1>&2
  echo "Please use them to create x10.conf and x10.sched and re-run." 1>&2
fi

heyu engine 1>&2
heyu upload 1>&2
heyu setclock 1>&2
heyu on D3

if [ -z "$URL_KEY" ]; then
    export prefix="/"
else
    export prefix="/$URL_KEY/"
fi

macro=$(cat <<'SCRIPT')
echo "Access-Control-Allow-Origin: *"
echo 
heyu macro "$(expr substr \"$REQUEST_URI\" 8 100 | tr -cd A-Za-z0-9_-)" 1>&2
SCRIPT
getset=$(cat <<'SCRIPT')
echo "Access-Control-Allow-Origin: *"
echo 
unit_code=$(expr match "$REQUEST_URI" '/\([A-P][01]\{0,1\}[0-9]\)$')
if [ ! -z "$unit_code" ]; then 
    if [ "$REQUEST_METHOD" = "GET" ]; then
        if [ "$(heyu onstate "$unit_code")" '>' 0 ]; then echo ON; else echo OFF; fi
    elif [ "$REQUEST_METHOD" = "POST" ]; then
        body=$(cat)
        if [ "$body" = "ON" ]; then
            heyu on "$unit_code" 1>&2
        elif [ "$body" = "OFF" ]; then
            heyu off "$unit_code" 1>&2
        else 
            heyu xpreset "$unit_code" "$body" 1>&2
        fi
    fi
elif [ "$REQUEST_METHOD" = "POST" ]; then
    house_code=$(expr match "$REQUEST_URI" '/\([A-P]\)$')
    if [ ! -z "$house_code" ]; then
        body=$(cat)
        if [ "$body" = "ON" ]; then
            heyu allon "$house_code" 1>&2
        else
            heyu alloff "$house_code" 1>&2
        fi
    fi
fi
SCRIPT
shell2http -cgi -no-index -port 80 -export-vars 'prefix' \
    "${prefix}macro/" "$macro" \
    "$prefix" "$getset" &
heyu monitor

(till here the ctrl + x and anwser with y)
then i entered the following command:

docker build --tag heyu:1.0 .

DO NOT FORGET the . at the end of the line, imo copy exactly!!!

then i entered the next command:

docker run --privileged -d -v /mnt/data/supervisor/homeassistant:/etc/heyu -v /etc/localtime:/etc/localtime --device /dev/ttyUSB0 -p 8080:80 heyu:1.0

Now the container is being build and if it is finished you can test it with the following command:

curl -v POST http://localhost:8080/A1 -d "ON"

This should put A1 in the on position, so if this is working you want to go to your configuration.yaml:
cd \config
nano configuration.yaml
and add the following lines:

shell_command:
  cmd_x10_on: "curl POST http://localhost:8080/{{x10code}} -d 'ON'"
  cmd_x10_off: "curl POST http://localhost:8080/{{x10code}} -d 'OFF'"
  cmd_x10_level: "curl POST http://localhost:8080/{{x10code}} -d '{{x10level}}'"

(till here then ctrl + x and anwser with y)
and finally add the x10 switches:

nano light.yaml

     slaapkamerlichtrechts:
      friendly_name: "Slaapkamerlichtrechts"
      turn_on:
        - service: shell_command.cmd_x10_on
          data_template:
            x10code: "D3"
      turn_off:
        - service: shell_command.cmd_x10_off
          data_template:
            x10code: "D3"
      set_level:
        - service: shell_command.cmd_x10_level
          data_template:
            x10code: "D3"
            x10level: "{{(brightness/4)|int}}'"

Now you are able to turn on, off and dim an X10 device from Hassio.

That being said, i havent got a clue of Docker or those other files(i just viewed and adapted), so a real Guru will probably say that all this is a big security risk(running in privileged mode and shit)… But it works, i’ve got a great firewall and i live alone.

Cheers.

3 Likes

I’m trying to add x10 to Raspberry PI 4 using HEYU and a CM11a with Home Assistant build image. Thank you for all the input. I took the romanc content and got it to build / run from the built-in SSH & Web terminal. While I was able to use the command line per romanc’s instructions, I was not able to access the service or x10 devices inside of the Home Assistant UI. I then adapted a few things from romanc’s input to create a true ‘add-on’. It actually starts, runs, and stays running. As an add-on I can go into the HEYU add-on log and see the monitor is running in the background. I can see x10 commands on the power line (triggered by a manual x10 transmitter) come into the CM11a and be logged into the HEYU add-on log in the UI.
However I have not been able to actually turn lights on or see devices show up in Home Assistant.

I’m confused on the instructions documented on the HEYU man pages which say to configure devices in “x10.conf”. The instructions on the web page “https://www.home-assistant.io/integrations/x10” say to add device information to configuration.yaml.

Any advice out there on a) which configuration file/approach is right if I’m trying to run HEYU as an add-on and b) has anyone gotten HEYU to report x10 devices in the devices page of Home Assistant regardless of using add-on versus HEYU build/run instructions illustrated by romanc?

Hi Stephen,

Before I used Hasio, I used Home Assistant without Docker on a raspberry. Then i too, would only have to set the usb port in x10.conf (like in Hasio above) but then I could use the x10 platform. Heyu would communicate with home assistant as a background service (true the x10 platform) and you could see if something is turned on manual(without Home Assistant, a switch for instance). My lights.yaml file would look like this:

  • platform: x10
    devices:
    • id: c16
      name: Livingroomlight

So i did not put all my x10 devices in X10.conf but in lights.yaml (much easier then the docker approach with the command line). I would like to know what things you adapted, maybe i can help.

Thanks for the reply. Romanc, will your lights show up as ‘entities’ in home assistant?

@stephenwill @romanc
I keep getting a failure to connect to localhost port 8080 connection refused when I run the test. I assumed it was because I had the wrong port, but I’m pretty sure I have the right port now. I’m running on /dev/ttyS0 since my CM17a is on COM1. The Serial Port forwarding is operating too. Any ideas? I followed the instructions above just simply swapping ttyS0 for ttyUSB0. Even going through S1-3 didn’t do it.

Edit: I just realized since I’m using a Virtualbox and not a Pi, I’m not using Arm, I’m x86_64. That means I might have the wrong shell2http loaded. Do you know if that would make a difference and if so, I need to switch that file out in the build.

Not automatically, because they are not in the config of heyu. I put them in the lights.yaml file.

That’s a complete different setup. I don’t think my config is gonna work for you. Arm vs Intel…

So I got it to work making a 2nd VirtualBox running Heyu exclusively with Ubuntu and then letting HassOS to communicate with the 2nd box via command line. Works like a charm.

@romanc - Thanks for your meticulously detailed steps. I too believe I am trying to add x10 to Raspberry PI 4 using HEYU and a CM11a with Home Assistant build image. After creating the heyu-run.sh file, I enter the following command:

docker build --tag heyu:1.0 . (making sure to include the “.”!)

and the response is

-bash: docker: command not found "my comment: <<<<<< ??????"

This is where I get totally confused - is the Hassio install a docker container or not? Enabling the Advanced features of Portainer reveals the hidden “type” elements of Hassio. I’m clearly stuck in the forest, but I am very frustrated trying to figure out exactly in which forest I am stuck. Used Imager to setup the SD card using “hassos_rpi3-5.12.img” for my Raspberry Pi 3B+.

It should be done in the Hassio terminal, that being said…
I’ve personally stopped using it, the configuration was just too slow on a Pi3 or 4.

I started over with a lite version of the latest pi os, installed homeassistant and heyu manually the old fashion way without docker and that worked like a charm!

mmotley has created an add-on which works with MQTT in a supervised HA installation to integrate the X10 CM11A and/or CM17A units into Home Assistant. ON/OFF and state are supported, but no dimming.

In case someone needs X10 to MQTT bridge with dimming support. This is not homeassistant add-on, just x10 to mqtt bridge I’m using this with node-red. Forked kevineye’s work and added support for getting brightness levels and sending out any x10 command (including absolute dimming etc). I think if someone wanted they could write ‘homeassistant support’ for this in quite simple node-red flow, sending out MQTT autodiscovery commands to Homeassistant for devices to config them etc.

cuetus/docker-heyu-mqtt