I've been able to get MySensors working with HomeGenie using the MQTT gateway. It doesn't have two-way communication or software-based pairing yet, but I'll work on those in the future.
I have a project going with openhab and thethingbox. I only use Mqtt with a combination of nrf24l01 and esp8266 modules. thethingbox server is simply used as a catch all for all mqtt messages from sensors or openhab. i parse all the message coming into ththingbox and take action depending on the message. If my door or window sensor is tripped a message is sent to Twitter. I also send temp and humidity readings to thingspeak and my cell phone reports long and lat coordinates to thingspeak so that my lights can come on as I approach the house. My next project is to setup ip cameras and motion sensors and sent pics to drop box.
Openhab is really not hard, you just have to keep at it, once you get it you will kick yourself for over complicating it
Mike
Sorry. Hek, I using this code. Vera3 find relay and it works, but also appears 3 door sensors instead of 3 temp sensors.
I try to use the my arduino board only with sd18b20 sketch and it work's and show temperature. Is it sketch suitale for vera?
@Gambituk said:
and here is the modified relay/temp sketch
// Running DS temperature sensor(s) and relay(s) on one mysensor arduino node
// Combines Onewire and Relay code
// 2014-10-14 Pego: Tested and Running on Uno/Clone and MQTT gateway
// Example sketch showing how to send in OneWire temperature readings
// Example sketch showing how to control physical relays.
// This example will remember relay state even after power failure.
#include <MySensor.h>
#include <SPI.h>
#include <DallasTemperature.h>
#include <OneWire.h>presen
#define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected
#define MAX_ATTACHED_DS18B20 16
#define RELAY_1 4 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define NUMBER_OF_RELAYS 2 // Total number of attached relays
#define RELAY_ON 1 // GPIO value to write to turn on attached relay
#define RELAY_OFF 0 // GPIO value to write to turn off attached relay
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) 30000 orig
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
MySensor gw;
float lastTemperature[MAX_ATTACHED_DS18B20];
int numSensors=0;
boolean receivedConfig = false;
boolean metric = true;
// Initialize temperature message
MyMessage msg(0,V_TEMP);
void setup()
{
// Startup OneWire
sensors.begin();
// Startup and initialize MySensors library. Set callback for incoming messages.
//gw.begin();
gw.begin(incomingMessage, AUTO, true);
// Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Temp and Relays", "1.0");
// Fetch the number of attached temperature sensors
numSensors = sensors.getDeviceCount();
// Present all sensors to controller
for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
gw.present(i, V_TEMP);
}
// Fetch relay status
for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
// Register all sensors to gw (they will be created as child devices)
gw.present(sensor, S_LIGHT);
// Then set relay pins in output mode
pinMode(pin, OUTPUT);
// Set relay to last known state (using eeprom storage)
digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
}
}
void loop()
{
// Process incoming messages (like config from server)
gw.process();
// Fetch temperatures from Dallas sensors
sensors.requestTemperatures();
// Read temperatures and send them to controller
for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
// Fetch and round temperature to one decimal
float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
// Only send data if temperature has changed more then 1 degC and no error
if (int(lastTemperature[i]) != int(temperature) && temperature != -127.00) { //added integer
// Send in the new temperature
gw.send(msg.setSensor(i).set(temperature,1));
lastTemperature[i]=temperature;
}
}
//gw.sleep(SLEEP_TIME); //no sleep for relays!!!!
}
void incomingMessage(const MyMessage &message) {
// We only expect one type of message from controller. But we better check anyway.
if (message.type==V_LIGHT) {
// Change relay state
digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
// Store state in eeprom
gw.saveState(message.sensor, message.getBool());
// Write some debug info
Serial.print("Incoming change for sensor:");
Serial.print(message.sensor);
Serial.print(", New status: ");
Serial.println(message.getBool());
}
}
By creating the file org.eclipse.smarthome.mqttbroker.cfg in the service folder (/usr/local/etc/openhab2/services in my case, chown to openhab), with the contents
name=mosquitto
host=192.168.1.69
secure=false
port=1883
username=
password=
retain=true
I was able to just create the MySensors MQTT gateway (using paperui) and it stayed online (no mqtt broker defined, but its addon is installed). I had the impressions that with the latest versions it should be possible to do everything in the PaperUI, and that the broker would use the mqtt2 addon (but in paper ui, service, config, mqtt tab, mqtt system broker connection, manage->plus button -> expert mode, I get to see the contents of the cfg file above)
But unfortunately, it seems that the discovery services enters a endless loop (maybe I need to update my arduinos sketch to the latest mysensors code?) and I don't get any auto discovered things. If I trigger a new discovery it will stop the previous one and start again.
Finally, I was able to manually create a thing, and link items on it. Eventually my battery level and humidity were displayed in the paper ui control page (after some weird delay, not updating once it shows in the log. the temperature didn't show up though).
Not sure if my understanding is off (or paperui is limited in this sense) but in the "thing" creation page I only get to specify one child id. Then my multi sensors/value nodes would need to be define in multiple things? As I can't properly define channels for each child id, and I'm not sure what var1-5 are all about.
I'll try defining things/channels/items directly in files in the following days, because so far I couldn't enjoy most of the benefits of this new version (auto discovery, logical grouping of physical device in "things", questionable "do-it-all in paper ui"), and I'm almost considering using mqtt1 binding in the new install
Although it should not be too difficult to make the MQTT Gateway with WiFi work on hardware and software level it is a bad idea on system level:
WiFi and MySensensor NRF24L01+ use the same 2.4 GHz band and with the antennas close a transmit from one will block the other and vice-versa.