Sonoff RFBridge with rflink32 and MQTT:
It took me quite some time to get the Mosquitto broker for Home Assistant up and running with my
Sonoff RFBridge v2.2 and even more effort to get my NewKaku devices and Eurodomest door sensor
working over MQTT.
Using normal “rflink:” Kaku worked in Home Assistant, but the documentation for MQTT with
RFLink is very scarse and it took me days to find out how it all works, so I decided to
post this small note here.
First problem: the MQTT “topics” for the RFBridge and rflink32 are very basic and cannot
be modified as far as I could figure out:
command_topic: /ESP00/cmd
state_topic: /ESP00/msg
Also, the RFBridge doesn’t seem to produce any Json output, but only very compact
instructions and messages, so I had to parse the messages myself (using Jinja2).
Commands (send to cmd_topic) always start with “10”.
Example: to turn a (New) Klik Aan Klik Uit switch on and off using Mosquitto and
RFBridge you can use this as payload:
10;NewKaku;ID=01c0xxxx;SWITCH=2;CMD=ON;
10;NewKaku;ID=01c0xxxx;SWITCH=2;CMD=OFF;
On the other hand: messages always start with “20”. If you enable (“Start listening”) in
Mosquitto configure you could see the detected signals being printed:
Example for the Eurodomest door switch (that only shows a single message if the door is
opened or closed):
20;0A;Eurodomest;ID=0daaxx;SWITCH=07;CMD=ALLOFF;
And if you use the Kaku remote control for the same switch as above you should this as
message on your Mosquitto broker:
20;0B;NewKaku;ID=01c0xxxx;SWITCH=2;CMD=OFF;
To configure these things in Home Assistant with MQTT I used this in configuration.yaml
(or mqtt.yaml) after searching and trying for hours and hours:
mqtt: !include mqtt.yaml
# mqtt.yaml:
- switch:
- unique_id: newkaku_002xxxx_0
name: kaku_timer_0
command_topic: /ESP00/cmd
payload_on: '10;newkaku;002xxxx;0;on;'
payload_off: '10;newkaku;002xxxx;0;off;'
- switch:
- unique_id: newkaku_002xxxx_1
name: kaku_timer_1
command_topic: /ESP00/cmd
payload_on: '10;newkaku;002xxxx;1;on;'
payload_off: '10;newkaku;002xxxx;1;off;'
# And for the door sensor I used this (under the same mqtt: block):
- binary_sensor:
- unique_id: eurodomest_0daaxx_7_mqtt
name: doorsensor_1_mqtt
state_topic: /ESP00/msg
device_class: door
off_delay: 300
force_update: true
payload_on: "ON"
payload_off: "OFF"
value_template: >
{% if value[6:36] == "Eurodomest;ID=0daaxx;SWITCH=07" %}
{% if is_state(entity_id, "ON") %}
{{ "OFF" }}
{% else %}
{{ "ON" }}
{% endif %}
{% endif %}
Because the door sensor only gives a single message I turned the binary switch into a
toggle by using the code above. Also, to make sure I respond to the correct message I
had to skip the counter after “20;” and so I decided to simply use the substring from
position 6 to position 36, which contains the name, the ID and the SWITCH.
Also the initial state is undefined, but that is not a real problem: as soon as you open
the door once the state is set to “ON” (Open).
Furthermore I used a timer to switch the sensor back to “OFF” (Closed) after 300 seconds.
Hope this helps someone else as well and if anyone has any tips for improvement: I’d be
happy to hear them!
Casey Lemmens