Solution to TS130F curtain switch

Hi,
My shutters are controlled by Tuya TS130F zigbee switches
unfortunately, unlike the documentation, the position is 100 when the shutter is closed and 0 when the shutter is open and motor_reversal does not work.
So I created virtual shutter like this:

cover:
  - platform: template
    covers:
      volet_salon:
        device_class: shutter
        friendly_name: "volet du salon"
        position_template: "{{ (100 - state_attr('cover.shutter_1, 'position')| float )|int }}"
        open_cover:
          service: cover.open_cover
          data: 
          target:
            entity_id: cover.shutter_1
        close_cover:
          service: cover.close_cover
          data: 
          target:
            entity_id: cover.shutter_1
        stop_cover:
          service: cover.stop_cover
          data:
          target:
            entity_id: cover.shutter_1
        set_cover_position:                   
          service: cover.set_cover_position         
          data:
            position: "{{ ( 100 - position )| int  }}"
          target:
            entity_id: cover.shutter_1

This works fine :slight_smile:

I wanted to make a correction so that position 50 corresponds to a median physical position of the shutter.
So I defined a parabolic law.

to find it, I physically opened the shutter halfway, and I read the position exposed by zigbee. example 36.
I defined my law by 3 points:
X = 100 Y = 0
X = 36 Y = 50
X = 0 Y = 100
I used an internet solver to find the equation
y = 0.0060763888888889 x² -1.6076388888889 x + 100
I modified the lines

position_template: "{{ (0.0060763*state_attr('cover.shutter_1', 'position')*state_attr('cover.shutter_1', 'position')-1.60763*state_attr('cover.shutter_1', 'position')+100| float )|int }}"

and

position: "{{ ( 0.0060763*position*position -1.60763*position+100 | float )| int  }}"

:slight_smile:

2 Likes

Thanks Thierry, I’m in the same situation and I’m looking for a solution as yours!
Unfortunately it doesn’t seems to work for me when I copy this yaml in configuration.yaml : I’ve got an error as “data:” attributes are empty.

Is there any trick I’ve missed?

Thanks!

Indeed there is a writing error here is the real yaml

        open_cover:
          service: cover.open_cover
          data: {}
          target:
            entity_id: cover.shutter_1
        close_cover:
          service: cover.close_cover
          data: {}
          target:
            entity_id: cover.shutter_1
        stop_cover:
          service: cover.stop_cover
          data: {}
          target:
            entity_id: cover.shutter_1
```
1 Like

Hi @thierry-rhone
I have the same problem witch my loratap curtain switch.
Can you help me.
Apparement tu es français et moi aussi donc si on peut discuter en français.
Merci

Hello!

I’m facing the same situation and I need help?

is this still the best solution? if so, how do I apply this fix?

thanks

Bonjour, bien, merci de nous avoir donné une solution à l’interrupteur de rideau TS130F.Je voulais vous demander si le pourcentage est indiqué sur la carte, car le pourcentage est toujours nul pour moi, même si cela fonctionne très bien. Merci

Hi Thierry,

Thanks very much, actually after your fix, this cheap controller is working better than the most expensive z-wave I tried… really good work…

Tried to fix the issue with my wrong position reading on my TS130F (from Moes),
As for version HA 2024.5 with ZHA with the Quirk: zhaquirks.tuya.ts130f.TuyaTS130FTI2 it seems not necessary to create such a template.
But I couldn’t manage to enter the parameters to force the TS130F considering the time difference between up and down lift.

I did use the following params, which allows to see the percentages more or less correct:

calibration = first step I did
calibration_time = second step adding the value manually did make the thing work
acceleration_time_lift = tried, but not clear to me if related to the difference up/down

There is solution, but I seems to be a bit quirky to me. I think if someone knows, more about the different available parameter it should work with no additional template.