ZippoSLO
(Marko)
January 23, 2021, 12:00pm
1
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:
Have I built a wrong configuration for the sensor? Why it’s always “1” ?
Is possible to see what HA is sending as the request to see how the webapi is called?
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
ZippoSLO
(Marko)
January 25, 2021, 7:33am
2
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?
Hellis81
(Hellis81)
January 25, 2021, 7:37am
3
The URL includes “login”, do you have to log in in order to see the values.
That could make it fail.
ZippoSLO
(Marko)
January 25, 2021, 8:18am
4
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
rainer99
(rainer99)
March 18, 2024, 5:28pm
6
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
ZippoSLO
(Marko)
April 10, 2024, 8:26pm
7
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
noxx
(Ralf B)
September 13, 2024, 11:30am
8
i get no values…
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
ZippoSLO
(Marko)
September 16, 2024, 11:20am
9
Api key - no brackets, no quotes.
Check te logs for errors.