goedh452 / homebridge-http-sprinkler

Homebridge http controlled sprinkler
Apache License 2.0
12 stars 6 forks source link

Partially incompatible to RainMachine #9

Closed pmuehlstein closed 5 years ago

pmuehlstein commented 5 years ago

Hey there, I'm using the RainMachine Mini 8 with your plugin and ran into problems. Status polling works well. Turning off zones is working too. But the RainMachine API does not allow to simply turn on a zone with a url. It needs a specified running time in the body of the http request.

Have a look at the RainMachine Apiary https://rainmachine.docs.apiary.io/#reference/zones/zoneidstart/post

I would set the time to 3600 seconds, because the plugin will turn the sprinklers off after the specified/default time, right? Any thoughts on how to send the time with the http request for the "on" command?

goedh452 commented 5 years ago

Hi, my plugin is indeed not compatible with the rainmachine. Would it be possible for you to just clone my plugin and modify to your needs?

pacco788 commented 5 years ago

Thank you for your quick reply. Unfortunately I'm not familiar with Javascript. My idea was to add the required body tag { "time": 60 } somewhere to the setPowerState (on) function. But I don't know how to to this...

goedh452 commented 5 years ago

If I look at the documentation the syntax is quite different than a single url. It expects a call with a json body. It is quite some work to implement that. If you have a single url that will start the rainmachine I can give it a try. In that case, please sent me the start url.

pacco788 commented 5 years ago

Sorry, I don't have a single url. If you could do this within a few minutes i would be pleased if you could help me. Maybe the curl command to start the zone may help you to understand which steps are necessary: curl POST -d '{"time": 3600}' http://rainmachine_ip:8081/api/4/zone/3/start?access_token=myaccesstoken

Please don't waste too much time on that! Learning JavaScript is something I always wanted to do ;)

pacco788 commented 5 years ago

Ok, i have a little workaround to make it work.

In the RainMachine UI I have made 5 new programs for 5 zones (every zone gets an own program) with 60 minutes of running time each and set them "Inactive". The programs are still manually executable, but don't run by schedule. You can run the programs by setting the config.json to

    {
      "accessory": "HttpSprinkler",
      "name": "Sprinkler Zone 1",
      "icon": 1,
      "onUrl": "https://rainmachine.ip:8080/api/4/program/1/start?access_token=_your_access_token_",
      "offUrl": "https://rainmachine.ip:8080/api/4/zone/1/stop?access_token=_your_access_token_",
      "timeout": 3000,
      "checkStatus": "polling",
      "pollingInterval": 5000,
      "statusUrl": "https://rainmachine.ip:8080/api/4/watering/zone?access_token=_your_access_token_",
      "jsonPath": "zones[0].state",
      "onValue": "1",
      "offValue": "0",
      "useTimer": "yes",
      "defaultTime": 900
    },

In the onURL you have to place the program number that will start the zone right after "program/", in the offURL you have to place the zone number right after "zone/"and the number in jsonPath is zone number minus 1: for zone 1 its "zones[0].state", for zone 2 its "zones[1].state"...

The index.js of the plugin needs a little modification. Just change the HTTP method in the setPowerState and setPowerStatePolling from GET to POST. Don't know if the change in the setPowerStatePolling area is really necessary, but it works ;)

goedh452 commented 5 years ago

So do I understand correctly that you’ve got it working now? Or do I need to modify anything in the code?

The method GET or POST can be set with a variable also. See the readme how to do that.

pacco788 commented 5 years ago

Yes, that's correct, its working now. No need for further modification.

I've already added "httpMethod": "POST" in the config.json, but that didn't work as expected. Is the HTTP method really a variable in your code? As already mentioned before im not familiar to JavaScript, but I have found the variable just once in the index.js in the "Get config info" section. It seems to be unused in the further code. Please have a look at it. Maybe it will make it a bit more compatible with other controllers :-)

goedh452 commented 5 years ago

Great you’ve got Ik working. I’ll have a look at the http method. Not worth anything when it is only mentioned in the config :-)