Controlloing openHAB devices from external program?

Hello -

I am new to the opehHAB community, but have been active in home automation for more than a decade. I’m currently moving from old X10 stuff controlled with my Linux box using heyu and going to Insteon.

Honestly I didn’t know until now that there was a way to control Insteon devices (directly) via Linux until I discovered openHAB, so I’m pretty excited!

While transitioning my hardware, I’d like to be able to control my Insteon devices (directly not via their X10 compatibility) from some of my old scripts. So my question is: is it possible to interact with openHAB devices from the Linux command line? Most of my scripts are in PERL, but I can always use external commands from PERL if there is no native lib to use.



I have a similar environment that was primarily X10 using iHouseHomeAutomation (freeware no longer supported). I still use it to interact with the 12 or so x10 modules I still have in the house, however, I use openHAB as my main controller. I currently drive all my x10 modules thru command line using the exec binding in openHAB. Prior to fully controlling from openHAB, I would use MQTT publish commands, also command line based, from iHouse to update the state in openHAB. This was the simplest and lowest programming knowledge required, which works for me. Also, since I’m using MQTT with my Arduino sensors, it made sense to combine the use vs. bringing on another controller or gateway.


Thanks for the info. I also used the exec binding to control my X10 stuff from openHAB. Didn’t think of using mqtt for feedback.

I guess what I’m looking for is going the other way. I’m looking to control an openHAB device from outside of openHAB.


Depending on what your other app/device is, there are multiple ways to talk to openHAB and control devices in it. Again, I used MQTT messages from my x10 app, which were then tied to a device in openHAB. The REST API is also an option, as are a number of other choices. Maybe a more specific example or use case can be found via search or if you post it here I’m sure other forum members would chime in.

Hi Yancy,

OK, here are some more details on what I am looking to do:

Running Heyu on my linux box, I have heyu run a script when it sees motion from an X10 motion sensor. The script checks the time of day, and based on the time of day turn on my bathroom light to a specific brightness.

  • If the sun is up, it doesn’t turn on the light
  • From sundown to 11:00pm it turns on 80%
  • From 11pm until Sunrise it turns on the light to like 20% to give you enough light to use the bathroom, but not to blind you when you go in from being asleep.
  • Locally turning on this switch also sends an X10 powerline command letting you know that it was turned on, so if you operate the switch locally, I have a rule set up that the script will not run and try to change the brightness on you.

The light being controlled is an Insteon switch, and I am using its X10 address. My script uses the heyu X10 to send the powerline command to turn on the switch. so I just have it run “heyu on BathroomLight”.

The one issue I have with this is speed: If you walk into the bathroom in the dark, and locally turn on the switch, it will send the X10 powerline command to let Heyu know that it is locally on. The Insteon switch takes about 1 to 2 seconds to send this command out. In the mean time the motion sensor sends the motion command and heyu fires off the X10 command to turn on the swtich to its determined brightness. So I wind up with the race condition where if the On command gets sent before the switch tells the computer it is already on, you turn on the light, and it immediately dims, forcing you to have to hit the switch again to get back to full brightness.

So, what I am looking for is a way to communicate with this switch FASTER. I am hoping the Insteon protocol is that answer. If my script can be told that the Insteon switch was locally turned on BEFORE it tries to send the ON command down the X10 powerline then I can fix this.

Since openHAB is the only way I know that I can communicate with the Insteon bus directly on Linux, here is what I guess I need:

  • A way to get openHAB to create a “lock file” IMMEDIATELY upon this switch being locally turned on. I’m not sure if openHAB will see this state change in realtime or if it waits to poll the device at some pre-determined time interval?
  • A way to tell openHAB to turn on an Insteon light (through the openHAB insteonplm binding) via a command line statement like (psudocode) “openhab on BathroomLight”.


OH does not communicate directly to any of your Insteon/x10 devices, instead it needs to still communicate thru an Insteon Hub/PLM. The InsteonPLM binding provides this communication from the OH bus to your Insteon gateway. So, improving the speed of communication is highly unlikely.

One idea, which isn’t the best I’ll admit, is to add a delay in your existing code with enough time to allow for the communication to arrive from the switch, check if it is already on, and then determine the next command.

Lastly, I’m curious as to why you would turn the switch on if you already have motion sensing? Why not let HA do it’s job?

Thanks Again Yancy.

Understood that openHAB speaks on the Insteon bus via the PLM/Hub. What I means (but wasn’t clear) was that I want to operate this Insteon switch via the Insteon Protocol rather than using the same switches X10 address and communication via the X10 protocol. From what I understand the Insteon protocol is much faster than X10.

I think you have gotten me what I was looking for, and writing it all down has helped me think through the issue.

I’ve looked into MQTT as you suggested and think this will allow me to transition from my old setup to openHAB.

My plan is to do this:

  • Receive X10 rf motion sensors with my W800RF32A receiver and use heyu to take these incoming commands and put them onto the MQTT bus.

  • Write an openHAB rule to write a lock file (or maybe set a variable) when the switch is locally turned on and clear this flag a few seconds later.

  • Write an openHAB rule to first check for the lockfile or variable value and trigger this light to specific brightnesses based on time of day when receiving this trigger from the MQTT bus.

A few posts back yo mentioned that you use the MQTT bus to update openHAB switch states that are changed on the X10 bus. Wondering you might share an example of that code?