Background: I have an ESP-201 running ESPEasy, and it works great. It is a very good solution. I also looked at MySensors, but did not care for the gateway required - I just thing it is unnecessary for what I need. I have five Oak by Digistump. They are based on ESP8266 but I couldn't immediately work out how to get ESPEasy on to them. I figured it should not be hard to send a temperature reading to Domoticz with simple code.
Hardware:
Board: Oak by Digistump
Sensor: si7021 bought on Aliexpress. The ones I got have a voltage regulator on them to make them 5V tolerant. Not good if batteries required. This can be removed, or you can buy boards without.
Procedure:
Add virtual hardware
To be able to communicate with devices like the ESP, we have to add virtual hardware to Domoticz. This step has to be done only once in your setup.
From the main Domoticz Menu, Select Setup -> Hardware

And add following hardware to you system:

Create a virtual sensor
The new hardware should be in the list and there should be a button "Create Virtual Sensors"

Click the button "Create Virtual Sensors" and choose Sensor Type "Temp+Hum"
From the main Domoticz Menu, Select Setup -> Devices
Note down the IDX number of your virtual sensor - you'll need to add it to the arduino code.
Sending data from arduino/ESP to Domoticz
This uses HTTP GET. Formatting must be correct.
This wiki page has a list of all urls that Domoticz uses.
Temperature/humidity
domoticzIP:PORT/json.htm?type=command¶m=udevice&idx=IDX&nvalue=0&svalue=TEMP;HUM;HUM_STAT
IDX = id of your device (This number can be found in the devices tab in the column "IDX")
TEMP = Temperature
HUM = Humidity
HUM_STAT = Humidity status
HUM_STAT can be one of:
0=Normal
1=Comfortable
2=Dry
3=Wet
Arduino code
Code: Select all
#include <Wire.h>
#include <SparkFun_Si7021_Breakout_Library.h> //https://github.com/sparkfun/Si7021_Breakout/blob/master/Libraries/Arduino/Si7021/src/SparkFun_Si7021_Breakout_Library.h
#include <ESP8266WiFi.h>
//int status = WL_IDLE_STATUS; // the Wifi radio's status
WiFiClient client;
// domoticz
const char * domoticz_server = "192.168.1.10"; //Domoticz port
int port = 8080; //Domoticz port
int idx = 5; //IDX for virtual sensor, found in Setup -> Devices
float humidity = 0;
float temp = 0;
//Create Instance of HTU21D or SI7021 temp and humidity sensor and MPL3115A2 barrometric sensor
Weather sensor;
void setup()
{
//Initialize the I2C sensors and ping them
sensor.begin();
}
void loop()
{
//Get readings from all sensors
getWeather();
printInfo();
delay(60000); // Wait 60 seconds
}
void getWeather()
{
// Measure Relative Humidity from the HTU21D or Si7021
humidity = sensor.getRH();
// Measure Temperature from the HTU21D or Si7021
temp = sensor.getTemp();
// Temperature is measured every time RH is requested.
// It is faster, therefore, to read it from previous RH
// measurement with getTemp() instead with readTemp()
}
void printInfo()
{
// Domoticz format /json.htm?type=command¶m=udevice&idx=IDX&nvalue=0&svalue=TEMP;HUM;HUM_STAT
if (client.connect(domoticz_server,port)) {
client.print("GET /json.htm?type=command¶m=udevice&idx=");
client.print(idx);
client.print("&nvalue=0&svalue=");
client.print(temp);
client.print(";");
client.print(humidity);
client.print(";0"); //Value for HUM_STAT. Can be one of: 0=Normal, 1=Comfortable, 2=Dry, 3=Wet
client.println(" HTTP/1.1");
client.print("Host: ");
client.print(domoticz_server);
client.print(":");
client.println(port);
client.println("User-Agent: Arduino-ethernet");
client.println("Connection: close");
client.println();
client.stop();
}
}