Controlling Switchbot Curtains via Alexa

Home Assistant Automation

Although there is a switchbot integration for Home assistant, I could not get it to work easily. So I set up an input boolean for my living room curtains and then set up two routines on Alexa to open and close the curtains. The routines toogle the input boolean when run so the states say in sync even if the curtains are opened or closed via Alexa.

alias: Control Living Room Curtains
description: ''
trigger:
  - platform: state
    entity_id: input_boolean.living_room_curtains
    id: open
    to: 'on'
  - platform: state
    entity_id: input_boolean.living_room_curtains
    id: close
    to: 'off'
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: open
        sequence:
          - service: media_player.play_media
            data:
              media_content_id: open curtains
              media_content_type: custom
            target:
              entity_id: media_player.kitchen_sonos
      - conditions:
          - condition: trigger
            id: close
        sequence:
          - service: media_player.play_media
            data:
              media_content_id: close curtains
              media_content_type: custom
            target:
              entity_id: media_player.kitchen_sonos
    default: []
  - service: media_player.play_media
    data:
      media_content_id: open curtains
      media_content_type: custom
    target:
      entity_id: media_player.kitchen_sonos
mode: single