Emulating Shelly 2.5's 'One button' input mode for Roller Shutters

When a Shelly 2.5 is controlling roller shutters, there exists the ability to set the “Input buttons” mode of the Shelly. This allows for the possibility of the shutters to be controlled with two separate buttons – one for up, one for down-- OR one button. In the case of “one button” mode, every time the button is pressed, the roller will go in the next sequence step. For example, a button press would start the opening the roller, the next would stop the rolling, the next would start closing the roller, the next press would stop it, etc.

As I have two physical buttons to control my roller, I wanted to use both buttons to control the roller however I wanted to emulate this one button mode using Home Assistant. With the Shelly integrated as a cover, this was relatively straightforward: I needed to keep track of the last state of the roller and either open the roller, close the roller, or stop the roller based on the last state of the roller.

To do this, I created one automation with an action to store the cover's last state in an input_select (an input_text would have worked as well) that was triggered every time there was a state_changed event for the cover. I then created a second automation that, when triggered, would either call cover.open_cover, cover.close_cover, or cover.stop_cover depending on the last state of the cover which is stored in the input_select as an option/value.

Here are the two automations:

alias: Set Bedroom Shutter State (Event Trigger)
description: ''
trigger:
  - platform: event
    event_type: state_changed
condition:
  - condition: template
    value_template: '{{ trigger.event.data.entity_id == "cover.bedroom_shutters" }}'
action:
  - service: input_select.select_option
    data:
      option: '{{ trigger.event.data.old_state.state }}'
    entity_id: input_select.bedroom_shutter_last_state
mode: single

alias: Toggle Bedroom Shutters
description: ''
trigger:
  - device_id: 6124f02a20f611eb8f2d55764adf7b07
    domain: zha
    platform: device
    type: remote_button_alt_short_press
    subtype: button_2
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: input_select.bedroom_shutter_last_state
            state: closing
        sequence:
          - service: cover.open_cover
            entity_id: cover.bedroom_shutters
      - conditions:
          - condition: state
            entity_id: input_select.bedroom_shutter_last_state
            state: opening
        sequence:
          - service: cover.close_cover
            entity_id: cover.bedroom_shutters
    default:
      - service: cover.stop_cover
        entity_id: cover.bedroom_shutters
mode: single
1 Like