How to debug RESTful sensor value

Hi!

I’m trying to get some data from Smoobu web API to show if a room is occupied or not. The result of a call is this:

{
    "page_count": 0,
    "page_size": 25,
    "total_items": 0,
    "page": 1,
    "bookings": []
}

So I created the entry in the configuration to read the value of “total_items”, always on today

sensor:      
  - platform: rest
    name: "Room 1 occupied"
    resource: "https://login.smoobu.com/api/reservations?apartmentId=123456&from={{now().strftime('%Y-%m-%d')}}&to={{now().strftime('%Y-%m-%d')}}&showCancellation=false"
    value_template: "{{ value_json.total_items }}"
    force_update: true
    scan_interval: 60
    headers:
      API-key: MyApiKey

The problem is that in Lovelvace I always see value “1”. If I check the same thing via POSTMAN, I get total_items: 0.

My questions are:

  1. Have I built a wrong configuration for the sensor? Why it’s always “1” ?
  2. Is possible to see what HA is sending as the request to see how the webapi is called?
  3. When is the sensor updated? I added force_update, but I don’t know if it’s needed.

Smoobu API documentation: https://docs.smoobu.com/#get-bookings-api

I fount some error reporting in the log

2021-01-25 02:45:04 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.soba_1_zasedena is taking over 10 seconds
2021-01-25 02:45:04 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: https://login.smoobu.com/api/reservations?apartmentId=123456&from={{now().strftime('%Y-%m-%d')}}&to={{now().strftime('%Y-%m-%d')}}&showCancellation=false failed with

Is there a way to get the information that is missing (see the end of the error - “failed with”) ?

I used the same method (I just fille the date from/to) in Postman and it worket perfectly in 1 second.

Could be that I use Homeassistant without SSL (https) and calling a https site?

The URL includes “login”, do you have to log in in order to see the values.
That could make it fail.

No, there is no need for login (the URL is a bit misleading, yes…). I pasted the URL in PostMan, added the APIkey (same as in the YAML sensor definition) and it works

No one…? :slight_smile:

Hi ZippoSLO Marko,

could you find a solution and could get it up and running?
Im looking for the same solution with my smoobu.

Thank you and best Regards, Rainer

Yes I did, I added this to the configuration.yaml. Set the variables in {brackets}. You need the apartnent ID ind the API key, both from Smoobu.

binary_sensor:
  - platform: rest
    name: "Soba 1 zasedena"
    resource_template: https://login.smoobu.com/api/reservations?apartmentId={ID in Smoobu}&showCancellation=false&from={{ now().strftime('%Y-%m-%d') }}&to={{ now().strftime('%Y-%m-%d') }}
    value_template: '{{value_json.total_items > 0}}'
    force_update: true
    scan_interval: 3600
    device_class: occupancy
    verify_ssl: false
    headers:
      API-key: {smoobu API key, configure in Smoobu}
      Cache-Control: no-cache

i get no values… :frowning:

binary_sensor:
  - platform: rest
    name: "Frohsinn"
    resource_template: https://login.smoobu.com/api/reservations?apartmentId={1234567}&showCancellation=false&from={{ now().strftime('%Y-%m-%d') }}&to={{ now().strftime('%Y-%m-%d') }}
    value_template: '{{value_json.total_items > 0}}'
    force_update: true
    scan_interval: 3600
    device_class: occupancy
    verify_ssl: false
    headers:
      API-key: '{abc1111222233334444555666xyz}'
      Cache-Control: no-cache

Api key - no brackets, no quotes.

Check te logs for errors.