Slider to call local network API

Hey, I’m pretty new to using HA so bear with my limited knowledge please!

I have my blinds hooked up to a DIY motor solution which is controlled via an onboard api on my local network. This allows me to send a GET request to get the current % opened and also to send a PUT request to open to a certain %.

I’m looking to hook this up to a slider in home assistant so I can see the current % and also drag it to open/close as desired. I’m guessing that’ll involve a GET to the local device API on my network to initially set the slider and then a PUT when I drag it and let go at another value. Happy to do some research but don’t really know where to begin. Thanks!

edit: Looks like the below works to get the response back from the API for current state but now just need to find out how to link a slider to a PUT request to update…

sensor:
    - platform: rest
        name: "Blind Status"
        value_template: '{{ value_json.position }}'
        unit_of_measurement: "%"
        resource: http://192.168.0.53/api/status

Do you control these blinds only with Home Assistant with this slider or also manually through an app or something?

The blinds are controlled by an ESP8266 which is running the API itself. That controls the motor so it’s not an off the shelf device with any existing interfaces or apps etc

All I need to be able to do is have a slider and if I drag it to 60 for example it would do a generic PUT REST call of “http://192.168.0.53/api/blinds?open=60”. There must be some way!

I’m guessing similar to how you’d use a slider to control light brightness via an “input-number” but I need that to map to a REST call.

have you looked at template cover?

once that’s properly configured you could add

or use esphome for your 8266 like:

Thanks I’ll take a look over those links tomorrow! I might be misunderstanding your second post but I don’t want to change anything I have running on the ESP as I’m pretty happy with that and I don’t want any high coupling between HA and the device. The ESP handles positioning, logic and state and HA simply calls it to say “can you open to X”.

It must be possible to simply send a basic PUT request to a URL. I might be able to combine that slider example with the RESTful command after a further research. Hoping someone might have had an example of passing the values between :stuck_out_tongue:

Take a look at the tenplate cover that @eggman posted and combine this with the rest sensor and the rest command

I’m not overly sure what benefits I get from the cover templates vs just a slider and automation?

I think I’m getting close with the below but it’s not quite there (not sending the exact value it seems and need to set the initial on the slider from the rest sensor GET)

input_number:
  blind_slider:
    name: "Blind State"
    min: 0
    max: 100
    step: 10

rest_command:
  blinds_set_state:
    url: "http://192.168.0.53/api/blinds?open={{ urlInput }}"
    method: PUT

automation:
  - alias: "Blind State Changed"
    trigger: 
      platform: state
      entity_id: input_number.blind_slider

    action:
      - service: rest_command.blinds_set_state
        data:
          urlInput: '{{ trigger.state }}'

You don’t need to create any automations or input_slider, just the rest commands and the cover and it will generate an entitiy that is of device type cover, you have the services set_cover_position etc.

Benefits would be IMHO better integration into home assistant. Further automations could be a lot easier when home assistant know what device it is and what (extra) services it can call

For instance if you know wanted to implement a solution where you open the blinds using google assistant. It would be far easier if home assistant knows it’s not just a random slider, but an actual cover it can open. ( I’m assuming here covers have the same plug and play functionality as lights do as I have yet to work with them) When you’re using the home assistant cloud for instance, after creating the cover home assistant will imediatly sync your cover entity to google home and make it available. Google home will instantly know what it is and how to deal with it while your slider would need additional configuration probably.

Changing the esp to Esphome also yields better integration. It adds devices almost automatically. You can program the device from home assistant and flash Over the Air without needing phyiscal access. You can check and debug by connecting to the logger over wifi. You can check on the status from home assistant etc etc

An example of something i’m running into:

I’ve got a smart plug connected to a light in the kitchen. I’ve reused my normal code for a smart plug for this one. However, When I now ask google home to turn off all the lights this light will stay on as google doesn’t know it’s a light. Telling Hassio it is a light and not a smart plug would fix this issue instantly.

TLDR: When starting out it can be easier to use the premade integrations available. If everything now works and you’re happy with it. Fine, don’t change anything, this is what you want. However, if you want to add functionality in the future and you probably will since you’re using home assistant. Your life can be made a lot easier when using the built in integrations as it already includes or maybe will recieve a lot of functionality you might want in the future.

Ah ha, rightly so! Much easier after I understood passing the position to the rest template. Thanks! Just need to find out how to format the entity better now on the UI. A lot of wasted space with the arrows and would prefer the position % to be shown in the same row somewhere :slight_smile: I’m sure the slider in the popup could look a little nicer too.

Might end up swapping to this soon: https://github.com/thomasloven/lovelace-slider-entity-row/tree/7

For anyone else:

rest_command:
  blinds_set_state:
    url: "http://192.168.0.53/api/blinds?open={{ urlInput }}"
    method: PUT

cover:
  - platform: template
    covers: 
      blinds:
        friendly_name: "Living Room Blinds"
        position_template: "{{ states('sensor.living_room_blind_status') }}"
        open_cover:
          service: rest_command.blinds_set_state
          data:
            urlInput: '100'
        close_cover:
          service: rest_command.blinds_set_state
          data:
            urlInput: '0'
        set_cover_position:
          service: rest_command.blinds_set_state
          data_template:
            urlInput: "{{position}}"
1 Like