Trainer
(Hannes)
February 9, 2020, 6:10pm
1
Hello,
i try to configure m smart doorbell.
i use a esp8266 with homie an this code:
#include <Homie.h>
#include "FS.h"
int readDelay = 50;
int buttonPressDelay = 3000;
int openingDelay = 3000;
int inputPin = 0; //D3;
const int relayPin = 4; //D1=5,D6=12,D2=4;
int inputValue = 0;
bool opened = false;
int timeOpened = 0;
const int PIN_RELAY = 14; //14
HomieNode doorbellNode("button", "button");
HomieNode openerNode("door", "switch");
HomieNode switchNode("plug", "switch");
//----------Klingel lautlos---------
bool lightOnHandler(HomieRange range, String value) {
if (value == "true") {
digitalWrite(PIN_RELAY, HIGH);
switchNode.setProperty("on").send("true");
} else if (value == "false") {
digitalWrite(PIN_RELAY, LOW);
switchNode.setProperty("on").send("false");
} else {
return false;
}
return true;
}
//--------Tueroffnerrelais
boolean openerHandler(const HomieRange& range, const String& value) {
if(value != "true" && value != "false") return false;
if(value == "true") {
digitalWrite(relayPin, HIGH);
openerNode.setProperty("on").send("true");
Serial.println("Opener started ...");
opened = true;
timeOpened = millis();
}
return true;
}
//--------Klingelsignal
void loopHandler() {
inputValue = digitalRead(inputPin);
digitalWrite(BUILTIN_LED, inputValue);
if(inputValue == 0) {
Serial.println("Doorbell pressed ...");
doorbellNode.setProperty("pressed").send("true");
delay(buttonPressDelay);
doorbellNode.setProperty("pressed").send("false");
}
delay(readDelay);
}
void setup() {
Serial.begin(115200);
Serial.println();
pinMode(inputPin, INPUT_PULLUP);
pinMode(BUILTIN_LED, OUTPUT);
digitalWrite(relayPin, LOW);
pinMode(relayPin, OUTPUT); //Pin connected to relay
pinMode(PIN_RELAY, OUTPUT);
digitalWrite(relayPin, LOW);
digitalWrite(PIN_RELAY, LOW);
Homie_setBrand("doorbell");
Homie_setFirmware("Doorbell", "1.0.0");
switchNode.advertise("on").settable(lightOnHandler);
openerNode.advertise("on").settable(openerHandler);
Homie.setLoopFunction(loopHandler);
Homie.setup();
}
void loop() {
int timeNow = millis();
if(timeOpened > 0 && (timeNow - timeOpened) > 3000) {
Serial.println("Close ...");
Serial.println(timeNow);
Serial.println(timeOpened);
timeOpened = 0;
digitalWrite(relayPin, LOW);
openerNode.setProperty("on").send("false");
Serial.println("Opener finished ...");
}
Homie.loop();
}
But every time i resart openhab oder my ESP8266 the Relais at Pin 4 is shot active high in between the boot sequence.
Do you know how to solve the problem?
H102
(CM6.5 H102)
February 9, 2020, 6:28pm
2
I didn’t look much at the code but have you tried setting rules to load after OH starts via the openhabian-config tool?
Trainer
(Hannes)
February 9, 2020, 6:37pm
3
i use openhab not openhabian, so i don’t thing i have this config option.
after i change on my esp
HomieNode openerNode("doorr", "switch");
everything works fine, but after i add it in my paperui *.item and *.sitemap i got this startup problem
H102
(CM6.5 H102)
February 9, 2020, 6:39pm
4
Is that a typo here on the post “doorr” or is that what you have in the file on esp?
Trainer
(Hannes)
February 9, 2020, 6:43pm
5
this is the id which i use in my mqtt command.
so my mqtt command looks like:
doorbell/c01/doorr/on/set
H102
(CM6.5 H102)
February 9, 2020, 6:53pm
6
You’ve tested and verified that command works? I ask b/c it’s odd that “doorr” is nowhere in the code above.
Trainer
(Hannes)
February 9, 2020, 6:56pm
7
that’s true, because it is only the id which i use for my mqtt command.
you can find the “openerNode” linked name.
i don’t know why, but the other relays doesn’t have any problem
HomieNode switchNode("plug", "switch");
H102
(CM6.5 H102)
February 9, 2020, 7:07pm
8
What are you running OH on and how did you install OH?
Trainer
(Hannes)
February 9, 2020, 7:07pm
9
i use Raspbian on my RPI3.
On Raspbian i have installed OP.
H102
(CM6.5 H102)
February 9, 2020, 7:13pm
10
To install openhabian:
Other Linux Systems (add openHABian just like any other software)
openHABian also supports general Debian/Ubuntu based systems on different platforms. Starting with a fresh installation of your operating system, install git, then clone the openHABian project and finally execute the openHABian configuration tool:
# install git
sudo apt-get update
sudo apt-get install git
# download and link
sudo git clone https://github.com/openhab/openhabian.git /opt/openhabian
sudo ln -s /opt/openhabian/openhabian-setup.sh /usr/local/bin/openhabian-config
# execute
sudo openhabian-config
You’ll see the openHABian configuration menu and can now select all desired actions. The “Manual/Fresh Setup” submenu entry is the right place for you.
The doc’s full description here:
Install and use openhabian-config tool to set rules to run after OH starts. I do not know if that will solve the issue but other suggestion is changing the code in OP so pin 4 does not go high on restart of OH.
Trainer
(Hannes)
February 10, 2020, 6:02pm
11
is there another option, because i thing i got a lot oft problems if i install openhabian over openhab.
i think this should be the same:
rule "On system start"
when
System started
then
val actions = getActions("mqtt","mqtt:mqtt:topic:4635ef43:Tueroffner_new")
actions.publishMQTT("home/c02/doorr/on/set","false")
end
Trainer
(Hannes)
February 10, 2020, 8:24pm
12
My problem was that i thought autoupdate=“false” in my *.item change the status to the old one.
Now i create a rule to change ON status to OFF after pressing the button.
Now everything works without problem