dxdc / homebridge-blinds

:sunrise: Homebridge Plugin to control my blinds over HTTP
https://www.npmjs.com/package/homebridge-blinds
ISC License
54 stars 26 forks source link

position_jsonata not working #56

Closed alexkoenigs closed 2 years ago

alexkoenigs commented 3 years ago

In my setup, jsonata doesn't seem to work as intended, as changes not made through homebridge don't reach homebridge. Please have a look at the following screenshots explaining my issue. This first one shows the logs, where a position of 64% is requested but the openLevel returned shows that the blinds are actually at 21%.

CleanShot 2020-12-28 at 13 03 34@2x

This following screenshot shows my setup, which should find the "openLevel" in the returned JSON. Please let me know where I'm missing something.

CleanShot 2020-12-28 at 13 07 45@2x

If you need anything else to help please let me know. Thank you

dxdc commented 3 years ago

Hi @alexkoenigs, I don't see any issue with your jsonata. However, a few comments:

Does the position eventually self-correct to 21?

I'm wondering if it would be helpful to fetch position_url once before asking the blinds to move, to ensure they were at the desired starting position. Any more information you're able to share would be helpful as well.

alexkoenigs commented 3 years ago

Hi, Thanks for the reply!

  1. regular polling would definitely be a big win, as blinds/shutters tend to be one of those things not solely controlled through HK but through physical buttons on the wall.
  2. I don't see an issue with my up/down time tbh, as it's in milliseconds and my use case are roller shutters which actually take about half a minute to move up or down.
  3. I've not tested to wait longer for it to self update, is there anything that might trigger it to fetch the position? or is it just a waiting game atm?
  4. fetching the actual position (position_url) before sending a move command would indeed be a very good idea! And probably not too hard to implement either. Having a configurable interval for fetching would still be a very welcome addition as well though.

If HomeKit blind status and real blind status align before issuing a command, it works perfectly. But in those cases of moving the shutters through other means than HomeKit, it breaks.

If there's anything else you'd like to see/know please feel free to ask.

alexkoenigs commented 3 years ago

Will test the eventual updating though and reply again here in about 15-20 minutes with the results.

dxdc commented 3 years ago

fetching the actual position (position_url) before sending a move command would indeed be a very good idea! And probably not too hard to implement either. Having a configurable interval for fetching would still be a very welcome addition as well though.

Yes have been thinking about this approach also.

I've not tested to wait longer for it to self update, is there anything that might trigger it to fetch the position? or is it just a waiting game atm?

It's up to HK how often to poll. That's why I'm thinking of the above approach for your use case.

Try force quit the Home app on your phone/tablet, and relaunch going to the pane where your blinds are. It should force the position to be re-polled. If that is working, then probably we need to do 2 things:

alexkoenigs commented 3 years ago

Force restarting the app does not update the status. I've tested with both Home and Elgato Eve. Setting "verbose" = true shows that homebridge should be aware of the status, but still both apps show no change.

dxdc commented 3 years ago

Thanks @alexkoenigs. Polling may just be the main / best way to do it. Can you post the logs though so I can see?

Also, if you restart homebridge, does the position update?

alexkoenigs commented 3 years ago

Logs after restarting Homebridge and force reopening Home App:

CleanShot 2020-12-28 at 21 20 08@2x

Position still not updated though, Apps show shutters closed completely close which was last HomeKit action performed like 2h ago. rolled up the shutters without homekit 20 minutes ago now and even restarting apps and homebridge no change to status "blinds closed" in apps.

dxdc commented 3 years ago

@alexkoenigs there is still something strange here:

With verbose: true, there should still be a line like:

Requested setCurrentPositionByUrl...

which I'm not seeing in your logs. Can you also post the results of:

curl http://192.168.0.3/ocf/wlss9/openLevel

dxdc commented 3 years ago

(Also, please check both standard and also error logs)... sometimes they are in different files.

alexkoenigs commented 3 years ago

I'll need another hint about what you mean by both logs. Homebridge? Your plugin? Please let me know where I can find the ones you mean.

But anyway: This is the beautified result of requesting http://192.168.0.33/ocf/wlss9/openLevel

CleanShot 2020-12-30 at 00 10 56@2x

openLevel is at 0 right now as blinds are closed (it's around midnight over here in Europe)

dxdc commented 3 years ago

I'll need another hint about what you mean by both logs. Homebridge? Your plugin? Please let me know where I can find the ones you mean.

It's the homebridge logs (the plugin just logs to homebridge). Everything looks normal, but strange it is not showing the position request.

alexkoenigs commented 3 years ago

Right, but I can't find anything about separate standard and error logs. If you tell me where to find those error logs I'll make sure to send them your way

dxdc commented 3 years ago

How do you run homebridge? If you use pm2, for example, could be:

/home/pi/.pm2/homebridge-out.log and /home/pi/.pm2/homebridge-error.log. It 100% will depend on your configuration/setup.

alexkoenigs commented 3 years ago

I'm running oznu/docker-homebridge. I just scanned through my entire homebridge directory, found the regular logs, which show just the same that I sent you. There doesn't seem to be separate error logs.

alexkoenigs commented 3 years ago

And by the way, let me tell you I'm already amazed by how invested you are in helping me. Not to bribe you or anything but I'm definitely sending a few bucks your way when we finally get this working.

dxdc commented 3 years ago

@alexkoenigs appreciate your support!

I'm not sure about docker logs for homebridge. One simple thing you could try is modifying your open/close/position_url to something wrong (like http://google.com/asdf) and see if you can get that error to show up when you start hb.

It will be in some log, just not sure if it's your primary one or not.

dxdc commented 3 years ago

You can see logs from another user here, which show how it should look:

https://github.com/dxdc/homebridge-blinds/issues/31

I'm just wondering if there is some error being triggered by your position_url somehow. Even simple things like JSON being reported with extra symbols or so could break jsonata parsing.

alexkoenigs commented 3 years ago

Oh yeah errors in general show up in those logs. Had a broken plugin the other day and that was spamming my logs with error messages until i yote it.

Well also I just noticed you said that you expected setCurrentPositionByUrl to show up somewhere, but I'm not sure it should, as I don't set my position using a parameter in the URL.

alexkoenigs commented 3 years ago

The thing is: My rollers' API is weird, so I can get the current position but I cannot set a target position that way. So for setting it all I can do is use your plugins' timing, but I could verify that the position is correct afterwards by requesting it

dxdc commented 3 years ago

Well also I just noticed you said that you expected setCurrentPositionByUrl to show up somewhere, but I'm not sure it should, as I don't set my position using a parameter in the URL.

Using position_url will trigger that. It should still be compatible w/ your use case. I need to do some refactoring of the plugin in general and implement some testing as well. It's on the list of to-do's just haven't gotten there yet...

In the meantime, you can also try editing the source to add some logging in places and try and figure out where it's struggling. The automated tests will be helpful to catch other issues though.

alexkoenigs commented 3 years ago

Yeah unfortunately no time for that :D I can squeeze in a bit of tinkering with Homebridge but that's really about it then. Please do let me know if you get around to addressing this at some point tho! I'll be waiting patiently :)

dxdc commented 3 years ago

@alexkoenigs I've been quite busy, but I just implemented polling which I think may fix your issue.

Basically, as long as the blind movement wasn't triggered by HK, it will self-correct the setting in the plugin. Can you please enable verbose as well for the settings, and let me know how this works for you? I'm curious especially to see the logs.

sudo npm install -g homebridge-blinds@1.3.25-beta.3
# restart homebridge