Template Switch - On/Off Flickering Behavior

Hi all,

I have a shutter that I control via a template switch. When turned on, the switch sets the shutter to a fixed position. Then the switch is turned off, the shutter opens. This works fine, but in the UI the switch behavior could be improved.

When the shutter is fully open and I toggle the switch, the following behavior is observed:

  • Switch turns on
  • A few seconds pass
  • Switch turns off
  • Many seconds pass
  • Switch turns on

I use the Somfy API to control my shutter and this causes a delay in cover status updates (since it’s not a local API). And that makes the switch behavior noticeable. Is there a way to fix this?

Let’s see your yaml for these components. Can’t say much without that.

Here you go, my switch template:

- platform: template
  switches:
    attic_shutter_ventilation_mode:
      friendly_name: Attic Shutter Ventilation Mode
      value_template: >-
        {{ 
          state_attr("cover.attic_shutter", "current_position")|int > 20 and
          state_attr("cover.attic_shutter", "current_position")|int < 25 
        }}
      icon_template: mdi:weather-windy
      turn_on:
      - service: cover.set_cover_position
        entity_id: cover.attic_shutter
        data:
          position: 21
      turn_off:
      - service: cover.open_cover
        entity_id: cover.attic_shutter

Not sure what the ‘fully open’ position is, but it seems as though it would be greater than 25.

So, if it’s fully open, the switch would be off, so toggling it would be to turn it on. Optimistically, the switch stays in the on position until the state of the cover changes and the value_template is evaluated again. Moving the cover probably takes some time, so the position goes through states of “fully open - 1”, “fully-open - 2”, etc. The switch’s value_template would evaluate to ‘off’, until it gets to less than 25, at which poinnt it would turn back on again.

So what would be an elegant solution to mitigate this behavior and have the switch stay on/off until the cover has set in the switched position?

It’s more work than it’s worth.

You could pair it with a input_boolean but it could get out of sync. Keeping it in sync will be the headache part. Personally, I just deal with it.

I think what makes it weird is that upper bound on the position. You can see how as the cover goes from closed to fully open, the value_template would evaluate to off, then on, and finally off again. That’s really three states and doesn’t really lend itself to a switch, which only has two.

Maybe replace the switch with an input_select like:

input_select:
  attic_shutter_ventilation_mode:
    name: Attic shutter ventilation mode
    options:
      - Narrow
      - Ventilating
      - Wide

I’m kind of with @petro with this one though…It’s probably going to be more trouble than it’s worth, unless you can figure out a new condition that actually only has two states for your cover.

Also, it’s not the sort of state that can change instantaneously like power to a light. It’s going to take time for the cover to move between two different positions. Even the input_select method is going to have a problem with that.

He may be able to template it if his cover has an intermediate state sent to an attribute or the main state. Like “opening” or “closing”. I don’t know of many covers that do this.