Update remote OLED with a mesage using MQTT


(Gregory Garman) #1

I am building a video doorbell which has a small OLED screen on it. There is a ESP8266 12E in the doorbell that is handling the doorbell press and running the OLED. I have several sensors around the house all using MQTT, but this is the first to have an OLED with a message on it. Also, I’m running OH1.

The code that is running on the doorbell is subscribed to homey\frontdoorbell\message, which works great when I use MQTT fx app to publish the message manually, such as the word “Hello”.

My question is, how do I, in openhab, publish a message string? For testing, I have a rule that triggers off the button being pressed and I want that rulle to change the message on the OLED to “Hello”. I have a second rule that will do the same kind of function when the button isn’t being pressed.

Here’s my current sitemap:
Text item=FrontDoorBellTemp label=“Front Door Temperature [%.0fF]” icon=“temperature”
{
Text item=FrontDoorBellTemp
Text item=FrontDoorBellPressure
Text item=FrontDoorBellHumidity
Switch item=FrontDoorBellRestart mappings=[ON=“Restart”]
Switch item=FrontDoorBellButton mappings=[ON=“Pressed”,OFF=“UnPressed”]
Setpoint item=FrontDoorBellTempCal label=“Temperature Calibration [%.0fF]” minValue=-10.0 maxValue=10.0 step=1
Text item=FrontDoorBellDefaultMessage label=“msg [%s]”
Text item=FrontDoorBellButtonMessage
}
items:
Number FrontDoorBellTemp “Air Temperature [%.1fF]” (temperature) //{mqtt="<[pimqtt:homey/2ndfloor/tempbaro/temp:state:default]"}
Number FrontDoorBellPressure “Barometric Pressure[%.0fPa]” (pressure) {mqtt="<[pimqtt:homey/frontdoorbell/tempbaro/pressure:state:default]"}
Number FrontDoorBellHumidity “Humidity [%.0f%%]” (humidity) {mqtt="<[pimqtt:homey/frontdoorbell/tempbaro/hum:state:default]"}
Switch FrontDoorBellRestart “Restart” (test) {mqtt=">[pimqtt:homey/frontdoorbell/settings/cmd:command:*:default]"}
Switch FrontDoorBellButton “Button” {mqtt=">[pimqtt:homey/frontdoorbell/button/state:default]"}
String FrontDoorBellDefaultMessage “Default Message” {mqtt=">[pimqtt:homey/frontdoorbell/defaultmessage/state:default]"}
String FrontDoorBellButtonMessage “Button Press Message” {mqtt=">[pimqtt:homey/frontdoorbell/buttonmessage/state:default]"}

rule:
rule “FrontDoorBellPressMessage”
when
Item FrontDoorBellButton changed from OFF to ON
then

		   	postUpdate(FrontDoorBellButtonMessage,"Test")
end   

Thanks for your help in advance!


(Rich Koshak) #2

Please How to use code fences.

You must use sendCommand if you want the new state to go out through the binding. postUpdate only changes the state internal to OH.

Also, you should use the method, not the Action for sendCommand. This is true for 1.8 as well. https://www.openhab.org/docs/configuration/rules-dsl.html#myitem-sendcommand-new-state-versus-sendcommand-myitem-new-state

Note, 1.8 has been almost three years without an update and there are very few users left who will be able to help with 1.8 problems on this forum. Going forward, without upgrading you will largely be in your own for support. In this case the problem would also have been a problem in OH 2 so it was easy to diagnose.


(Vincent Regaud) #3
String FrontDoorBellButtonMessage “Button Press Message” { mqtt=">[pimqtt:homey/frontdoorbell/buttonmessage/state:command:*default]" }