Humanity/ShiftPlanning API

Does anyone know if it would be doable and not a really hard exercise for a non-programmer to query the ShiftPlanning/Humanity API to return who is working both TODAY and TOMORROW and dynamically keep that up to date in the front end? Would be a REALLY useful addition to our family life…!
API reference

Should be not that hard… the API returns json which is very easy to process. I may help with that.

Wow thanks @clyra, I’ll get cracking and see what I can manage. Totally new to this!!

Damn. Come unstuck at the first hurdle. I have to authenticate against https://www.humanity.com/oauth2/token.php using the POST method…have been looking at the docs but it seems mostly to relate to authenticating other clients against HASS not the other way around!

This page shows how to do that:

So, the first think your module should do is authenticate himself and get the token. The next request you just pass the token. Take a look on the “requests” python library on how to do the “POST”.

I signed for a free trial and the api integration… We will have to wait.

1 Like

Ah wow - so we’re talking about creating a custom component or similar? Wow, hadn’t realised that…

Maybe it’s possible to do the sensor using the REST component, but I think you have to manually get the token and insert it on the config. Dont know how long the token would still be valid. The custom_component is not that hard.

1 Like

I’m glad you’re confident! :rofl:
Potentially though, it would be useful to many more people than just me. It’s quite a widely used platform.

btw… You have to ask them to use the API. They need some time do that, so my advice is to ask now :).

1 Like

I’ve got API access already - applied yesterday and they granted it same day. It’s the “oh wow, now what?” stage I’m at now…

Got the API access and did basic python code to interface with it. I never used humanity before…Looking at the API, where’s the info you are looking for?

1 Like

Cool!! Thanks
To be honest, I’m not sure WHERE the information is stored within the API, I’ve done some playing and some clicking but couldn’t find what I was looking for. Every time I generated a token, it only seemed to work for one query then became invalid.
I THINK this is the report I’d need? Basically whatever API point shows WHO is scheduled on for today (and also the following day) is what I’m after…

I think i did some progress. You are looking for the “get shifts” call. I will try to publish some code tomorrow so you can test.

I’m sure there’s bugs, but I made a initial version of the sensor. You can get it from my github page here. Doesnt look great…

17

1 Like

WOW!!! Thank you!! So cool! Epic! Really delighted!

So I’m experimenting with a template sensor to split the individuals into separate sensors.
We normally have three people on staff on a given day but on occasion you’ll get a split shift with someone doing half a day and then being replaced at lunch time with another member of staff.

value_template: "{{ states('sensor.humanity_today').split(',')[0] }}"
value_template: "{{ states('sensor.humanity_today').split(', ')[1] }}"
value_template: "{{ states('sensor.humanity_today').split(', ')[2] }}"
value_template: "{{ states('sensor.humanity_today').split(', ')[3] }}"
value_template: "{{ states('sensor.humanity_tomorrow').split(',')[0] }}"
value_template: "{{ states('sensor.humanity_tomorrow').split(', ')[1] }}"
value_template: "{{ states('sensor.humanity_tomorrow').split(', ')[2] }}"
value_template: "{{ states('sensor.humanity_tomorrow').split(', ')[3] }}"

So the above works, but obviously it doesn’t deal with empty values gracefully but maybe there’s no way to improve that. I’m really pleased!!

I knew something like that would happen. My test case was too simple, so I just assumed that a list was enough. I thought about using attributes to split individuals, but I’m not sure. The “hard” work of grab the information is done, now is just a matter of how to show it :-). Why you want to split the shift in individuals? What are you trying to do?

Just out of the blue this morning I get this in my logs and no data for the sensors

Do you think it is likely to be just a temporary glitch on the Humanity side or something I can debug from my side?

Thanks!

hm… not sure. How is your shifts for today/tomorrow on humanity? I have to put a few more debug messages in the code to help with this kind of problem.