Mazzen
(Matthias)
September 3, 2019, 2:48pm
1
Hi! I am new to MQTT and I setup my stuff in Openhab 2.4 all by files, without PaperUI.
What I have done is:
myMQTT.things:
Bridge mqtt:broker:myLocalBroker "MQTT Openhabbridge"
[
host="localhost",
secure=false
]
{
Thing topic GenericMQTTtopic{
Channels:
Type switch : Test_Switch_MQTT "Test Switch MQTT Channel" [ stateTopic="testswitch/state", commandTopic="testswitch/command", on="ON", off="OFF" ]
}
}
mySwitch.items:
Switch TestSwitchMQTT "Test switch mqtt switch" {channel="mqtt:topic:myLocalBroker:GenericMQTTtopic:Test_Switch_MQTT"}
My understanding was hat I can publish a message for example from my Ubuntu now like:
mosquitto_pub -h 192.168.1.2 -t testswitch/command -m “ON”
But the switch doesnt change the status. I am sure my Broker is running correctly, because I am publishing my temperatures in a rule wich works fine. Also my PaperUI shows that the Broker is online an the channel is linked.
I am running a Ubuntu 18 with Mosquitto, on this machine is also running my openHAB.
I am sure its a newbi failure, but I would apreciate if someone can help me
vzorglub
(Vincent Regaud)
September 3, 2019, 3:57pm
2
When you action the switch, in an UI for example, the command topic will be used to send the payload.
To change the state of the swith with an mqtt message from outside openHAB, use the state topic
Mazzen
(Matthias)
September 3, 2019, 4:13pm
3
Thank you very much for your answer.
mosquitto_pub -h 192.168.1.2 -t testswitch/state -m "ON"
doesnt work
vzorglub
(Vincent Regaud)
September 3, 2019, 4:22pm
4
Set up a subscriber to check that the message is sent
Mazzen
(Matthias)
September 3, 2019, 4:32pm
5
I get a response:
The subscriber is my local running mosquitto
*the temp was published by a rule from openHAB
vzorglub
(Vincent Regaud)
September 3, 2019, 6:47pm
6
Can you post the item publishing the temperature, please
Mazzen
(Matthias)
September 3, 2019, 11:16pm
7
thermo.items
Number:Temperature WandthermostatWohnzimmer2ACTUALTEMPERATURE "Actual temperature" {channel="homematic:HM-TC-IT-WM-W-EU:OEQ1009821:OEQ1569091:2#ACTUAL_TEMPERATURE"}
sendMQTT.rules
rule "sendthermo"
when Time cron "0 0/1 * * * ?" //cron every minute
then
var Number tempTemperature = (WandthermostatWohnzimmer2ACTUALTEMPERATURE.state as QuantityType<Number>).doubleValue
val actions = getActions("mqtt","mqtt:broker:myLocalBroker")
actions.publishMQTT("temp/wt1", tempTemperature.toString)
end
opus
(JĂĽrgen Baginski)
September 4, 2019, 4:20am
8
What kind of switch is this? Can you manualy switch it and check what messages (state?) are send by subscribing to all messages ( with #)?
1 Like
Mazzen
(Matthias)
September 4, 2019, 11:17am
9
Hi,
when I subscribe # in my python script and manually switch in Paper UI I recieve this messages:
So it seems that the channel works, but I am doing just something wrong with publishing?
rossko57
(Rossko57)
September 4, 2019, 11:32am
10
Try making another new String type channel without the on/off stuff, link it to a new test String type Item, to capture the raw payload.
1 Like
Mazzen
(Matthias)
September 6, 2019, 9:58am
11
Hi rossko57,
I had no idea to try that, because it was a example but your suggestion solved my problem! Thank you very much.
rossko57
(Rossko57)
September 6, 2019, 10:07am
12
It’s just a diagnostic move to see what OH is actually “seeing”. Did you get your Switch working?