New Binding!

Hello all, I’m trying to implement a new binding in openhab. I have some questions. I would like to know if with the next java code I could get the command from the event bus.

protected void internalReceiveCommand(String itemName, Command command) {
    logger.debug("internalReceiveCommand({},{}) is called!", itemName, command);
    if (command.toString().equals("OFF")) {
        logger.debug("mi apagado");
    } else {
        logger.debug("mi encendido");

I suppose that the parameter command is the command from the event bus and I guess that the parameter itemName is the name of the item that I have configured in the .item file. I’m right?
Thank you all.

Why not

import org.openhab.core.library.types.OnOffType;

and use the following

if (OnOffType.ON.equals(command)) {
//do something

This is better coding style

Ok, I wil try this method but How I get the itenName then? I have genereted the jar file of my binding and I have put it on my openhab addons folder but it doesn’t work. There are no message about my binding activation. Do you know what may be the problem?

Thank you very much!

Have you already implemented BindingProvider and BundleActivator for you binding? If not, take a look a simple binding e.g. exec binding what you should do.

No, I have not implemented BindingProvider. What do I have to put in this file? This is my BundleActivator:

package org.openhab.binding.x10cm15;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class x10cm15Activator implements BundleActivator {

private static Logger logger = LoggerFactory.getLogger(x10cm15Activator.class);
private static BundleContext context;

 * Called whenever the OSGi framework starts our bundle
 * @param bc the bundle's execution context within the framework
public void start(BundleContext bc) throws Exception {
    context = bc;"X10 cm15 binding has been started.");

 * Called whenever the OSGi framework stops our bundle
 * @param bc the bundle's execution context within the framework
public void stop(BundleContext bc) throws Exception {
    context = null;
    logger.warn("X10 cm15 binding has been stopped.");

 * Returns the bundle context of this bundle
 * @return the bundle context
public static BundleContext getContext() {
    return context;


I’m trying to implement an X10 binding. So my binding is so simple because it only has to receive a command from the event bus and call a c library to turn on or off a device.

Could someone help me?

What about having a look how the MochadX10 binding is written ?

I will have a look to the this binging. Another question when I follow this steps to generate the jar file:

1.Right-click on your binding project
2.Select ExportChoose
3.Plug-in Development->Deployable plug-ins and fragments
4.Fill “Directory” with the Path where you want your jar-file to appear
5.Check “Use class files compiled in the workspace” on the “Options” tab
6.Click Finish and check your Directory

But fail and create a where I can read the next kind of errors:

  1. ERROR in /home/dani/openhab-master/bundles/binding/org.openhab.binding.x10cm15/src/main/java/org/openhab/binding/x10cm15/internal/ (at line 31)
    public void run() {
    The method run() of type x10cm15Oncommand must override a superclass method

I’m using java-oracle 1.8 and I don’t know what is wrong because the files have no errors in the eclipse proyect.

Thank you for answer me!