Switch-Bot API integration

Something like this?

sensor:
  - platform: rest
    name: 'Positie Woonkamer Gras Gordijn'
    resource: !secret switchbot_woonkamer_gras_gordijn_status_url
    method: GET
    scan_interval: 30
    headers:
      Authorization: !secret switchbot_api
      Content-Type: 'application/json'
    value_template: '{{ value_json.body.slidePosition }}'
    json_attributes_path: "$.body"
    json_attributes:
      - deviceId
      - deviceType
      - hubDeviceId
      - calibrate
      - group
      - moving
      - slidePosition    
  - platform: rest
    name: 'Positie Woonkamer Water Gordijn'
    resource: !secret switchbot_woonkamer_water_gordijn_status_url
    method: GET
    scan_interval: 30
    headers:
      Authorization: !secret switchbot_api
      Content-Type: 'application/json'
    value_template: '{{ value_json.body.slidePosition }}'
    json_attributes_path: "$.body"
    json_attributes:
      - deviceId
      - deviceType
      - hubDeviceId
      - calibrate
      - group
      - moving
      - slidePosition  
cover:
  - platform: template
    covers:
      woonkamer_gras_gordijn:
        device_class: curtain
        friendly_name: "Woonkamer gras gordijn"
        #position_template: "{{ states('sensor.positie_woonkamer_gordijn') }}"
        position_template:  "{% if  (states('sensor.positie_woonkamer_gras_gordijn') | round | int) == 0 %}
                             100
                             {% else %}
                             {{  100 % (states('sensor.positie_woonkamer_gras_gordijn') | round | int) }}
                             {% endif %}" # my change using % (mod) to convert the value. if value is 0 it throws error in log about using mod on a value of 0. so place in the static value instead.
        open_cover:
          service: rest_command.switchbot_device_command
          data:
            deviceId: !secret switchbot_woonkamer_gras_gordijn_deviceId
            command: "setPosition"
            parameter: "0,ff,0"
        close_cover:
          service: rest_command.switchbot_device_command
          data:
            deviceId: !secret switchbot_woonkamer_gras_gordijn_deviceId
            command: "setPosition"
            parameter: "0,ff,100"
        stop_cover:
          service: rest_command.switchbot_device_command
          data:
            deviceId: !secret switchbot_woonkamer_gras_gordijn_deviceId
            command: "turnOff"
        set_cover_position:
          service: rest_command.switchbot_device_command
          data:
            deviceId: !secret switchbot_woonkamer_gras_gordijn_deviceId
            command: "setPosition"
            parameter: "0,ff,{{position}}"
  - platform: template
    covers:
      woonkamer_water_gordijn:
        device_class: curtain
        friendly_name: "Woonkamer water gordijn"
#        position_template: "{{ states('sensor.positie_woonkamer_water_gordijn') }}"
        position_template:  "{% if  (states('sensor.positie_woonkamer_water_gordijn') | round | int) == 0 %}
                             100
                             {% else %}
                             {{  100 % (states('sensor.positie_woonkamer_water_gordijn') | round | int) }}
                             {% endif %}" # my change using % (mod) to convert the value. if value is 0 it throws error in log about using mod on a value of 0. so place in the static value instead.
        open_cover:
          service: rest_command.switchbot_device_command
          data:
            deviceId: !secret switchbot_woonkamer_water_gordijn_deviceId
            command: "setPosition"
            parameter: "0,ff,0"
        close_cover:
          service: rest_command.switchbot_device_command
          data:
            deviceId: !secret switchbot_woonkamer_water_gordijn_deviceId
            command: "setPosition"
            parameter: "0,ff,100"
        stop_cover:
          service: rest_command.switchbot_device_command
          data:
            deviceId: !secret switchbot_woonkamer_water_gordijn_deviceId
            command: "turnOff"
        set_cover_position:
          service: rest_command.switchbot_device_command
          data:
            deviceId: !secret switchbot_woonkamer_water_gordijn_deviceId
            command: "setPosition"
            parameter: "0,ff,{{position}}"
1 Like