mandarons / ha-bouncie

Home Assistant custom integration for Bouncie.com - track your car stuff in Home Assistant
BSD 3-Clause "New" or "Revised" License
30 stars 4 forks source link

[FEATURE] MIL Event code support #10

Open 29w211barnes opened 1 year ago

29w211barnes commented 1 year ago

Use case I would like to be able to have home assistant be able to react to MIL status codes.

Describe the solution you'd like Expose the status codes returned by a MIL event as an attribute that would be accessible in scripts, automations, or as template values in a card. If possible it would be nice to have them as separate list items, but using template .split(',') should be fine as well.

Additional context The bouncie API docs shows a MIL event that looks like:

{
    "eventType": "mil",
    "imei": "359486064322553",
    "vin": "5J8YD4H37JL001743",
    "mil": {
        "timestamp": "2019-07-01T15:22:56.000Z",
        "value": "ON",
        "codes": "U1126, P0303"
    }
}

I recognize that this will be very hard to test w/o a vehicle that is currently reporting codes.

Right now I can get the MIL last updated using:

{{ state_attr('sensor.escape_car_mil', 'mil_lastupdated') }}

I envision codes to be similar:

{{ state_attr('sensor.escape_car_mil', 'mil_codes') }}
mandarons commented 1 year ago

MIL codes are only available over their Webhooks API (Health events). To use their Webhooks API, you will need HA to expose over internet where Bouncie server can reach. Not sure if most of the folks who use this integration will have their HA instance available over internet.

cmaglio commented 1 year ago

I’m only one person, but I would have no problem using webhooks to get this data as I do for other integrations. By exposed, you mean we would have to use our nabucasa address (or other external address) as the return url for the webhook, correct? Perhaps it could be an optional portion of the integration setup process?

cap60552 commented 1 year ago

Interesting, didn't realize that was webhook only.

Personally I would be fine with the nabucasa route. I used to use a webhook for ifttt bouncir integration.

I like the idea of it being an optional item.

mandarons commented 1 year ago

Can you try https://www.home-assistant.io/docs/automation/trigger/#webhook-trigger? It seems that HA allows setting up Webhooks as an automation trigger. trigger.data can be used to process MIL information.

tonygauderman commented 1 year ago

I am pulling it via REST API right now with Node Red.. and actually have a vehicle with a check engine light currently on (just fixed sons car Thursday, now daughters is on..)

This is the JSON response I get when issuing the REST API call (with some items removed obviously like lat/lon, vin, iemi).

Text of MIL code is name, in this case, "EVAP System Pressure Sensor/Switch Circuit Range/Performance"

{"model":
   {"make":"FORD",
     "name":"Escape",
     "year":2015},
     "nickName":"Megan’s Escape",
     "standardEngine":"2.5L I4",
     "vin":"xxxxxxxxxxxxxxxxxxxx",
     "imei":"xxxxxxxxxxxxxxxxxxxx",
      "stats":
           {"localTimeZone":"-0600",
            "lastUpdated":"2023-01-13T22:02:27.000Z",
            "odometer":63507,
            "location":
                  {"lat":xxxxxxxxxx,
                   "lon":xxxxxxxxx,
                   "heading":167,
                   "address":null},
            "fuelLevel":63.576765442923346,
            "isRunning":false,
            "speed":0,
            "mil":
                {"milOn":true,
                 "lastUpdated":"2023-01-13T21:16:46.000Z",
                 "qualifiedDtcList":[{"code":"P0451","name":["EVAP System Pressure Sensor/Switch Circuit Range/Performance"]}]},
            "battery":{"status":"normal","lastUpdated":"2022-01-17T15:21:17.000Z"}}}
mandarons commented 1 year ago

Ohh cool! Thanks for sharing, @tonygauderman. It looks like docs.bouncie.dev is highly incomplete/inaccurate. :(

mandarons commented 1 year ago

If we can get all the possible keys in REST API responses from bouncie folks, that would be great. I can use that for more entities/attributes implementation.

mandarons commented 1 year ago

I will try contacting Bouncie folks to get this information. Let's see if they help. :)

tonygauderman commented 1 year ago

Their documentation seems a little stale, so I relied on it to get started with what I was doing with webhooks, and then REST, but relied on what I was actually getting back to write the rest of my Node Red flow. Got everything I think I needed that way, but it isn't scalable at all, and when I have time am going to move everything over to this integration.. In the mean time, if there is anything I can get for you as far as responses, I have 4 cars with Bouncies, and REST and webhooks both set up. Webhooks didn't work that great for me, because Bouncie gives up pretty easy if it's unable to reach the webhook and marks it inactive without any notification.

mandarons commented 1 year ago

@cap60552 Looks like we can actually get more data than what's documented on Bouncie website, through REST API. I sent a note to Bouncie folks. Let's see.

@tonygauderman can you share all responses that you received from Bouncie REST API that are not documented on docs.bouncie.dev? I will start thinking about how to expose them through ha-bouncie.

tonygauderman commented 1 year ago

I'm only hitting the vehicles API, and all I've seen is in the JSON like I posted earlier. Are you using the user and/or trips API? I could test against those too, but using them right now.

vziukas commented 1 year ago

@mandarons I sent a note to Bouncie folks. Let's see.

I'm a bounce folk, we got your request. First of all thanks for building this integration. I'm an HA user and poked around a little to create this before. I discussed with the developers what we need to improve on docs.bouncie.dev and API responses. The main thing identified are the default values for those properties where we do not have data from the vehicle yet (not those properties not even returned). Do not have an exact estimate on work but changes should be implemented in the next few weeks. I'll post it here once we have the release.

tonygauderman commented 1 year ago

@mandarons I sent a note to Bouncie folks. Let's see.

I'm a bounce folk, we got your request. First of all thanks for building this integration. I'm an HA user and poked around a little to create this before. I discussed with the developers what we need to improve on docs.bouncie.dev and API responses. The main thing identified are the default values for those properties where we do not have data from the vehicle yet (not those properties not even returned). Do not have an exact estimate on work but changes should be implemented in the next few weeks. I'll post it here once we have the release.

Awesome stuff!! Guessing there isn't a ton of 3rd party API use, but it's a neat features, and something I've been dabbling with on my own for a couple years with the webhooks and recently with the REST calls from Node Red.. looking forward to getting off that and not being a user base of 1! Looking forward to more data being available!