Brandawg93 / homebridge-fordpass

Control your Ford vehicle in HomeKit using Homebridge.
GNU General Public License v3.0
62 stars 15 forks source link

OccupationSensor which is triggered when the car is plugged to a power supply socket #190

Closed y-mishchenko closed 2 years ago

y-mishchenko commented 2 years ago

Hi, I have an outdoor power socket. The socket is disabled by default as I do not want strangers to use it. I only enable it when I plug my car into it. Currently I need to remember to do that. Instead I can create an automation which enables the socket when the car reports that it is plugged.

It seems to work for my Kuga 2021 (in Germany). So perhaps it might be helpful for other people like me.

Regards, Yury.

Brandawg93 commented 2 years ago

This doesn't seem to connect to the Ford api?

y-mishchenko commented 2 years ago

This doesn't seem to connect to the Ford api?

How do you mean? I have simply checked the JSON which your code gets from the API and noted this section:

"chargingStatus":{ "value":"NotReady", "status":"CURRENT", "timestamp":"07-10-2022 16:21:24" }, "plugStatus":{ "value":0, "status":"CURRENT", "timestamp":"07-10-2022 16:21:24" },

So my code simply uses what is already available.

Brandawg93 commented 2 years ago

Ah. I see. So when the vehicle is charging, it enables the occupancy sensor. Have you tried with the programmable switch? It is in the latest version. 98b17ca84e71f4eaadc2e0e909b42701160a1c3c

y-mishchenko commented 2 years ago

The programmable switch does not work for me as it never gets into "ChargingAC" state because my power socket is disabled. I have made my sensor to be controlled by the same configuration switch (the one which enables the programmable switch).

In other words I need to differentiate between: "plugged" and "charging". My car can be plugged but not charging (as the socket is disabled).

Brandawg93 commented 2 years ago

Interesting! I'll play around with this and get back to you if I have any questions. Thanks for the PR!

Brandawg93 commented 2 years ago

@y-mishchenko, I made a few changes to the PR. Namely, I like your implementation of the occupancy sensor better than the programmable switch, so I converted the charging switch to that as well. And of course Ford broke some other API calls, so I fixed those here as well.

Let me know if this works for you and I'll merge it into master.

y-mishchenko commented 2 years ago

@Brandawg93, this works for me, thank you!

y-mishchenko commented 2 years ago

@Brandawg93 , I have just tried the latest changes. I does not work for me. It fails while adding accessory. I have added a debug message which prints the vehicle JSON. As you see it does not contain either the nickName nor the model

[7/24/2022, 11:46:32 PM] [FordPass] Add vehicle : { "VIN": "W****", "nickName": "", "tcuEnabled": true, "isASDN": false }

(node:2131) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: Accessories must be created with a non-empty displayName. at new Accessory (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Accessory.ts:421:11) at new PlatformAccessory (/usr/local/lib/node_modules/homebridge/src/platformAccessory.ts:70:9) at FordPassPlatform. (/usr/local/lib/node_modules/homebridge-fordpass/src/index.ts:278:25) at Generator.next () at /usr/local/lib/node_modules/homebridge-fordpass/dist/index.js:8:71 at new Promise () at __awaiter (/usr/local/lib/node_modules/homebridge-fordpass/dist/index.js:4:12) at /usr/local/lib/node_modules/homebridge-fordpass/src/index.ts:272:56 at Array.forEach () at FordPassPlatform. (/usr/local/lib/node_modules/homebridge-fordpass/src/index.ts:272:15)

Brandawg93 commented 2 years ago

That could be a cache issue. I changed the vehicle details api call because the other one is always down for some reason.

y-mishchenko commented 2 years ago

@Brandawg93 , There were few issues , I have committed some changes: Generate accessory name in the "old" style: "[year] Ford [model]" There was a bug in getVehicles: array elements are not updated by assigning new values to the loop variable Services were registered by name via FordAccessory which added accessory name to the service ID, so homebridge native getServiceById did not work