How to retrieve response from Restful http get command

I have a RESTful command set up to get the current speed of a pond pump

rest_command:
  get_falls_pump_speed:
    url: "https://smartcontrol.aquascapeinc.com/external/api/get?token=MyToken&v2"

Getting the url in a browser returns the speed of the pump as such - 1 is the current speed:

I’ve read through a bunch of documentation but I just can’t figure out what I need to add to my RESTful command to retrieve this speed. Your help would be appreciated.

I have no problem changing the pump speed or turning it on or off from HA but getting it’s current state has me scratching my head.

I don’t think it matters to this question but I have the pumps set up in HA as template lights and the various scripts call a RESTful command to perform each function.

- platform: template
  lights:
    falls_pump:
      friendly_name: "Falls Pump"
      turn_on:
        service: script.falls_pump_on
      turn_off:
        service: script.falls_pump_off
      set_level:
        service: script.falls_pump_level
        data:
          brightness: "{{ brightness }}"
    bog_pump:
      friendly_name: "Bog Pump"
      turn_on:
        service: script.bog_pump_on
      turn_off:
        service: script.bog_pump_off
      set_level:
        service: script.bog_pump_level
        data:
          brightness: "{{ brightness }}"

You need a value_template and a level_template for your template ‘lights’. The value_template is meant for on/off state, and the level_template for the actual speed.

The level_template (speed) of the template light can be based on a Rest sensor which retrieves the JSON result mentioned above.

With some logic you should also be able to derive the state (on/off) from the speed?

Thank you @verjager for pointing out that I needed a value and level template for my template lights. I probably would have gone about that in the wrong manner. I have a similar http get for determining whether the pumps are on or off.

I had been over the documentation for the RESTful Sensor multiple times. That’s where I’m confused. Should I be doing something like this?

sensor:
  - platform: rest
    resource: https://smartcontrol.aquascapeinc.com/external/api/get?token=MyToken&v2
    method: GET
    level_template: bog_pump_speed

Where “bog_pump_speed” is the name I gave my level_template in the template lights?

I would expect:

sensor:
  - platform: rest
    resource: https://smartcontrol.aquascapeinc.com/external/api/get?token=MyToken&v2
    method: GET
    value_template: "{{ value_json[0] }}"

Thanks again for the help. I’m making progress but I’m still doing a couple of things wrong.

When I look at the log I see that I am retrieving the values requested:

2023-11-08 10:57:33.771 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://smartcontrol.aquascapeinc.com/external/api/get?token=MyToken1&v1
2023-11-08 10:57:33.773 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://smartcontrol.aquascapeinc.com/external/api/get?token=MyToken1&v2
2023-11-08 10:57:33.775 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://smartcontrol.aquascapeinc.com/external/api/get?token=MyToken2&v1
2023-11-08 10:57:33.776 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://smartcontrol.aquascapeinc.com/external/api/get?token=MyToken2&v2
2023-11-08 10:57:33.894 DEBUG (MainThread) [homeassistant.components.rest.data] Data fetched from resource: 1
2023-11-08 10:57:33.921 DEBUG (MainThread) [homeassistant.components.rest.data] Data fetched from resource: 1
2023-11-08 10:57:33.923 DEBUG (MainThread) [homeassistant.components.rest.data] Data fetched from resource: 5
2023-11-08 10:57:33.925 DEBUG (MainThread) [homeassistant.components.rest.data] Data fetched from resource: 1

But when I look at the sensor using developer tools it shows no value:

Secondly my scan_interval is being ignored. The requests are just running over and over continuously. I’ve seen some posts that say the scan_interval is no longer used but there is an example of it on the documentation page for Rest sensor.

  - platform: rest
    name: Bog pump speed
    resource: https://smartcontrol.aquascapeinc.com/external/api/get?token=MyToken1&v2
    method: GET
    value_template: "{{ value_json[0] }}"
    scan_interval: 900

  - platform: rest
    name: Falls pump speed
    resource: https://smartcontrol.aquascapeinc.com/external/api/get?token=MyToken2&v2
    method: GET
    value_template: "{{ value_json[0] }}"
    scan_interval: 900

  - platform: rest
    name: Bog pump OnOff
    resource: https://smartcontrol.aquascapeinc.com/external/api/get?token=MyToken1&v1
    method: GET
    value_template: "{{ value_json[0] }}"
    scan_interval: 600

  - platform: rest
    name: Falls pump OnOff
    resource: https://smartcontrol.aquascapeinc.com/external/api/get?token=MyToken2&v1
    method: GET
    value_template: "{{ value_json[0] }}"
    scan_interval: 600

From your previous screenshot it looked like a json result was retrieved. If it is just a single value, you can use:

value_template: "{{ value }}"
1 Like

Correction - I did a restart (rather than reload) and the scan_interval is being used.

@verjager I’m assuming you have used template lights since you were able to help me so much. What did you use to display them on your UI? The Lovelace slider entity row doesn’t seem to be working for me: https://community.home-assistant.io/t/lovelace-slider-entity-row-with-template-lights/638687

Just that one.

type: entities
entities:
  - type: custom:slider-entity-row
    entity: light.bedroom

@verjager then I’m definitely doing something wrong with that too. If you have any free time, would you mind taking a look at https://community.home-assistant.io/t/lovelace-slider-entity-row-with-template-lights/638687/6 to see if you can see what I’m doing wrong with the slider bar? I can change the brightness on a regular light slider bar but not my template light.