Sonoff Dual Window Cover with set position

I did some changes and fixed some things based on the comments above. I am using the recorder to save the changes of input_number and removed the initial from the window_position.
There is also the fix on automations 411_1 and 412_1 sugested by @foraster.
Also I added underscore 1 on each element in order to make it easier to add multiple covers by replacing the _1.

configuration.yaml

recorder:

timer:
  window_up_1:
    duration: '00:00:18'
  window_down_1:
    duration: '00:00:18'

input_number:
  window_position_1:
    name: "Window 1 Position"
    min: 0
    max: 18
  window_set_position_1:
    name: "Window 1 Set Position"
    min: 0
    max: 100 

cover:
  - platform: template
    covers:
      window_cover_1:
        friendly_name: "Window 1 Cover"
        position_template: "{{ (((states.input_number.window_position_1.state | int) * 100)/18 | int) }}"
        open_cover:
          - service: mqtt.publish
            data:
              topic: 'cmnd/sonoff_1/power2'
              payload: 'OFF'
          - service: mqtt.publish
            data:
              topic: 'cmnd/sonoff_1/power1'
              payload: 'ON'
        close_cover:
          - service: mqtt.publish
            data:
              topic: 'cmnd/sonoff_1/power1'
              payload: 'OFF'
          - service: mqtt.publish
            data:
              topic: 'cmnd/sonoff_1/power2'
              payload: 'ON'
        stop_cover:
          - service: mqtt.publish
            data:
              topic: 'cmnd/sonoff_1/power1'
              payload: 'OFF'
          - service: mqtt.publish
            data:
              topic: 'cmnd/sonoff_1/power2'
              payload: 'OFF' 

automations.yaml

- id: '301_1'
  alias: Window 1 - MQTT Button1 OFF (up)
  trigger:
  - payload: 'OFF'
    platform: mqtt
    topic: stat/sonoff_1/POWER1
  action:
  - service: timer.cancel
    entity_id: timer.window_up_1

- id: '302_1'
  alias: Window 1 - MQTT Button2 OFF (down)
  trigger:
  - payload: 'OFF'
    platform: mqtt
    topic: stat/sonoff_1/POWER2
  action:
  - service: timer.cancel
    entity_id: timer.window_down_1

- id: '303_1'
  alias: Window 1 - Timer stopped
  trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.window_up_1
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.window_down_1
  action:
  - service: cover.stop_cover
    data:
      entity_id: cover.window_cover_1

- id: '311_1'
  alias: Window 1 - MQTT Button1 ON (up)
  trigger:
  - payload: 'ON'
    platform: mqtt
    topic: stat/sonoff_1/POWER1
  condition:
    condition: template
    value_template: '{{ as_timestamp(now()) - as_timestamp(states.input_number.window_set_position_1.last_updated) > 3 }}'
  action:
  - service: timer.start
    data:
      duration: 00:00:18
    entity_id: timer.window_up_1

- id: '312_1'
  alias: Window 1 - MQTT Button2 ON (down)
  trigger:
  - payload: 'ON'
    platform: mqtt
    topic: stat/sonoff_1/POWER2
  condition:
    condition: template
    value_template: '{{ as_timestamp(now()) - as_timestamp(states.input_number.window_set_position_1.last_updated) > 3 }}'
  action:
  - service: timer.start
    data:
      duration: 00:00:18
    entity_id: timer.window_down_1

- id: '411_1'
  alias: Window 1 - Position UP
  trigger:
    platform: time
    seconds: '/1'
  condition:
    condition: state
    entity_id: 'timer.window_up_1'
    state: 'active'
  action:
  - service: input_number.set_value
    data_template:
      entity_id: input_number.window_position_1
      value: "{% if (states.input_number.window_position_1.state | int) < 18 %}\n  {{\
        \ (states.input_number.window_position_1.state | int) + 1 }}\n{% else %}\n \
        \ 18\n{% endif %}"

- id: '412_1'
  alias: Window 1 - Position Down
  trigger:
    platform: time
    seconds: '/1'
  condition:
    condition: state
    entity_id: 'timer.window_down_1'
    state: 'active'
  action:
  - service: input_number.set_value
    data_template:
      entity_id: input_number.window_position_1
      value: "{% if (states.input_number.window_position_1.state | int) > 1 %}\n  {{\
        \ (states.input_number.window_position_1.state | int) - 1 }}\n{% else %}\n \
        \ 0\n{% endif %}"

- id: '511_1'
  alias: Window 1 - Set Position Down
  trigger:
    platform: state
    entity_id: input_number.window_set_position_1
  condition:
    condition: template
    value_template: "{{ (states.input_number.window_position_1.state | int) > ((((states.input_number.window_set_position_1.state | int ) * 18 )/100) | int) }}"
  action:
  - service: timer.start
    data_template:
      entity_id: timer.window_down_1
      duration: "{{ '00:00:%02d' | format( ((states.input_number.window_position_1.state | int) - ((((states.input_number.window_set_position_1.state | int ) * 18 )/100) | int) ) | abs ) }}"
  - service: cover.close_cover
    data:
      entity_id: cover.window_cover_1

- id: '512_1'
  alias: Window 1 - Set Position UP
  trigger:
    platform: state
    entity_id: input_number.window_set_position_1
  condition:
    condition: template
    value_template: "{{ (states.input_number.window_position_1.state | int) < ((((states.input_number.window_set_position_1.state | int ) * 18 )/100) | int) }}"
  action:
  - service: timer.start
    data_template:
      entity_id: timer.window_up_1
      duration: "{{ '00:00:%02d' | format( ((states.input_number.window_position_1.state | int) - ((((states.input_number.window_set_position_1.state | int ) * 18 )/100) | int) ) | abs ) }}"
  - service: cover.open_cover
    data:
      entity_id: cover.window_cover_1

groups.yaml

window_cover_1:
  name: Window Cover 1
  entities:
  - cover.window_cover_1
  - input_number.window_set_position_1
  - input_number.window_position_1
  - timer.window_up_1
  - timer.window_down_1
2 Likes

You could use the same wires, but I wouldn’t recommend it because you would not have feedback on Home Assistant.
The best way is to use the GPIO pins as the diagram I have attached here.

1 Like

You can bridge the wires direct to the motor directly to the switches. But it does not make sense then to configure the gpios.

It makes more sense to connect the physical switches to the gpios since it also simplifies the wiring.

But in my opinion, it works the same in one way as in another. That if once you go through the gpio you could program that the pulsation would be of xx seconds for a single touch to raise or lower it completely. Thing that the engine could not directly. In my case I have them without seconds since for me the buttons is to go up a bit or go down a bit.

1 Like

Feedback regarding cover position right?

Hello Everyone ! :smiley:

Like you will see here, I’m new at the HomeAssistant community :stuck_out_tongue: So I will need some help !!!

Here is my problem:

I use 2 RF remotes to control my blackout’s (bedroom and living room). I have a Broadlink RMPro, and I already have the RF codes !!

RF Codes I Have:
Living Room

  • Open
  • Pause
  • Close

Bed Room

  • Open
  • Pause
  • Close

Every time I want to change the position with the remote, I have to press Open and then Pause . Unless I want to fully close/open (In that case I don’t need to press Pause)

Here is what I wanted to do:

I wanted to have something like this x2 (living room, bedroom)

And I would like them to work this way …

  • I could choose the percentage I want (from 0 to 100%) (my blinds take 50 seconds to open and 49 seconds to close)
  • Every time I changed the position, I wanted them to RESET, by this I mean:
    - Send Close RF CODE to close, WAIT 55 Seconds, and then SEND open button to open the desired position.

why reset?

  • I need them to RESET because sometimes I use my physical remote control, and sometimes I use my HA/Homekit. :slight_smile:

The question is : Is this possible?

I’m new here and this was probably the nearest solution that I found compared to what I want ! The problem is that I don’t know how to “code”… Honestly I have no idea how to code :cry:

Can someone help me in this code please??

I can buy you a beer ! :beer:

Hi

It is a simple, although tedious and lengthy, matter of replicating all the code for each shutter.

It’s tedious because you have to edit the code to make it specific for each cover, eg entity_id, timer duration, MQTT commands, etc.

I would make sure that I have one shutter working as needed before duplicating code.

Here is some of my code:

Hope this helps.

Thank you!!!

Shouldn’t it be ‘data’ instead of ‘date’?

Hi, I’m trying to create a folder for the timer file and input_number.
-timer:! include_dir_merge_list timer /
-input_number:! include_dir_merge_list input_number /
But the config does not perplex me
She work only with single file:
timer: !include timers.yaml
input_number: !include input_numbers.yaml

Is there a way to create folders for the timer and input_number files?
Is Possible?
Thank’s

Create a folder in the CONFIG folder where configuration.yaml is e.g. timers

In this folder put the all the yaml files for that component (timers )

In configuration. yaml put

timer: !include_dir_merge_list mytimerfolder/

Also, check this out:

It’s a long read but all the info is there.

Hi

I have the same issue as j1gg3.

Shutters stay in ‘Opening’ position in Homekt. Siri responds normally but shutters do not operate.

I have everything structured in different files as pierre explained, how should I include recorder?

On the other hand is not the union of position / set position in the same bar possible?

Thanks for your work

I am using this with my sunshade and it works great but I would like to have:

status “close” --> sunshade is rolled up
status “open” --> sunshade is rolled down

Is it possibile ?

I noticed this when my daughter told to Google Home : “Hey google, close all” … light went off but the sunshade went down!! :smile:

Hi all,

I’ve tried several times to set up the window cover (with or without the recorder).

Maybe my setup is strange but when I push open it closes and viceversa.

Here’s my dual config:

image

I’ve tried to modify the automation, ok for the cover button. But I can’t succeed to fix also the other automations. Can someone please support me?

Thank you in advance

Perhaps you could try swapping the wires coming out of the Sonoff marked out1 & out2.

Yeah. At the end I tried all available combinations and reached out the right setting.

Now I have a new question for you all: I can use Google Assistant to Open-Close the cover (using commands “switch on”-“switch off”.

Anyone knows if it is possible also to set position using voice?

Thank you in advance!

I’m using Sonoff T1 two gang with following Tasmota fork - https://github.com/stefanbode/Sonoff-Tasmota/wiki/Shutter-blinds-working-with-two-relays

It allows me to control my covers with position. I’ve added my covers to Google home with Home-assistant cloud. They appears in GH as lights. I can say open cover and set cover to xx%. GH response with turning on cover and setting brightness to xx%.

Hello good afternoon,
Why do they use the TASMOTA software and do not use the ESPURNA software for the blinds?
ESPURNA has a synchronization mode that allows having only one relay on at the same time

I’m a fork from Tasmota. This fork supports shutter position. Original Tasmota and Espurna do not support this option.

Hello, everything worked first, now the timer up or down is increased only with the slider ‘Set Position’ and not with the up or down arrows. The configuration has not been changed. Has this happened to anyone else?