Dooya DT82tv Curtain Motors with Sonoff RF Bridge

Anyone who is using this solution, I have a quick update. I was unable to use the position_template thing that c_wolsey was using to determine position/state and earlier I was looking for a way to retain the states of my door/window sensors when I found this thread.

The thread shows you how to set up automations for simple sensors that don’t have MQTT/Sonoff stored position data. That way, the automations can force retention of the sensor’s state by the MQTT broker. Anyway, I used that model to set up a way to store the state data for the curtain when I send a command from my remote or HA. This is what my automation looks like:

- id: publish_mqtt_from_master_bedroom_curtain_codes
  alias: Publish MQTT From Master Bedroom Curtain Codes
  trigger:
    - platform: mqtt
      topic: 'cmnd/sonoff-bridge/backlog'
  condition:
    - condition: template
      value_template: "{{ trigger.payload in ('rfraw AA B0 35 05 04 12FC 05DC 02D0 0168 1EE6 A481A3A3B2B2B2A3A3A3B2A3A3A3B2B2A3A3A3A3A3A3B2A3B2B2B2B2B2B2B2A3B2A3B2B2B2A3B2B2B2 55;rfraw off', 'rfraw AA B0 35 05 04 12FC 05DC 02D0 0168 1EF0 A481A3A3B2B2B2A3A3A3B2A3A3A3B2B2A3A3A3A3A3A3B2A3B2B2B2B2B2B2B2A3B2A3B2B2A3A3B2B2A3 55;rfraw off', 'rfraw AA B0 35 05 04 12FC 05DC 02C6 0168 1EE6 A481A3A3B2B2B2A3A3A3B2A3A3A3B2B2A3A3A3A3A3A3B2A3B2B2B2B2B2B2B2A3B2A3B2A3B2A3B2A3B2 55;rfraw off') }}"
  action:
    - service: mqtt.publish
      data_template:
        topic: "433/Master_Bedroom_Curtain"
        payload: >-
          {%- if trigger.payload == 'rfraw AA B0 35 05 04 12FC 05DC 02D0 0168 1EE6 A481A3A3B2B2B2A3A3A3B2A3A3A3B2B2A3A3A3A3A3A3B2A3B2B2B2B2B2B2B2A3B2A3B2B2B2A3B2B2B2 55;rfraw off' -%}
            ON
          {%- else -%}
            OFF
          {%- endif -%}
        retain: True

Now I have a state_topic in MQTT called 433/Master_Bedroom_Curtain and if I add to my curtain cover the state_topic, state_open and state_closed like this:

  - platform: mqtt
    device_class: curtain
    name: "Master Bedroom Curtains"
    command_topic: "cmnd/sonoff-bridge/backlog"
    payload_open: "rfraw AA B0 35 05 04 12FC 05DC 02D0 0168 1EE6 A481A3A3B2B2B2A3A3A3B2A3A3A3B2B2A3A3A3A3A3A3B2A3B2B2B2B2B2B2B2A3B2A3B2B2B2A3B2B2B2 55;rfraw off"
    payload_close: "rfraw AA B0 35 05 04 12FC 05DC 02D0 0168 1EF0 A481A3A3B2B2B2A3A3A3B2A3A3A3B2B2A3A3A3A3A3A3B2A3B2B2B2B2B2B2B2A3B2A3B2B2A3A3B2B2A3 55;rfraw off"
    payload_stop: "rfraw AA B0 35 05 04 12FC 05DC 02C6 0168 1EE6 A481A3A3B2B2B2A3A3A3B2A3A3A3B2B2A3A3A3A3A3A3B2A3B2B2B2B2B2B2B2A3B2A3B2A3B2A3B2A3B2 55;rfraw off"
    state_topic: "433/Master_Bedroom_Curtain"
    state_open: "ON"
    state_closed: "OFF"

It will set the state when I click a button. Click ‘open’ and the icon changes to opened, click ‘close’ and the icon changes to closed. Obviously, this isn’t ideal/perfect because there is a delay on the curtain to open/close but it works very well since we don’t have a native position value from the unit. You’ll notice that if I hit the ‘stop’ button it’ll act like the curtain is closed – not sure what to do with that… :slight_smile:

==EDIT==

So I’ve been messing with this thing a little more and I found that I can setup and if, elif, else integrating the stop button and taking advantage of the position_topic instead of the state_topic. It works even better!

configuration.yaml:

cover:
  - platform: mqtt
    device_class: curtain
    name: "Master Bedroom Curtains"
    command_topic: "cmnd/sonoff-bridge/backlog"
    payload_open: "rfraw AA B0 35 05 04 12FC 05DC 02D0 0168 1EE6 A481A3A3B2B2B2A3A3A3B2A3A3A3B2B2A3A3A3A3A3A3B2A3B2B2B2B2B2B2B2A3B2A3B2B2B2A3B2B2B2 55;rfraw off"
    payload_close: "rfraw AA B0 35 05 04 12FC 05DC 02D0 0168 1EF0 A481A3A3B2B2B2A3A3A3B2A3A3A3B2B2A3A3A3A3A3A3B2A3B2B2B2B2B2B2B2A3B2A3B2B2A3A3B2B2A3 55;rfraw off"
    payload_stop: "rfraw AA B0 35 05 04 12FC 05DC 02C6 0168 1EE6 A481A3A3B2B2B2A3A3A3B2A3A3A3B2B2A3A3A3A3A3A3B2A3B2B2B2B2B2B2B2A3B2A3B2A3B2A3B2A3B2 55;rfraw off"
    position_topic: "433/Master_Bedroom_Curtain"

automation.yaml:

automation:
- id: publish_mqtt_from_master_bedroom_curtain_codes
  alias: Publish MQTT From Master Bedroom Curtain Codes
  trigger:
    - platform: mqtt
      topic: 'cmnd/sonoff-bridge/backlog'
  condition:
    - condition: template
      value_template: "{{ trigger.payload in ('rfraw AA B0 35 05 04 12FC 05DC 02D0 0168 1EE6 A481A3A3B2B2B2A3A3A3B2A3A3A3B2B2A3A3A3A3A3A3B2A3B2B2B2B2B2B2B2A3B2A3B2B2B2A3B2B2B2 55;rfraw off', 'rfraw AA B0 35 05 04 12FC 05DC 02D0 0168 1EF0 A481A3A3B2B2B2A3A3A3B2A3A3A3B2B2A3A3A3A3A3A3B2A3B2B2B2B2B2B2B2A3B2A3B2B2A3A3B2B2A3 55;rfraw off', 'rfraw AA B0 35 05 04 12FC 05DC 02C6 0168 1EE6 A481A3A3B2B2B2A3A3A3B2A3A3A3B2B2A3A3A3A3A3A3B2A3B2B2B2B2B2B2B2A3B2A3B2A3B2A3B2A3B2 55;rfraw off') }}"
  action:
    - service: mqtt.publish
      data_template:
        topic: "433/Master_Bedroom_Curtain"
        payload: >-
          {%- if trigger.payload == 'rfraw AA B0 35 05 04 12FC 05DC 02D0 0168 1EE6 A481A3A3B2B2B2A3A3A3B2A3A3A3B2B2A3A3A3A3A3A3B2A3B2B2B2B2B2B2B2A3B2A3B2B2B2A3B2B2B2 55;rfraw off' -%}
            100
          {%- elif trigger.payload == 'rfraw AA B0 35 05 04 12FC 05DC 02D0 0168 1EF0 A481A3A3B2B2B2A3A3A3B2A3A3A3B2B2A3A3A3A3A3A3B2A3B2B2B2B2B2B2B2A3B2A3B2B2A3A3B2B2A3 55;rfraw off' -%}
            0
          {%- else -%}
            50
          {%- endif -%}
        retain: True

Anyway, thought I’d share.
-Greg