Homeassistant sensor, Bash-script with curl and json

jonrub11

n3wb
Dec 13, 2018
18
0
Sweden
Hi,

I am trying to create a sensor for Homeassistant so I can see which BlueIris profile is active for the moment.

I have created a bash-script for the json commands but I am stuck, it wont log me in.

# Ask about sessionkey and add it to $sessionkey
sessionkey=$(curl --header "Content-Type: application/json" --request POST --data '{"cmd":"login"}' http://192.168.1.205:81/json | jq -r '.session')
# create responsekey
responsekey=$(echo -n username:$sessionkey:password | md5sum)
# Log in via json
curl --header "Content-Type: application/json" --request POST --data '{"cmd":"login","session":'"$sessionkey"',"response":'"$responsekey"'}' http://192.168.1.205:81/json

Any ideas?

Thanks in advance!
 
Does the response key look like a simple hex string? It might not matter but I know UI3's login code produces lower-case abcdef characters.

Are you able to capture the network traffic being sent and received?
 
Sorry for late reply.

Yes, I have tested with wireshark and the result is in the attached image. I think the spaces is just how Wireshark displays it but what could be the problem is the dash (-) at the end.
What do you think? I have no idea how to remove it.

Thanks!
 

Attachments

  • wireshark.png
    wireshark.png
    6.3 KB · Views: 25
And when I solved that problem I got a new one. :)

Now it works as I want when I run each line one by one. When I put them in a bash-script, everything after a pipe (|) prints on a new line.
 
And when I solved that problem I got a new one. :)

Now it works as I want when I run each line one by one. When I put them in a bash-script, everything after a pipe (|) prints on a new line.
Share/post/attach the relevant portion of your BASH script (as a .txt text file) and I'll try to help.
 
Thank you for your willingness to help. I actually solved the problem by running all commands on the same line separeted with ; .