QuickSander / homebridge-http-curtain

Homebridge plugin to operate web based/http curtains with push position updates.
Other
2 stars 3 forks source link

Need ReGex for setter Please #18

Closed GevaudanBeast closed 2 years ago

GevaudanBeast commented 2 years ago

Hello,

I would like to ask you for a small change in order to make my roller shutters work.

My home automation API needs to be able to receive (SETTER) with a body request.

Here is an example to determine the desired position of a roller shutter: http://xxx.xxx.xxx.xxx/api/core/ana/196642?ApiKey=xxxx&option=filter_state

Method: PUT

Request body (your "%d"): {"value":xxx}

Can you add that please?

Thank you!

QuickSander commented 2 years ago

Hi,

Do you desire a HTTP body that eventually requests the curtain to move to a certain position? Or a getter to retrieve the current position (your issue title and text conflict a bit).

If you need a setter, I don't think you will need a RegEx, but just a simple %d replacement for the body. The body itself can already be specified using the URL object.

I will look into this once I have some time this week.

GevaudanBeast commented 2 years ago

Hello, Indeed I made a mistake in the title, it is indeed the "setter" part of which I wish an improvement. You are right, I don't need ReGex, but to be able to move the "%d" in the body: {"value":%d} A big thank you if you have the possibility to do it, because I am unable to develop my own code...

GevaudanBeast commented 2 years ago

Hi, In the meantime, I am preparing your future update. Does that sound right to you? Thx

       {
            "name": "Porte",
            "notificationID": "X4VR3-4",
            "getCurrentPosUrl": {
                "url": "http://xxxx/api/core/ana/196642?ApiKey=xxxx&option=filter_state",
                "method": "PUT"
            },
            "getCurrentPosRegEx": "^.+?\\\"value\\\"\\\\s*:\\\\s*(\\\\d+).*$",
            "setTargetPosUrl": {
                "url": "http://xxxx/api/core/ana/196638?ApiKey=xxxx&option=filter_state",
                "method": "PUT",
                "body": "{\"value\":%d}"
            },
            "accessory": "HttpCurtain"
        }
QuickSander commented 2 years ago

Sounds about right. Sorry I did not change it yet, but I certainly will somewhere the coming days.

GevaudanBeast commented 2 years ago

Thx you, I have a error message : [2/19/2022, 13:08:25] [Fenêtre] Your CurrentPosRegEx regular expression: "^.+\"value\"s*:s*(d+).*$" did not match any part of the returned body: "{"_id" :196623,"value":20}"

CONFIG :

        {
            "name": "Fenêtre",
            "notificationID": "X4VR1-1",
            "getCurrentPosUrl": {
                "url": "http://xxxx/api/core/ana/196623?ApiKey= xxxx&option=filter_state",
                "method": "GET"
            },
            "getCurrentPosRegEx": "^.+\\\"value\\\"s*:s*(d+).*$",
            "getPositionStateUrl": {
                "method": "GET"
            },
            "setTargetPosUrl": {
                "url": "http://xxxx/api/core/ana/196619?ApiKey= xxxx&option=filter_state",
                "method": "GET"
            },
            "getTargetPosUrl": {
                "method": "GET"
            },
            "getTargetPosRegEx": "^.+\\\"value\\\"s*:s*(d+).*$",
            "identifyUrl": {
                "method": "GET"
            },
            "accessory": "HttpCurtain"
        }
QuickSander commented 2 years ago

Your regEx contains an error. Can you simplify it to:

\"value\"s:s([0-9]+)

GevaudanBeast commented 2 years ago

Thank you that seems work better :)

QuickSander commented 2 years ago

Hi,

Please try the new release with body setter %d support: v1.5.0.

GevaudanBeast commented 2 years ago

I try, just few minute.

GevaudanBeast commented 2 years ago

I just tested for one of my shutters, it seems to work. There is just the loading wheel in Home app which turns continuously

GevaudanBeast commented 2 years ago

Many thanks for your work. I allow myself to share your plugin on the forum where I participate so that others can use it (https://forum.gce-electronics.com/t/tuto-ipx800-v5-homebridge/14713). By any chance, have you developed a thermostat plugin using body requests?

QuickSander commented 2 years ago

I just tested for one of my shutters, it seems to work.

There is just the loading wheel in Home app which turns continuously

I don't think you need the notificationId as I think your curtain doesn't send updates by itself to homebridge? If I am right you want to instead poll the curtain position with the pullInterval config setting. This should fix your continued rotation ik HomeKit. This is because HomeKit is waiting until the targetPos matches the currentPos. Without an update push this never happens.

GevaudanBeast commented 2 years ago

Perfect, thank you !!!