Using MySensors 1.5 in OpenHAB 1.7.0+ with rules only

Hey folks! I’ve found a very complete and well-working framework for using dirt-cheap nRF24l01+ transceivers by Nordic to build a sensor-actor mesh-network.

A Gateway Software is flashed to an Arduino, which is also connected to the radio transceiver to listen and talk to the radio network of the other nodes. Communication to OpenHAB will be a simple serial protocol with many hard-defined device types.

After evaluating the system for a few weeks, I can say this is the most complete radio network framework I’ve ever seend (even tops/improves maniacbug’s and TMRh20’s) great work on the RF24, RF24Network and RF24Mesh libraries.

Implementation needs to be done using the basic serial protocol described here:


I am very, very active in this topic right now, so feel free to contact my anytime regarding this feature.

For instant usage, I rework a small implementation into the rules inspired by l154 from the forums.

Only the constants are finished right now. Receiving and decoding messages works as well but is not well-coded, since I am not good at Java and some constructs like the tenary operator don’t seem to work inside the rule (Xtent).

    // MySensors 1.5 ///////////////////////////////////////////////////////////////////////////////////
// MessageTypes //
val int M_PRESENTATION    = 0  // Sent by a node when they present attached sensors. This is usually done in setup() at startup.
val int M_SET             = 1  // This message is sent from or to a sensor when a sensor value should be updated
val int M_REQ             = 2  // Requests a variable value (usually from an actuator destined for controller).
val int M_INTERNAL        = 3  // This is a special internal message. See table below for the details
val int M_STREAM          = 4  // Used for OTA firmware updates

// SubTypes for MessageType M_PRESENTATION //
// (Not used for now, as automatic configuration is not possible in OpenHAB 1.)
// val int S_DOOR                     = 0   // Door and window sensors
// val int S_MOTION                   = 1   // Motion sensors
// val int S_SMOKE                    = 2   // Smoke sensor
// val int S_LIGHT                    = 3   // Light Actuator (on/off)
// val int S_BINARY                   = 3   // Binary device (on/off), Alias for S_LIGHT
// val int S_DIMMER                   = 4   // Dimmable device of some kind
// val int S_COVER                    = 5   // Window covers or shades
// val int S_TEMP                     = 6   // Temperature sensor
// val int S_HUM                      = 7   // Humidity sensor
// val int S_BARO                     = 8   // Barometer sensor (Pressure)
// val int S_WIND                     = 9   // Wind sensor
// val int S_RAIN                     = 10  // Rain sensor
// val int S_UV                       = 11  // UV sensor
// val int S_WEIGHT                   = 12  // Weight sensor for scales etc.
// val int S_POWER                    = 13  // Power measuring device, like power meters
// val int S_HEATER                   = 14  // Heater device
// val int S_DISTANCE                 = 15  // Distance sensor
// val int S_LIGHT_LEVEL              = 16  // Light sensor
// val int S_ARDUINO_NODE             = 17  // Arduino node device
// val int S_ARDUINO_REPEATER_NODE    = 18  // Arduino repeating node device
// val int S_LOCK                     = 19  // Lock device
// val int S_IR                       = 20  // Ir sender/receiver device
// val int S_WATER                    = 21  // Water meter
// val int S_AIR_QUALITY              = 22  // Air quality sensor e.g. MQ-2
// val int S_CUSTOM                   = 23  // Use this for custom sensors where no other fits.
// val int S_DUST                     = 24  // Dust level sensor
// val int S_SCENE_CONTROLLER         = 25  // Scene controller device
// val int S_RGB_LIGHT                = 26  // RGB light
// val int S_RGBW_LIGHT               = 27  // RGBW light (with separate white component)
// val int S_COLOR_SENSOR             = 28  // Color sensor
// val int S_HVAC                     = 29  // Thermostat/HVAC device
// val int S_MULTIMETER               = 30  // Multimeter device
// val int S_SPRINKLER                = 31  // Sprinkler device
// val int S_WATER_LEAK               = 32  // Water leak sensor
// val int S_SOUND                    = 33  // Sound sensor
// val int S_VIBRATION                = 34  // Vibration sensor
// val int S_MOISTURE                 = 35  // Moisture sensor

// SubTypes for MessageType M_SET //
val int V_TEMP                  = 0   // Temperature
val int V_HUM                   = 1   // Humidity
val int V_STATUS                = 2   // Binary status. 0=off 1=on
val int V_LIGHT                 = 2   // Deprecated. Alias for V_STATUS. Light status. 0=off 1=on
val int V_PERCENTAGE            = 3   // Percentage value. 0-100 (%)
val int V_DIMMER                = 3   // Deprecated. Alias for V_PERCENTAGE. Dimmer value. 0-100 (%)
val int V_PRESSURE              = 4   // Atmospheric Pressure
val int V_FORECAST              = 5   // Whether forecast. One of "stable", "sunny", "cloudy", "unstable", "thunderstorm" or "unknown"
val int V_RAIN                  = 6   // Amount of rain
val int V_RAINRATE              = 7   // Rate of rain
val int V_WIND                  = 8   // Windspeed
val int V_GUST                  = 9   // Gust
val int V_DIRECTION             = 10  // Wind direction
val int V_UV                    = 11  // UV light level
val int V_WEIGHT                = 12  // Weight (for scales etc)
val int V_DISTANCE              = 13  // Distance
val int V_IMPEDANCE             = 14  // Impedance value
val int V_ARMED                 = 15  // Armed status of a security sensor. 1=Armed, 0=Bypassed
val int V_TRIPPED               = 16  // Tripped status of a security sensor. 1=Tripped, 0=Untripped
val int V_WATT                  = 17  // Watt value for power meters
val int V_KWH                   = 18  // Accumulated number of KWH for a power meter
val int V_SCENE_ON              = 19  // Turn on a scene
val int V_SCENE_OFF             = 20  // Turn of a scene
val int V_HVAC_FLOW_STATE       = 21  // Mode of header. One of "Off", "HeatOn", "CoolOn", or "AutoChangeOver"
val int V_HVAC_SPEED            = 22  // HVAC/Heater fan speed ("Min", "Normal", "Max", "Auto")
val int V_LIGHT_LEVEL           = 23  // Uncalibrated light level. 0-100%. Use V_LEVEL for light level in lux.
val int V_VAR1                  = 24  // Custom value
val int V_VAR2                  = 25  // Custom value
val int V_VAR3                  = 26  // Custom value
val int V_VAR4                  = 27  // Custom value
val int V_VAR5                  = 28  // Custom value
val int V_UP                    = 29  // Window covering. Up.
val int V_DOWN                  = 30  // Window covering. Down.
val int V_STOP                  = 31  // Window covering. Stop.
val int V_IR_SEND               = 32  // Send out an IR-command
val int V_IR_RECEIVE            = 33  // This message contains a received IR-command
val int V_FLOW                  = 34  // Flow of water (in meter)
val int V_VOLUME                = 35  // Water volume
val int V_LOCK_STATUS           = 36  // Set or get lock status. 1=Locked, 0=Unlocked
val int V_LEVEL                 = 37  // Used for sending level-value
val int V_VOLTAGE               = 38  // Voltage level
val int V_CURRENT               = 39  // Current level
val int V_RGB                   = 40  // RGB value transmitted as ASCII hex string (I.e "ff0000" for red)
val int V_RGBW                  = 41  // RGBW value transmitted as ASCII hex string (I.e "ff0000ff" for red + full white)
val int V_ID                    = 42  // Optional unique sensor id (e.g. OneWire DS1820b ids)
val int V_UNIT_PREFIX           = 43  // Allows sensors to send in a string representing the unit prefix to be displayed in GUI. This is not parsed by controller! E.g. cm, m, km, inch.
val int V_HVAC_SETPOINT_COOL    = 44  // HVAC cold setpoint
val int V_HVAC_SETPOINT_HEAT    = 45  // HVAC/Heater setpoint
val int V_HVAC_FLOW_MODE        = 46  // Flow mode for HVAC ("Auto", "ContinuousOn", "PeriodicOn")

// SubTypes for MessageType M_INTERNAL //
val int I_BATTERY_LEVEL           = 0   // Use this to report the battery level (in percent 0-100).
val int I_TIME                    = 1   // Sensors can request the current time from the Controller using this message. The time will be reported as the seconds since 1970
val int I_VERSION                 = 2   // Used to request gateway version from controller.
val int I_ID_REQUEST              = 3   // Use this to request a unique node id from the controller.
val int I_ID_RESPONSE             = 4   // Id response back to sensor. Payload contains sensor id.
val int I_INCLUSION_MODE          = 5   // Start/stop inclusion mode of the Controller (1=start, 0=stop).
val int I_CONFIG                  = 6   // Config request from node. Reply with (M)etric or (I)mperal back to sensor.
val int I_FIND_PARENT             = 7   // When a sensor starts up, it broadcast a search request to all neighbor nodes. They reply with a I_FIND_PARENT_RESPONSE.
val int I_FIND_PARENT_RESPONSE    = 8   // Reply message type to I_FIND_PARENT request.
val int I_LOG_MESSAGE             = 9   // Sent by the gateway to the Controller to trace-log a message
val int I_CHILDREN                = 10  // A message that can be used to transfer child sensors (from EEPROM routing table) of a repeating node.
val int I_SKETCH_NAME             = 11  // Optional sketch name that can be used to identify sensor in the Controller GUI
val int I_SKETCH_VERSION          = 12  // Optional sketch version that can be reported to keep track of the version of sensor in the Controller GUI.
val int I_REBOOT                  = 13  // Used by OTA firmware updates. Request for node to reboot.
val int I_GATEWAY_READY           = 14  // Send by gateway to controller when startup is complete.
val int I_REQUEST_SIGNING         = 15  // Used between sensors when initialting signing.
val int I_GET_NONCE               = 16  // Used between sensors when requesting nonce.
val int I_GET_NONCE_RESPONSE      = 17  // Used between sensors for nonce response.

I also have some basic logic working and testing right now.

If anyone could create a real binding of this. This would help a lot! RFXCOM Binding should be a good starting point for this.

1 Like

I have been using these for a while now but with the MQTT gateway talking to openhab. It works great for thinks like temp and humidity.

I struck a problem trying to implement the pulse power meter and it didn’t work because the sensor expects a response from OpenHAB. I gave up for now…

But I did find some information where someone is building a binding for MySensors for Openhab 2 which is cool in that it has auto discovery of the sensors…

The answer from openhab is possible with my hacky approach. I already have bi-directional things working with RGB Lights, Infrared Transmitters and some custom switches.

Right now I am polishing the hacky hacky code for the next few days. :smile:

1 Like

I’m working on a OH2 binding for MySensors.

Please let me know if you have suggestions or found bugs. :smile:

Indeed MySensors is a very powerful library and has a great community. I’m totally addidcted! :wink:

1 Like

Hey TimO yeah that must have been where I say the info about your binding…

Based on your work I’ve ordered the bits to create a new Ethernet Gateway, I see that the “pulse meter” is still on your to-do list so I’ll be keeping an eye on that because that’s my main challenge at the moment.

@TommySharp I’ve discussed this “issue” with Kai here:!topic/openhab2/QbmaSwC59l0

I’m still not sure, what the best way to solve this problem will be.

@TimO I don’t have such a pulse meter but will try to help out in getting a usable logic for this thing.

Could you open a seperate thread for this so we don’t spam the main topic? An issue on your github repository would perfectly fit, i guess.

I think we can solve this pretty easily :blush:

Yeah I’m keen to help out with this binding in any way too! Have signed up to GitHub just in case you start an issue there.

Please find my current, binding-free, working setup attached:

Hey Tommy,

did you solve your problem with the pulse meter?

I am running the MySensors pulse powermeter, maybe I can offer some help?

My setup is: MySensors -> MQTT -> OpenHab 1.8


Hi Max, I haven’t had too much time to spend on it but I would love to get it done…
I haven’t yet upgraded to OpenHAB 1.8, do you think this is necessary?

I don’t think you need to upgrade. If your temperature and humidity sensors are working then the MQTT-connection should be fine. If I remember correctly I also had it running with 1.7.

Could you post your item definitions for the pulse meter and ideally also for one or two sensors?

I don’t have anything setup in openHAB yet… I read that the requesting of the value from OpenHAB by the pulse meter wasn’t supported so I didn’t even try… :frowning:

If you have something working I’d gladly borrow your arduino sketch and config for your openhab items :slight_smile: :slight_smile: :slight_smile:

Sure. I will post the config and sketch I am using.

Just give me a day, because I have to get the relevant files from my computer at home.

See here