Slider for roller shutter positioning with conversion formula

Hello together,

I have a Shelly 2.5 device that I use to control my roller shutter.

Unfortunately, the percentages for controlling the roller shutter do not correspond to the window’s height but instead to how much the blind has been winded down (e.g. in order to move the blind to half of the window’s height I have to set it to 65% instead of 50%).

I have already done some successful tests with a slider based on an input_number and some polynomial functions that translate e.g. 50% to 65% (the according inverse function will then show 50% in the UI when the blind is actually at 65%, so in the middle of the window’s height).

I have set this up as follows (instead of polynomial functions, I use the factors 0.5 and 2 as inverse function in this example):
2020_12_31_15_19_15_Window

  • 1 input_number as slider
  • 2 template sensors
    • Display value: "{{0.5*(state_attr('cover.shellyswitch25_68887d', 'current_position') | float) | round(0)}}"
    • Actual value: "{{(2*(states.sensor.shelly_sz_display.state | float)) | round(0)}}"
  • 2 automations
    • “Trigger” automation (this one is supposed to react to changes of the slider and move the blind to the (translated) position)
      • Trigger: Type “state”, entity “input_number.slider”
      • Action: REST command to move the blind to position '{{states.sensor.shelly_sz_actual.state | round(0)}}'
    • “Listener” automation (this one is supposed to listen to externally triggered changes of the blind’s position and subsequently move the slider to the (translated) position)
      • Trigger: Type “state”, entity “cover.shellyswitch25_68887d”, attribute “current position”
      • Action: Type “Call service”, service “input_number.set_value”, entity id “input_number.slider”, value '{{states.sensor.shelly_sz_display.state | round(0)}}'

The problem now obviously is that the “Trigger” and the “Listener” automation are affecting each other. Whenever I move the roller shutter, the “Listener” sets the value of the slider to 'value x 0.5 ’ which again triggers the “Trigger” automation and so on until the slider’s value has halved itself so often that it arrives at 0.

I already tested several conditions for the automations like “trigger onyl if cover.shellyswitch25_68887d.current_position and slider value are different” but nothing seems to really work and I cannot wrap my head around it :persevere:

What would be the right way to achieve what I want?

Thank you in advance and a Happy New Year!

Try a template cover.

Would that help me in translating the percentages? Basically, this is the only thing left now. I took a look at the template cover documentation but I am afraid I don’t see how this can help to achieve what I want.
All the controls are already working via the Shelly integration. The actual problem is that my two automations are affecting each other.

It sounds like what I did for my Add-A-Motor integration, where my “percentage” is based on how long the motor ran the cord that controls the curtains.

For me I used pyscript to control everything from a templated cover device in HASS.

My Add-A-Motor is activated by an outlet turning on or off, so I can use this to determine what “percentage” the curtain is open by knowing how many seconds it takes to complete a full cycle of the curtains (open to close and close to open). It was made more complicated by the fact that the Add-A-Motor has to complete a cycle to reverse the motor, so it has to be closed fully to draw it back to open or vice versa.

The script I wrote is the action on a cover template in HASS for cover_open, cover_close, etc, and I utilize a variable to know if the motor is set to forward or reverse and how many seconds it has run or if it is at a fully open or closed position to then determine what has to happen to get to the percentage I want.

For example, if it is closed and I want it to be 30% then I turn on the outlet for 30% of the full cycle seconds, if I want to close it back to 20% then it will run all the way to open, turn off the outlet, pause for one second and start the outlet for 80% of the cycle time to get to the 20% I requested.

It is how I was able to take a cheap curtain cord controller and make it a pretty nice piece of home automation rather than forking over the money for truly automated drapes. If you want to look at my script I’m happy to share it, perhaps the concept will help you as it really sounds like a variation on the same theme.

Hi CO_4X4, please feel free to share it, I would love to take a look at it in order to better understand what you’re doing and especially how cover templates can be utilized.

Though, for now I have to say that it doesn’t sound to me like it will solve my problem. I am rather looking for a way that my trigger and listener automations can be triggered individually without getting into that repetition chain where they trigger each other multiple times so long until the roller shutter reaches 0%.

Ok, for anyone interested: I got it to work by correcting my sensors and automations and using a timer.

sensor:
  - platform: template
    sensors:
     shelly_wzk_display:
        friendly_name: "Translated percentage"
        unit_of_measurement: '%'
        value_template: "{{0.95*(state_attr('cover.shellyswitch25_691f30', 'current_position') | float) | round(0)}}"
      shelly_wzk_actual:
        friendly_name: "Actual percentage"
        unit_of_measurement: '%'
        value_template: "{{(1.0526315789473684210526315789474*(states('input_number.rolladen_wzk_slider') | float)) | round(0)}}"

The factors 0.95 and 1.0526 are just used for testing. For productive use, these factors will be replaced by a polynomial function and their corresponding inverse function.

2 automations:

  • “Listener” automation
    • Trigger: change of roller shutter’s attribute “current_position”
    • Condition: timer.rollershutter is “idle”
    • Actions
      1. Set value of input_number.slider to '{{states.sensor.shelly_wzk_display.state}}'
      2. Call service timer.start for timer.rollershutter with duration 2 seconds.
  • “Trigger” automation
    • Trigger: change of input_number.slider's value
    • Condition: timer.rollershutter is “idle”
    • Actions
      1. Call service --> script for moving roller shutter to position {{states.sensor.shelly_wzk_actual.state}}' (REST call)
      2. Call service timer.start for timer.rollershutter with duration 2 seconds.

Thanks for your support.