Hey there! This is more a beginner question, not a program expert but I hope someone can help:
I try to get the state of an entity with an curl command. I use Keyboard Maestro on my Mac, where I can execute Shell scripts. I found on the REST API docs the command:
curl -X GET -H "x-ha-access: Password" -H "Content-Type: application/json" http://IPAdress:8123/api/states/media_player.schlafzimmer
which works fine, no problem. The thing is I just want to get one specific attribute from the result (âmedia_album_nameâ) - Do I have to add something on that curl command?
I donât think the api or curl will let you get specific attributes, you need to do some post processing of the result from curl. jq is a unix command line that enables you to parse the json output from curl, like
I donât know if jq is available by default on a mac, but its home page is here. If not, you can probably implement a filter with grep, but thatâs going to be more work.
Ok, looks like you already have a solution. Cool! But since I already went through the effort, Iâll go ahead and reply. Maybe someone else could use this infoâŚ
If you wanted to do it with grep, you could use this:
Or, you could use the jq command that @gpbenton mentioned. (Thanks gpbenton, didnât know about it. Very cool! And itâs available for Linux on rpi - âsudo apt-get install jqâ):
Look in the abbusage_ha.sh - that one just sets up auth.
It creates one sensor that has a bunch of attributes. Thereâs a screenshot of it. (You could create multiple sensors)
The json file it pulle looks like this:
{âusedMbâ:265358,âdownloadedMbâ:228091,âuploadedMbâ:37268,âremainingMbâ:null,âdaysTotalâ:31,âdaysRemainingâ:20,âlastUpdatedâ:â2019-05-17 19:32:04â}