Need help configurating smart blinds using the Tuya component

Hey, sorry for the delay. Yes, I finally figured it out, here is my automations.yaml file, as you can see I added an automation so the Tuya devices send their state every two second:

- id: '1548790568933'
  alias: Actualizar Estados Tuya
  trigger:
  - platform: time_pattern
    seconds: /2
  action:
  - alias: ''
    data: {}
    service: tuya.force_update
- id: '1548848519050'
  alias: Open to off
  trigger:
  - entity_id: cover.50758014cc50e31a7f8c
    from: open
    platform: state
    to: unknown
  action:
  - service: timer.cancel
    entity_id: timer.window_up
      
- id: '1548848632774'
  alias: Closed to off
  trigger:
  - entity_id: cover.50758014cc50e31a7f8c
    from: closed
    platform: state
    to: unknown
  action:
  - service: timer.cancel
    entity_id: timer.window_down
    
- id: '1548848879275'
  alias: Window - Timer stopped
  trigger:
  - event_data:
      entity_id: timer.window_down
    event_type: timer.finished
    platform: event
  - event_data:
      entity_id: timer.window_up
    event_type: timer.finished
    platform: event
  condition: []
  action:
  - data:
      entity_id: cover.50758014cc50e31a7f8c
    service: cover.stop_cover
- id: '1548849447894'
  alias: Button Up
  trigger:
  - entity_id: cover.50758014cc50e31a7f8c
    platform: state
    to: open
  condition:
  - condition: template
    value_template: '{{ as_timestamp(now()) - as_timestamp(states.input_number.window_set_position.last_updated)>3 }}'
  action:
  - data:
      duration: 00:00:25
      entity_id: timer.window_up
    service: timer.start
- id: '1548849728182'
  alias: Button Down
  trigger:
  - entity_id: cover.50758014cc50e31a7f8c
    platform: state
    to: closed
  condition:
  - condition: template
    value_template: '{{ as_timestamp(now()) - as_timestamp(states.input_number.window_set_position.last_updated)> 3 }}'
  action:
  - data:
      duration: 00:00:25
      entity_id: timer.window_down
    service: timer.start
- id: '1548850079399'
  alias: Posicion Arriba
  trigger:
    platform: time_pattern
    seconds: /1
  condition:
  - condition: state
    entity_id: timer.window_up
    state: active
  action:
  - service: input_number.set_value
    data_template:
      entity_id: input_number.window_position
      value: '{{ (states.input_number.window_position.state | int) + 1 }}'
    
- id: '1548850263986'
  alias: Posicion abajo
  trigger:
    platform: time_pattern
    seconds: /1
  condition:
  - condition: state
    entity_id: timer.window_down
    state: active
  action:
  - service: input_number.set_value
    data_template:
      entity_id: input_number.window_position
      value: '{{ (states.input_number.window_position.state | int) - 1 }}'
    
- id: '1548850461000'
  alias: Set Position Down
  trigger:
  - entity_id: input_number.window_set_position
    platform: state
  condition:
  - condition: template
    value_template: '{{ (states.input_number.window_position.state | int) > ((((states.input_number.window_set_position.state | int ) * 25 )/100) | int) }}'
  action:
  - service: timer.start
    data_template:
      entity_id: timer.window_down
      duration: "{{ '00:00:%02d' | format( ((states.input_number.window_position.state | int) - ((((states.input_number.window_set_position.state | int ) * 25 )/100) | int) ) | abs ) }}"
  - service: cover.close_cover
    data:
      entity_id: cover.50758014cc50e31a7f8c
- id: '1548850461111'
  alias: Set Position Up
  trigger:
  - entity_id: input_number.window_set_position
    platform: state
  condition:
  - condition: template
    value_template: '{{ (states.input_number.window_position.state | int) < ((((states.input_number.window_set_position.state | int ) * 25 )/100) | int) }}'
  action:
  - service: timer.start
    data_template:
      entity_id: timer.window_up
      duration: "{{ '00:00:%02d' | format( ((states.input_number.window_position.state | int) - ((((states.input_number.window_set_position.state | int ) * 25 )/100) | int) ) | abs ) }}"
  - service: cover.open_cover
    data:
      entity_id: cover.50758014cc50e31a7f8c
2 Likes

Hello Peroanjo, i’m new here. can jou explane your code?

Thank you very much! Do you mind sharing the config and lovelace part as well?

Hi Daniel, I’m facing the same problem, I adapted your automation to my cover, but I think I need to do more things… It’s possible that I need to configure input_numbers? which? window_position and windows_set_position? how do you show this on the GUI? Can you explain it to me?
I also need to define timers? how many?
Sorry but i’m a little bit lost.
Gracias!

Thanks, @peroanjo - this is so useful. What a huge workaround - do you know if it’s the tuya app that simply doesn’t report the state properly when it changes - even though it maintains it in the app, or the tuya integration that doesn’t support the functionality. If it’s the tuya integration, maybe it’s possible to add it in - we could save so much overhead (!!) Thanks for the hard work!

Hi,

I’m having a very similar problem after updating the wifi firwmare of one of my curtain switches. Before the update, if you hit open or close button and don’t hit the stop, status was reported as open or closed respectively until further actions. After updating firmware, the open / closed status is maintained just for the few seconds the switch is acting on the curtain. Then, once it stops, the status goes to “unknown”.

After playing with the tuya app, I believe the behaviour changed on the tuya cloud service, that started sending an “stop” command to the switch after a defined trip time.
I believe we can provide workarounds of different complexities, but the perfect solution would be that tuya cloud gets enhanced so it delivers the open / closed status when the switch was actioned for the full trip time defined. I’m trying to figure out how to send that feedback to tuya.

1 Like

Hi!

I have the exact same problem. Could you please explain the code or how did it impact? Like what can you see now? What’s the difference? Can you open the shutter to 50%, for example? :slight_smile:

Could you also give the rest of the code for the configuration.yaml and/or others? Sorry! I’m new to this system and I would really appreciate more information from my shutters! :slight_smile:

Thank you so much for your time! @peroanjo

We have a bunch of codes to set position of a RF curtain on Home Assistant. The curtain is controlled using 3 switches: open, close and stop.
If you mind, we can share it.

konnectedvn
We have a bunch of codes to set position of a RF curtain on Home Assistant. The curtain is controlled using 3 switches: open, close and stop.
If you mind, we can share it.

RF? I do have a remote for my curtains, but not sure if its RF… but I’d like to see the code you have anyways… I have nothing but issues with states with my Zemismart curtains.

On another note… in an attempt to fix my issues with states and position with my curtains, i did clean up the code above and explain what’s happening with that — It was confusing, ill admit.

I adjusted it for my sliding curtains; but its should be the same for shades or blinds etc.

You’ll need 2 timers setup in config yaml

timer:
  curtains_open:
  name: "Curtains Open"
    
  curtains_closed:
  name: "Curtains Closed"

Also, you’ll need 2 input_number’s setup (use helper) set max time to the time it takes for your curtains to fully open or close. In my case, 15s

input_number.curtains_set_position
input_number.curtains_position

Heres the very cleaned up, and properly formatted automation.yaml code from above— with some explaining.


#Force state update from Tuya App Every 2 sec.
#In my case this did nothing. Tuya didn’t update — but it should’ve 
  - id: update_status_from_tuya
    alias: 'Update Status from Tuya '
    trigger:
    - platform: time_pattern
      seconds: /2
    action:
    - service: tuya.force_update
      data: {}

#Cancel curtains_open Timer upon Unknown state
  - id: open_to_unknown
    alias: 'Open to unknown'
    trigger:
    - entity_id: cover.balcony_curtains
      from: open
      platform: state
      to: unknown
    action:
    - service: timer.cancel
      entity_id: timer.curtains_open
       
#Cancel curtains_closed Timer upon Unknown state 
  - id: closed_to_unknown
    alias: 'Closed to unknown'
    trigger:
    - entity_id: cover.balcony_curtains
      from: closed
      platform: state
      to: unknown
    action:
    - service: timer.cancel
      entity_id: timer.curtains_closed
      
#Stop the Curtains when either Timer is Finished
  - id: curtains_timer_finished
    alias: 'Curtains - Timer Finished'
    trigger:
    - platform: event
      event_data:
        entity_id: timer.curtains_closed
      event_type: timer.finished
    - platform: event
      event_data:
        entity_id: timer.curtains_open
      event_type: timer.finished
    condition: []
    action:
    - service: cover.stop_cover
      data:
        entity_id: cover.balcony_curtains
      
#Start curtains_open Timner on OPEN state
#Adjust Duration to the time it takes to open. In my case, it takes 15sec to fully Open.
  - id: open_button
    alias: 'Open Button'
    trigger:
    - platform: state
      entity_id: cover.balcony_curtains
      to: open
    condition:
    - condition: template
      value_template: '{{ as_timestamp(now()) - as_timestamp(states.input_number.curtains_set_position.last_updated)>3 }}'
    action:
    - service: timer.start
      data:
        duration: 00:00:15
        entity_id: timer.curtains_open
      
#Start curtains_closed Timner on CLOSED state
#Adjust Duration to the time it takes to Close. In my case, it takes 15sec to fully Close.
  - id: close_button
    alias: 'Close Button'
    trigger:
    - platform: state
      entity_id: cover.balcony_curtains
      to: closed
    condition:
    - condition: template
      value_template: '{{ as_timestamp(now()) - as_timestamp(states.input_number.curtains_set_position.last_updated)> 3 }}'
    action:
    - service: timer.start
      data:
        duration: 00:00:15
        entity_id: timer.curtains_closed
      
#When curtains_open Timer Starts, Set the Curtains Position value
  - id: position_open
    alias: 'Position Open'
    trigger:
      platform: time_pattern
      seconds: /1
    condition:
    - condition: state
      entity_id: timer.curtains_open
      state: active
    action:
    - service: input_number.set_value
      data_template:
        entity_id: input_number.curtains_position
        value: '{{ (states.input_number.curtains_position.state | int) + 1 }}'
    
#When curtains_closed Timer Starts, Set the Curtains Position value  
  - id: position_closed
    alias: 'Position Closed'
    trigger:
      platform: time_pattern
      seconds: /1
    condition:
    - condition: state
      entity_id: timer.curtains_closed
      state: active
    action:
    - service: input_number.set_value
      data_template:
        entity_id: input_number.curtains_position
        value: '{{ (states.input_number.curtains_position.state | int) - 1 }}'
      
#Set the Curtains Position value towards CLOSED until the 15sec Close time is reached. 
#Be Sure to change my 15s value to yours in the value_template and Duration below.
#Make sure it matches your close_button second values above.
  - id: set_position_closed
    alias: 'Set Position Closed'
    trigger:
    - platform: state
      entity_id: input_number.curtains_set_position
    condition:
    - condition: template
      value_template: '{{ (states.input_number.curtains_position.state | int) > ((((states.input_number.curtains_set_position.state | int ) * 15 )/100) | int) }}' # <-- Change 15 to your Close time in seconds
    action:
    - service: timer.start
      data_template:
        entity_id: timer.curtains_closed
        duration: "{{ '00:00:%02d' | format( ((states.input_number.curtains_position.state | int) - ((((states.input_number.curtains_set_position.state | int ) * 15 )/100) | int) ) | abs ) }}" # <-- Change 15 to your Close time in seconds
    - service: cover.close_cover
      data:
        entity_id: cover.balcony_curtains

#Set the Curtains Position value towards OPEN until the 15sec Open time is reached. 
#Be Sure to change my 15s value to yours in the value_template and Duration below.
#Make sure it matches your open_button second values above.
  - id: set_position_open
    alias: 'Set Position Open'
    trigger:
    - platform: state
      entity_id: input_number.curtains_set_position
    condition:
    - condition: template
      value_template: '{{ (states.input_number.curtains_position.state | int) < ((((states.input_number.curtains_set_position.state | int ) * 15 )/100) | int) }}' # <-- Change 15 to your Open time in seconds
    action:
    - service: timer.start
      data_template:
        entity_id: timer.curtains_open
        duration: "{{ '00:00:%02d' | format( ((states.input_number.curtains_position.state | int) - ((((states.input_number.curtains_set_position.state | int ) * 15 )/100) | int) ) | abs ) }}" # <-- Change 15 to your Open time in seconds
    - service: cover.open_cover
      data:
        entity_id: cover.balcony_curtains

Ok, keep in mind this is not my code; i simply cleaned up and attempted to adapt the above posted code to my needs with my curtains. Unfortunately, this seems to be an ongoing issue with Tuya not updating their state when requested. I’m not sure anything from our end can be done about this. But maybe someone will have better luck then i did with this code.

In theory, with this code, you’d be able to setup a slider in the frontend (with input_number.curtains_position) and choose the position you want.

Ah well… the search continues for a solution for these migraine-inducing Tuya devices…

Sorry for my late reply. My codes are here but few days ago, I found another component with same functions.
Here: Custom Component: Cover Time Based
Using component instead of a compilation of automations, inputs etc. might save time and easy to deploy multi covers.

Hi all,
i just setup some tuya covers switches.
Up and down is working, but state is not return or just sometimes…
I’m not talking about state going to unknown. State is not changing to ‘open’ or ‘closed’ even a second… It stays at unknown…

Hi, there is an issue with the Tuya API which impacts the HA integration but for controlling with HA you can create a cover template for each switch and set the open/closed icon based on the switch state. Surprisingly, the icon retains active state (colour) but not the active icon. Still it’s better than the alternative.

cover:
  - platform: template
    covers:
      office_blind2:
        device_class: shutter
        optimistic: true
        friendly_name: "Office Blind"
        open_cover:
          service: cover.open_cover
          data:
            entity_id: cover.20770531bcddc2608xxxxx
        close_cover:
          service: cover.close_cover
          data:
            entity_id: cover.20770531bcddc2608xxxxx
        stop_cover:
          service: cover.stop_cover
          data:
            entity_id: cover.20770531bcddc2608xxxxx
        icon_template: >-
            {% if is_state('cover.20770531bcddc2608xxxxx', 'open') %}
              mdi:window-shutter-open
            {% else %}
              mdi:window-shutter
            {% endif %}
2 Likes

This works perfect. Thank you.

Done everything, but the server will not restart, I get the errors something like_:

  Invalid config for [timer]: expected a dictionary for dictionary value @ data['timer']['name']. Got 'Curtains Closed'. (See /config/configuration.yaml, line 97). 
Invalid config for [automation]: [action] is an invalid option for [automation]. Check: automation->trigger->0->action. (See /config/configuration.yaml, line 24). 
Invalid config for [automation]: [action] is an invalid option for [automation]. Check: automation->trigger->0->action. (See /config/configuration.yaml, line 24). 
Invalid config for [automation]: expected dict for dictionary value @ data['trigger'][0]['event_data']. Got None
extra keys not allowed @ data['trigger'][0]['entity_id']. Got None
required key not provided @ data['action']. Got None. (See /config/configuration.yaml, line 24). 

You have a timer in your automation that is in error or other issues in automation config.

Hello everyone! :smiley: Sorry to bring this subject back up, but I would really loveto control my shutters with %, like “Open 30% of the shutter”. But I don’t understand how can I do this. Is there any tutorial ? I’m also very new to HA and I don’t understand much of what was spoken eheheh . Or is there any video explaining? Sorry to bother :<

Good afternoon everyone. I want to ask some questions. I have 6 Wifi module curtain ms-108. In HA appear as a switch and not as a cover. And in this way it just appears to me as a simple switch and not as a double switch. Can you help? Thanks

hola, ¿como seria el automatismo si quiero crear una escena que cuando diga buenas noches al asistente de google me baje la persiana 10 segundos? gracias, he probado horas y no lo consigo

Hello, how would the automation be if I want to create a scene that when I say good night to the google assistant, I lower the blind for 10 seconds? Thanks, I have tried hours and I can’t