I don’t know if you’ve seen it, but in the Gladys GitHub repository, there is an export of the Insomnia Core software that allows you to test requests on the Gladys API.
Once the software is installed and the export file is imported into Insomnia, you just need to change the environment variables once to change the URL of your Gladys server.
Then you just need to log in via Insomnia (User → login) with the credentials/password of your Gladys admin to retrieve an access token (access_token) that you can go modify in the environment variables again.
This access_token will be useful once logged in via Python to make your REST calls.
Hello @Ook! For now, the Gladys 4 REST API is more for « internal » use within Gladys. There is not yet a long-term token mechanism to use the API externally (with an API key).
This is, however, a planned development, which is listed here:
You can vote for the feature if you want to see it in Gladys
Out of curiosity, why would you like to use the API externally?
In the meantime, two possibilities
1) The MQTT API
If you want to send new device values, you can use the Gladys MQTT API (more explanations in the documentation), which is the cleanest option, in my opinion
2) Use a « user » token as if you were the frontend
If you really want to use the API in a script before API tokens are available, you can use the login flow in your script to retrieve an access_token and a refresh_token, then call the Gladys API with an access_token in the « Authorization » header.
It’s less clean than using future API keys, but it gets the job done in the meantime
My goal is twofold: I’m working on a voice recognition and synthesis script, and I wanted to run a scenario (basically turn everything off when leaving).
Secondly, for educational purposes, as I’m learning Python mostly on my own and have already managed to consume a REST API from a software at my job, and I want to try with another one to get used to this technology.
So I think the front-end equivalent would suit me.
Otherwise, I’ll tinker with MQTT if I can send a presence departure indicator… Thanks for the info!
Hello, I’m following up on the topic to ask a question I haven’t found the answer to. Is it possible to retrieve electricity consumption information from a smart plug via the API, or is this not possible? Thanks in advance.
Hello @desdamo, do you want the instant consumption or consumption history?
Be careful, there is no API key mechanism in Gladys 4 yet (planned but still under development), so the API can only be consumed « as if your script is the frontend ».
If you want instant (and if your outlet reports consumption information of course), you can access the consumption via this GET I think: Gladys Assistant REST API documentation
Hello @pierre-gilles, I want to retrieve via a front-end the consumption of several connected outlets. No snapshot as I want to know the average consumption for the week or day. Is this possible?