Hi Everybody,
I want to share you how I configured an ESP8266 module with firmware 0.1.1 PRO version in OpenHab server.
Purpose:
Create sensore for outside with the following functionality:
Scheme:
Configuration:
Firmware settings:
Main
Sensors
GPIO
Servers
IP-192.168.1.148- My OpenHAB Server
Debug data
To see if your system is receiving data by protocol MQTT from the sensor,
Please run this command on Raspberry pi console:
mosquitto_sub -h localhost -v -t '#'
and you should see the following output:
/esp8266/gpio/input/15 1
/esp8266/gpio/output/15 1
/esp8266/gpio/output/14 1
/esp8266/gpio/output/16 0
/esp8266/sensors/dhtt1 24.5
/esp8266/sensors/dhth1 39.0
/esp8266/sensors/freemem 21928
/esp8266/sensors/uptime 76635
OpenHab My Home interface
OpenHab installation
I'm using OpenHab installed on RaspBerry PI with
MQTT support
I'm not going to explain how to install OpenHab server
I'm sure that anybody can find a good documentation in Internet -
OpenHab Installation
OpenHab Configuration
- Edit file openhab.cfg
You can find this file in directory /etc/openhab/configurations/openhab.cfg
In Transport configurations section add the followingmqtt:mymosquitto.url=tcp://localhost:1883
mqtt:mymosquitto.qos=0
mqtt:mymosquitto.retain=true
mqtt:mymosquitto.async=true
- Create file myhome.item in /etc/openhab/configuration/items/
Group All
Group WH (All)
Group Uber "" (All)
Group gGF (All)
Group gFF (All)
Group gC (All)
Group gVR (All)
Group Shutters (All)
Group Weather (All)
Group Status (All)
Group Hardware "" <network> (All)
Group all
Rollershutter Roof_Switch "Verandah Roof [(%d)]" <rollershutter>
Switch ESP8266_Status "ESP8266 Module Helth" (Hardware) { nh="192.168.1.149" }
DateTime Date "Date [%1$tA, %1$td.%1$tm.%1$tY]" <calendar> { ntp="Asia/Jerusalem:ru_RU" }
Switch esp_relay_up "Roof_UP" (all,gVR) { mqtt=">[mymosquitto:/esp8266/gpio/output/15:command:ON:0],>[mymosquitto:/esp8266/gpio/output/15:command:OFF:1],<[mymosquitto:/esp8266/gpio/output/15:state:default]" }
Switch esp_relay_down "Roof_Relay_DOWN" (all,gVR) { mqtt=">[mymosquitto:/esp8266/gpio/output/14:command:ON:0],>[mymosquitto:/esp8266/gpio/output/14:command:OFF:1],<[mymosquitto:/esp8266/gpio/output/14:state:default]" }
Switch esp_Rain "Rain status [%s]" (all,gVR) { mqtt="<[mymosquitto:/esp8266/gpio/input/0:state:MAP(0on1off.map)]" }
Number esp_temp "Temp [%.1f °C]" (all,gVR) { mqtt="<[mymosquitto:/esp8266/sensors/dhtt1:state:default]" }
Number esp_humid "Humid [%.1f %%]" (all,gVR) { mqtt="<[mymosquitto:/esp8266/sensors/dhth1:state:default]" }
- Create file myhome.sitemap in /etc/openhab/configuration/sitemaps/
sitemap myhome label="My Home"
{
Frame label="Rooms" {
Group item=gVR label="Verandah" icon="terrace" {
Text item=esp_Rain label="Rain Status [%s]" icon="light"
Text item=esp_temp label="Temp. [%s]" icon="temperature"
Text item=esp_humid label="Humid. [%s]" icon="climate"
Switch item=Roof_Switch label="Roof"
}
}
Frame label="Date" {
Text item=Date
}
Frame label="Devices" {
Group item=Hardware label="Status" icon="heating" {
Switch item=ESP8266_Status
}
}
}
- Create file myhome.rules in /etc/openhab/configuration/rules/
I created three rules:
1. Open roof from the button.
2. Close roof from the button.
3 When sensor is detecting a rain, the system automatically close a roof.
Each rule working with timer, if you open, close a roof from the button or by rain sensor , the system is waiting one minute and then stop both relay.import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.openhab.core.library.types.*
var Timer timer=null
var Timer2 timer2=null
var Timer3 timer3=null
var Timer4 timer4=null
rule "Roof Stop"
when
Item Roof_Switch received command STOP
then
sendCommand(esp_relay_up, OFF)
sendCommand(esp_relay_down, OFF)
end
rule "Roof UP"
when
Item Roof_Switch received command UP
then
sendCommand(esp_relay_down, OFF)
sendCommand(esp_relay_up, ON)
timer = createTimer(now.plusMinutes(1)) [|
sendCommand(esp_relay_up, OFF)
]
end
rule "Roof DOWN"
when
Item Roof_Switch received command DOWN
then
sendCommand(esp_relay_up, OFF)
sendCommand(esp_relay_down, ON)
timer2 = createTimer(now.plusMinutes(1)) [|
sendCommand(esp_relay_down, OFF)
]
end
rule "Rain"
when
Item esp_Rain received update ON
then
sendCommand(esp_relay_down, ON)
timer3 = createTimer(now.plusMinutes(1)) [|
sendCommand(esp_relay_down, OFF)
]
end