So I finally changed the splitter connector to USB micro and it is a bit more polished now
I also connected it to openHab2 via MQTT binding. So in case any one is interested here is the configuration for the thing and items.
Bridge mqtt:broker:openhab [ host="localhost" ] {
Thing topic mag "Magnety" {
Channels:
Type contact : pin17 [ stateTopic="mag-out/0/17/1/0/16", on="1", off="0"]
Type contact : pin16 [ stateTopic="mag-out/0/16/1/0/16", on="1", off="0"]
Type contact : pin15 [ stateTopic="mag-out/0/15/1/0/16", on="1", off="0"]
Type contact : pin14 [ stateTopic="mag-out/0/14/1/0/16", on="1", off="0"]
Type contact : pin1 [ stateTopic="mag-out/0/1/1/0/16", on="1", off="0"]
Type contact : pin0 [ stateTopic="mag-out/0/0/1/0/16", on="1", off="0"]
Type contact : pin2 [ stateTopic="mag-out/0/2/1/0/16", on="1", off="0"]
Type contact : pin3 [ stateTopic="mag-out/0/3/1/0/16", on="1", off="0"]
Type contact : pin4 [ stateTopic="mag-out/0/4/1/0/16", on="1", off="0"]
Type contact : pin5 [ stateTopic="mag-out/0/5/1/0/16", on="1", off="0"]
Type contact : pin6 [ stateTopic="mag-out/0/6/1/0/16", on="1", off="0"]
Type contact : pin7 [ stateTopic="mag-out/0/7/1/0/16", on="1", off="0"]
Type contact : pin8 [ stateTopic="mag-out/0/8/1/0/16", on="1", off="0"]
Type contact : pin9 [ stateTopic="mag-out/0/9/1/0/16", on="1", off="0"]
Type contact : pin19 [ stateTopic="mag-out/0/19/1/0/16", on="1", off="0"]
Type contact : pin18 [ stateTopic="mag-out/0/18/1/0/16", on="1", off="0"]
}
}
Contact mag17 "Magnet 17" <window> { channel="mqtt:topic:openhab:mag:pin17" }
Contact mag16 "Magnet 16" <window> { channel="mqtt:topic:openhab:mag:pin16" }
Contact mag15 "Magnet 15" <window> { channel="mqtt:topic:openhab:mag:pin15" }
Contact mag14 "Magnet 14" <window> { channel="mqtt:topic:openhab:mag:pin14" }
Contact mag1 "Magnet 1" <window> { channel="mqtt:topic:openhab:mag:pin1" }
Contact mag0 "Magnet 0" <window> { channel="mqtt:topic:openhab:mag:pin0" }
Contact mag2 "Magnet 2" <window> { channel="mqtt:topic:openhab:mag:pin2" }
Contact mag3 "Magnet 3" <window> { channel="mqtt:topic:openhab:mag:pin3" }
Contact mag4 "Magnet 4" <window> { channel="mqtt:topic:openhab:mag:pin4" }
Contact mag5 "Magnet 5" <window> { channel="mqtt:topic:openhab:mag:pin5" }
Contact mag6 "Magnet 6" <window> { channel="mqtt:topic:openhab:mag:pin6" }
Contact mag7 "Magnet 7" <window> { channel="mqtt:topic:openhab:mag:pin7" }
Contact mag8 "Magnet 8" <window> { channel="mqtt:topic:openhab:mag:pin8" }
Contact mag9 "Magnet 9" <window> { channel="mqtt:topic:openhab:mag:pin9" }
Contact mag19 "Magnet 19" <window> { channel="mqtt:topic:openhab:mag:pin19" }
Contact mag18 "Magnet 18" <window> { channel="mqtt:topic:openhab:mag:pin18" }
Quick preview in openHab2 PaperUI
I would also like to share the arduino code as I have some question.
#include <Ethernet.h>
#include <MySensors.h>
#define SKETCH_NAME "Magnety"
#define SKETCH_MAJOR_VER "1"
#define SKETCH_MINOR_VER "0"
byte pins[] = { 17, 16, 15, 14, 1, 0, 2, 3, 4, 5, 6, 7, 8, 9, 19, 18 };
int sentValues[16] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
MyMessage messages[16] = {
MyMessage( 17, V_TRIPPED )
,MyMessage( 16, V_TRIPPED )
,MyMessage( 15, V_TRIPPED )
,MyMessage( 14, V_TRIPPED )
,MyMessage( 1, V_TRIPPED )
,MyMessage( 0, V_TRIPPED )
,MyMessage( 2, V_TRIPPED )
,MyMessage( 3, V_TRIPPED )
,MyMessage( 4, V_TRIPPED )
,MyMessage( 5, V_TRIPPED )
,MyMessage( 6, V_TRIPPED )
,MyMessage( 7, V_TRIPPED )
,MyMessage( 8, V_TRIPPED )
,MyMessage( 9, V_TRIPPED )
,MyMessage( 19, V_TRIPPED )
,MyMessage( 18, V_TRIPPED )
};
void setup()
{
byte pinsCount = sizeof( pins ) / sizeof( pins[0] );
for( byte i = 0; i < pinsCount; i++ )
{
pinMode( pins[i], INPUT );
}
}
void presentation()
{
// Send the sketch version information to the gateway and Controller
sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER "." SKETCH_MINOR_VER);
byte pinsCount = sizeof( pins ) / sizeof( pins[0] );
for( byte i = 0; i < pinsCount; i++ )
{
//This seems not to be usefull with openhab mqtt bindings
//present( pins[i], S_DOOR );
//But this seems to be more uefull when controller is started after gateway
send( messages[i].set( sentValues[i] ) );
}
}
void loop()
{
int value;
// Short delay to allow buttons to properly settle
sleep(5);
byte pinsCount = sizeof( pins ) / sizeof( pins[0] );
for( byte i = 0; i < pinsCount; i++ )
{
value = digitalRead( pins[i] );
if ( value != sentValues[i] ) {
// Value has changed from last transmission, send the updated value
send( messages[i].set( value==HIGH ? 1 : 0 ) );
sentValues[i] = value;
}
}
}
I noticed the gateway sends the presentation of sensors all the time but that is not of much use in my setup. On the other hand it is useful to send the actual state periodically as it is known without remembering or if the controller started later than GW. But I have a feeling that I might misused the presentation function. Does any one know if this approach is ok by the "mysensors way"?
Of course I welcome any suggestion for improvments
Thanks