dxdc/homebridge-blinds

Get blind state via webhook

Closed this issue · 7 comments

Hello!
In order to be able to control some internal device depending on blind state (up or down), I would like to be able to know via the webhook the state of a given blind. This is to stop some internal network device by asking via webhook in case the blind is down.

I am asking this because my Somfy blinds to not have position_url system so I am not able to use the URL "http://192.168.1.40:51828/?pos=00" to do what I want.

Or is there a simple way with ?pos even if I have no position_url? Or would this require some dev for you to export simple up/down statesvia webhook?

Many thanks in advance!

dxdc commented

@genfersee it sounds like you want the state reported by homekit, is that right? I'm not totally sure I understand the purpose of your request though?

This is to stop some internal network device by asking via webhook in case the blind is down.

I didn't understand that. If you want the position reported by homekit, you can grab the states from homebridge directly:

curl -X PUT http://127.0.0.1:51826/accessories --header "Content-Type:Application/json"

Where 51826 should be replaced by your port number, and 127.0.0.1 should be replaced by your IP. It doesn't make sense to replicate the feature here I don't think.

Also, per your suggestion, pos=0 is a valid position request so we can't use that to interpret the current position. One idea would be to use a webhook and reply with the current position if the user reports an invalid position (suppose -1). Not sure this is exactly ideal either.

You will have to find your device in here. jq can be a useful tool to parse/filter the JSON.

Btw, there is another way you can do this all which is with NodeRED and node-red-contrib-homebridge-automation. You can pull the state of any device whenever you want and do anything you'd like with the information. Very powerful.

https://github.com/NorthernMan54/node-red-contrib-homebridge-automation

@dxdc thank you so much for your detailed answer, I did not know about this way to get accessories info with curl!

Is there a way to only get the info of a given accessory (aid)?

My usecase is the following: I have a webcam behind a blind. I want to modify my webcam script to check if blind is down. If blind is up, webcam will take a picture. If blind is down, webcam script will prevent to take a picture :-)

dxdc commented

Is there a way to only get the info of a given accessory (aid)?

Yes. Look into jq

You can just pipe your curl response, e.g.

curl ..... | jq ......

My usecase is the following: I have a webcam behind a blind. I want to modify my webcam script to check if blind is down. If blind is up, webcam will take a picture. If blind is down, webcam script will prevent to take a picture :-)

Thanks for the clarification. So, I think the curl request is the way to go then. Either that, or you can try the NodeRed route, and move your 'webcam' script to be entirely managed inside of NR!

So I will have to parse this big JSON file... many thanks for your help, I will give a try!

I managed to get the blind status value!
curl -s -X GET http://my_ip:my_port/characteristics?id=my_aid.my_iid | jq '.[] | .[] | .value'

dxdc commented

Forgot you could directly query by aid/iid. Great!

Now fully implemented and working! Many thanks again for the tip!