hello, I have created a rf2mqtt gateway and now I would like to integrate it to my openhab.
I installed the mqtt embedded broker, I tried to do some configuration but it does not work.
I would like to start over simply starting from the MQTT commands sent and received in order to turn on or off a switch.
The messages I receive and transmit to the switch are:
{“Value”: 3461392, “protocol”: 1, “length”: 24, “delay”: 469}
{“Value”: 3461379, “protocol”: 1, “length”: 24, “delay”: 468}
the first turns on, the second goes off.
Depending on the TOPIC the message updates the status on openhab, if published in
home / OpenMQTTGateway / commands / 433toMQTT
or it acts on the switch if published in
home / OpenMQTTGateway / commands / MQTTto433
You can help me, I read the tutorial but honestly it is not very clear to me.
Since you are writing the gateway yourself, you should consider implementing the Homie standard for MQTT. This will let the MQTT2 binding automatically discover your gateway and create your Things.
What wasn’t clear to you? I can help but I’d just recreate the tutorial wasting my time and getting you no closer to understanding.
At a very high level:
Create a MQTT Broker Thing and configure to connect to the broker
Create a Generic MQTT Thing to represent each device
Create a Channel on the MQTT Thing to publish/subscribe to the desired topics
Hi! I succeeded!
Yesterday I finally solved the problem of the RF receiver, now I have a gateway that takes radiofrequency signals and sends them as mqtt messages with a homie format. I created the binding, I created the item, I created a channel, I created a panel in hubpannel with a Dummy widget that reads the value of the channel.
At the moment it writes the value transmitted by the radio frequency on screen.
Now I wonder, do I have to change the gateway code to create more channels, one for each sensor, or can I act through openHAB to do that?
I looked at the map file, I would say to my nose that with that I could say that the signals AAAA01, AAAA02, AAAA03 and AAAA01 are part of the 4-channel remote control called AAAA, that the code BBBB01 is the PIR in the corridor, that the senosre CCCC01 indicates the opening of the door and so on …
Am I on the right track? Can I only act on the configuration of openhab items?
Furthermore, the last value read remains written in the MQTT message in the topic on the broker, and here I believe I have to intervene with a script. I should set the event to change the code in the message and trigger a behavior, such as sending a mail or a telegram or a message of another kind, but I’ll see this after creating the ensemble in openhab.
A more standard approach would be to do this in the gateway. Then each of your sensors would be published to a separate topic (per the Homie standard) and then each sensor will have a separate Channel in OH to represent it.
As a general Rule, I always recommend stuff like this to be implemented in the edge device, not in OH.
But OH can handle this too. But it will require you to write Rules to parse the messages and update Items based on the contents of the message. This almost always requires long switch statements and the requirement of updating Rules every time you add a new device.
That’s because whatever is sending the message has set the retain flag to true. When the retain flag is true, the message stays on the topic and when a client subscribes to the topic, they will receive the last retained message. To change this behavior, you need to change your publisher to set the retain flag to false.
@maddmax1976 I would be interested in having some feedback about your implementation in OpenHAB, could you share your different definitions/configurations?
Thinking about it, I’m not interested in having an object for each sensor, after all the only interest is to have a feedback of which sensor has activated.
Unfortunately, in the old alarm control unit I can not tell if a door, a window has been opened or if movement has been detected.
With the current gateway configuration, I know the code that triggers the alarm.
I left the configuration of the mqtt binding as it was.
With the rules I can have the information that is missing:
rule "Decode Sensor"
When
Item RFGateway_RFSignal changed to 524745 or Item RFGateway_RFSignal changed to 5724096
then
sendBroadcastNotification ("Open Entry Door!")
end
this is just a prototype, and it seems to work.
Once all the alarm isensors are reactivated, I will use a Switch / Case construct (or similar) to specify the broadcast message to send.
Created the OpenMQTTGateway in OpenHAB, resulting in working setup.
I know this because the commands I send from my Light Switch Remote Control to the 433 MHz receiver appear well in the Serial Monitor and matches the OpenHAB MQTT Config Topic
20:09:46.246 -> N: Received json : {"value":13081585,"protocol":1,"length":24,"delay":368}
What I know at this point is: 13081585 is the value for switching on and off the light.
So far so good. What I am struggling at now, is how to get this value from OpenHAB back to the Transmitter.
What I tried so far is as follows:
Created a Generic MQTT item, following this instruction.
When I press this button, I get an expected result in OpenHAB log:
2021-01-24 21:10:27.351 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'Switch1' received command ON
2021-01-24 21:10:27.370 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Switch1' predicted to become ON
2021-01-24 21:10:27.402 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Switch1' changed from OFF to ON
But what I would expect is that the light switches on at that time.
I know this is not hardware related, as I would expect something in my serial monitor which says that the value has been transmitted. The Serial Monitor does not say anything about a transmitted value.
Something like this is what I am looking for in my Serial Monitor, but I don’t see it, what reflects that something in the chain goes wrong…
xx.xx.xx -> N: Sent json : {"value":13081585,"protocol":1,"length":24,"delay":368}