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”}