Sonoff Dual Window Cover with set position

Thanks, but how does the “recorder:” feature work specifically?

It stores the current values of window position to the Db and they are restored after a reboot.
If you want more info check the official thread Here

Perfect. Thank you. So just write recorder:
without adding anything else. It will update the home-assistant_v2-db file. Correct?

It doesn’t need anything more. This way it will write on the DB file, though you do have the option to write on a different DB if you configure it.

In other news, I found a really useful feature of Home Assistant, it’s called Packages.
Because of all these lines and different components of the configuration you could end up having a really large configuration file. With the Packages you could add them to a different file.

If anyone is interested check the official doc here.
I’ve also updated the first thread with this tip.

1 Like

I copy all the code but nothing is working for me. It doesn’t show errors. I think that it isn’t even communicating with the sonoff by mqtt. I putted window_1 as the sonoff topic. I have connected the sonoff with home assistant with discovery in configuration ( with setoption19 in the sonoff, and interlock) and I can control it as 2 normal switches in HA. What should I do??

EDIT: It’s working now, I changed the cover (I have the sonoff mqtt integrated by configuration integration).

I was really unhappy with HomeAssistant not having time-based value-changing timers – this kind of timer would fit perfectly here.

What was the assumptions:
a) find out MIN value,
b) find out MAX value,
c) find time DURATION that takes between MIN and MAX,
d) store current value STATE between MIN and MAX based on what time passed in down-counting and up-counting.

I ended up with my own time-counter custom component that simplifies “Dual switch window cover with set position” to three automations.

EDIT:

I’m removing source code from here to keep it up-to-date under this topic:

1 Like

That looks interesting.

Have you tried with multiple covers (I have 11 shutters ie 99 automations)?

I’m giving it a go.

Will let you know how it goes.

It works partially.

First of all I get the following errors:

Error while executing automation automation.back_bedroom_shutter_time_counter_stopped. Invalid data for call_service at pos 1: not a valid value for dictionary value @ data[‘entity_id’]
11:12 AM helpers/script.py (ERROR) - message first occured at 11:05 AM and shows up 19 times

Unable to remove unknown listener <function async_track_point_in_utc_time..point_in_time_listener at 0x6ebe78a0>
11:12 AM core.py (WARNING)

The Up/Down arrows and stop button work as expected.

When using the arrows/stop buttons the position updates when the cover stops not in real time (I can live with that)

Moving the slider (eg 100 -> 90) sets the cover in motion but it (the cover) does not stop at the set position (90) but keeps going. The slider updates to 90. The time_counter is running as expected.

Perhaps if we determine the cause of the errors it may solve the issue.

Hi, thanks for your feedback!

Invalid data for call_service at pos 1: not a valid value for dictionary value @ data[‘entity_id’]

First error looks like you have a typo or disallowed characters in entity_id.

Unable to remove unknown listener <function async_track_point_in_utc_time…point_in_time_listener at 0x6ebe78a0>

I was also seeing this from time to time, but it’s probably caused by first error.

Please review the config for a single cover – you can paste it here for some debug. :slight_smile:

I’m using it with 3 covers.

In configuration.yaml I have:

   time_counter:
      back_bedroom_shutter:
        name: "Back Bedroom Shutter position counter"
        duration: 16 
        min: 0 
        max: 100
        debounce: 1000

The cover definition is:

- platform: template
  covers:
    back_bedroom_shutter:
      friendly_name: "Back Bedroom Shutter"
      position_template: "{{ (states.time_counter.back_bedroom_shutter.state | int) }}"
      close_cover:
        - service: mqtt.publish
          data:
            topic: 'cmnd/sonoff11/power2'
            payload: 'ON'
      open_cover:
        - service: mqtt.publish
          data:
            topic: 'cmnd/sonoff11/power1'
            payload: 'ON'
      stop_cover:
        - service: mqtt.publish
          data:
            topic: 'cmnd/sonoff11/power1'
            payload: 'OFF'
        - service: mqtt.publish
          data:
            topic: 'cmnd/sonoff11/power2'
            payload: 'OFF'
      set_cover_position:
        - service: time_counter.set
          entity_id: time_counter.back_bedroom_shutter
          data_template:
            state: '{{ position }}'
        - service_template: >
            {% if position > states.cover.back_bedroom_shutter.attributes.current_position | int %}
              cover.open_cover
            {% elif position < states.cover.back_bedroom_shutter.attributes.current_position | int %}
              cover.close_cover
            {% endif %}
          entity_id: cover.back_bedroom_shutter

And the automations are:

- alias: Back Bedroom Shutter - started
  trigger:
    - platform: mqtt
      topic: 'stat/sonoff11/+'
      payload: 'ON'
  action:
    - service_template: >
        {% if trigger.topic.split('/')[-1] == 'POWER2' %}
          time_counter.downcount
        {% elif trigger.topic.split('/')[-1] == 'POWER1' %}
          time_counter.upcount
        {% endif %}
      entity_id: time_counter.back_bedroom_shutter

    - alias: Back Bedroom Shutter - stopped
      trigger:
        - platform: mqtt
          topic: 'stat/sonoff11/+'
          payload: 'OFF'
      action:
        - service: time_counter.stop
          entity_id: time_counter.back_bedroom_shutter

    - alias: Back Bedroom Shutter - time counter stopped
      trigger:
        platform: event
        event_type: time_counter.stopped
        event_data:
          entity_id: time_counter.back_bedroom_shutter
      action:
        - service: cover.stop_cover
          data:
            entity_id: back_bedroom_shutter

Went over it several times but can’t find the typo. Perhaps fresh eyes will pick it up.

BTW my relays are reversed ie POWER1 opens, POWER2 closes
Thanks

In action.service.data.entity_id you’re missing cover. before the id of the entity.

It should be:

data:
  entity_id: cover.back_bedroom_shutter

Yep that’s is. Found it 2 seconds after you did. Thanks.

Works perfectly.

Very elegant, especially when combined with https://github.com/thomasloven/lovelace-slider-entity-row/commits?author=thomasloven like so:

  - entity: cover.back_bedroom_shutter
  - entity: cover.back_bedroom_shutter
    full_row: true
    type: 'custom:slider-entity-row'

20

Now to do the other 10 shutters.

Thanks

1 Like

Hello.

I have been working trying to get my roller blind position working today. I had not seen the recent posts to this thread.

So I am trying Seweryn_Zeman’s time_counter custom component.
I have modified my different config files, and like the simple elegant look of the simple slider that is shown in PierreScerri’s screenshot.

I have my configuration files modified, and Lovelace is set up as per PierreScerri’s screenshot - thanks. However, I am back to an old problem:

The slider moves in the interface, but has no action whatsoever. It jumps back to its original (0%) position. Also, moving a shutter using the cover controls does nothing to the position slider… Hmm. Any ideas?

Also, one of my shutters, which shows this in states:


shows NaN% in lovelace? All the other showing “Closed” regardless of their positions. (All of them show 0.0 as the value in states, only this shutter displays NaN % in Lovelace?

Here’s some of my config:

From covers.yaml:

- platform: template
  covers:
    livingfront_cover:
      friendly_name: "Living Room Front Shutter"
      position_template: "{{ (states.time_counter.cover_livingfront_cover.state | int) }}"
      open_cover:
        - service: mqtt.publish
          data:
            topic: 'homeassistant/downstairs/shutters/LivingRoomShutter1/cmnd/POWER1'
            payload: 'On'
      close_cover:
        - service: mqtt.publish
          data:
            topic: 'homeassistant/downstairs/shutters/LivingRoomShutter1/cmnd/POWER2'
            payload: 'On'
      stop_cover:
        - service: mqtt.publish
          data:
            topic: 'homeassistant/downstairs/shutters/LivingRoomShutter1/cmnd/POWER3'
            payload: 'On'   
      set_cover_position:
        - service: time_counter.set
          entity_id: time_counter.cover_livingfront_cover
          data_template:
            state: '{{ position }}'
        - service_template: >
            {% if position > states.cover.livingfront_cover.attributes.current_position | int %}
              cover.open_cover
            {% elif position < states.cover.livingfront_cover.attributes.current_position | int %}
              cover.close_cover
            {% endif %}
          entity_id: cover.livingfront_cover

From my time_counter.yaml file:

  cover_livingfront_cover:
    name: "Living Room Front Shutter position counter"
    duration: 21
    min: 0
    max: 100
    debounce: 1000

From my scripts.yaml file:

open_front_shutter:
  alias: Open Front Shutter
  sequence:
    - service: cover.open_cover
      data:
        entity_id: cover.livingfront_cover
    - service: time_counter.upcount
      data:
        entity_id: cover.livingfront_cover

stop_front_cover:
  alias: Stop Front Shutter
  sequence:
  - service: cover.stop_cover
    data:
      entity_id: cover.front_cover
  - service: time_counter.stop
    data:
      entity_id: cover.front_cover

close_front_shutter:
  alias: Close Front Shutter
  sequence:
    - service: cover.close_cover
      data:
       entity_id: cover.livingfront_cover
    - service: time_counter.downcount
      data:
        entity_id: cover.livingfront_cover

and from my automation.yaml:

#Automations for Living Room Front Shutter
- alias: Living Room Front Shutter - started
  trigger:
    - platform: mqtt
      topic: 'homeassistant/downstairs/shutters/LivingRoomShutter1/stat/+'
      payload: 'ON'
  action:
    - service_template: >
        {% if trigger.topic.split('/')[-1] == 'POWER1' %}
          time_counter.downcount
        {% elif trigger.topic.split('/')[-1] == 'POWER2' %}
          time_counter.upcount
        {% endif %}
      entity_id: time_counter.cover_livingfront_cover

- alias: Living Room Front Shutter - stopped
  trigger:
    - platform: mqtt
      topic: 'homeassistant/downstairs/shutters/LivingRoomShutter1/stat/+'
      payload: 'OFF'
  action:
    - service: time_counter.stop
      entity_id: time_counter.cover_livingfront_cover

- alias: Living Room Front Shutter - time counter stopped
  trigger:
    platform: event
    event_type: time_counter.stopped
    event_data:
      entity_id: time_counter.cover_livingfront_cover
  action:
    - service: cover.stop_cover
      data:
        entity_id: cover.livingfront_cover

If anyone could give me a hint as to where I might look to get the sliders working, I would appreciate that ! Thanks

I found that the slider does not update until the timer stops.

It would be nice to have some indication that the shutter is moving, but I’m happy with the end result

But hey, I got rid of 66 automations, 22 input sliders, and 22 timers. That has to count for something.

Now if only I could get my iPhone Home app to stop saying ‘Opening’ when the shutter is fully open.

Thanks.

Some progress here, problem was PIBCAK. Resolved. ( had an incorrect name for one of my time counters).

However, now I have a different problem, that I don’t fully understand.
None of my sliders work as expected, and one seems to be the reverse of all of the others.

I also find that composing questions to post here is the best way to troubleshoot. While explaining the problem in words, it really helps to go back and check the config… Like you PierreScerri - my POWER1 is up/close and my POWER2 is down/open.

I modified my covers.yaml to reflect the up / down timer for POWER 1 and POWER 2 respectively. It seems to be working better now.

However, the Office Shutter position never gets set… it always stays at 100%. when I use the buttons to control that shutter. If I use the slider, the shutter moves accordingly, and the position is set correctly when it stops moving… unless I set the position with the slider to 0% - then it stays at 100%. Everything is set up the same as the other shutters, so this is a mystery to me.

NONE of the other shutters sliders work to set the position. I try to set the position to say 50% from 100% - and it stops at 97%? However, their position is correctly reported as closed or 100% when fully opened or closed.

So frustrating when the setup is identical (probably isn’t but I cannot see…

One other thing… there’s always one thing isn’t there… When I use a script to invoke the closure of all shutters, once closed, all positions update, apart from my office shutter, which remains at 100% (open). That’s also another small issue… when closed (0%) the slider shows closed. When open (100%) the slider shows 100% (and not open). Can we not have a consistent display and show open for 100%, closed for 0% and the %age for anything in between?

HELP!!!

The inverted shutter has to be a typo.

Re 100% vs open, perhaps that’s why the iPhone Home app says “Opening” when the shutter is at 100%

Still getting a lot of this:

Unable to remove unknown listener <function async_track_point_in_utc_time..point_in_time_listener at 0x6f193108>
6:08 PM core.py (WARNING)

A few of them at a time every 30-45 minutes.

Any idea what this could be?

Hey, good to see that someone made a use of this component. :slight_smile:

I updated the component.py under:

It solves Unable to remove unknown listener warnings.
FYI @PierreScerri

@Neale_Dowling I’ll take a look at your scenario when I find some time!

@Seweryn_Zeman THanks for your work here… using it and its working well.

I found my problem after leaving things alone for some time… (A break, and coming back with fresh eyes is often the solution!!! My problem was my MQTT topic. I organise my topics under “upstairs” and “downstairs”. My office is downstairs, and in the automation, a copy paste error meant I had upstairs in the mqtt topic, not downstairs… @PierreScerri - of course, you were right, it was a typo!!! hence the problem. All working well now. Will try the new code to see if the Unable to remove unknown listener warnings go away.

Thanks again…