kamiKAC / leaf2mqtt

Pull in data from the Nissan Connect platform for the LEAF and publish over MQTT
GNU General Public License v3.0
7 stars 5 forks source link

No stats data fetched with Leaf2MQTT #19

Closed hmfssantos closed 3 months ago

hmfssantos commented 3 months ago

Describe the bug During the regular fetch operation to retrieve the data from NissanConnect, there are no values for the Stats (Daily and Monthly). I'm using V0.0.3, having started only a couple of days ago to use this code. However, when I publish the command through the MQTT integration "leaf/command/stats/daily" with payload "update" I receive the desired string of data.

LEAF_TYPE newerThanMay2019

Expected behavior Include the string for the stats together with the rest of data (cockpit, climate, battery and location)

kamiKAC commented 3 months ago

Hi Looking in the code here shows that MQTT update message in topic leaf/{vin}/command fetches:

To check this fix use docker image kamikac/leaf2mqtt:edge (note that this is temporary tag). If this fix works for you please give some feedback so I will release it.

Best Regards Marcin

hmfssantos commented 3 months ago

Hey Marcin,

Thanks a lot for such a fast support on this query. I'm newbee to all this stuff. Currently, I'm able to fetch all the data regarding Battery Status, Climate Status, Location, Cockpit Status. With that, I can add sensors to display the information I need in my dashboard. What is missing is that I'm not able to get any data from the stats topics (daily or monthly) such as this one:

FINEST: 2024-05-28 23:44:17.581608: MqttClientWrapper: Publishing message SJNFAAZE1U0123456/battery/percentage 83

I can only get the data when I go to the MQTT settings integration and manually publish a packet:

Topic: leaf/command/stats/daily Payload: update

And then, I'm able to fetch the topic:

Message 1 received on leaf/stats/daily/json at 11:59 PM: {"targetDate":"2024-05-28 00:00:00.000","travelTimeHours":"1","travelDistanceMiles":"53","travelDistanceKilometers":"85","milesPerKwh":"4.51","kilometersPerKwh":"7.26","kwhUsed":"11.71","kwhPerMiles":"0.22","kwhPerKilometers":"0.14","tripsNumber":"4","kWhGained":"3.40","lastReceivedDateTimeUtc":"2024-05-28T22:58:46.786398Z"}

Looking to the code you highlighted, I wonder if this issue could be fixed if you add the two last lines to this section of the code:

fetchAndPublishBatteryStatus(mqttClient, vin),
fetchAndPublishClimateStatus(mqttClient, vin),
fetchAndPublishLocation(mqttClient, vin),
fetchAndPublishCockpitStatus(mqttClient, vin),
fetchAndPublishDailyStats(mqttClient, vin),
fetchAndPublishMonthlyStats(mqttClient, vin)

Does this makes sense? I hope I'm not messing everything up with my lack of knowledge...

Many thanks in advance for your support.

Regards, Hugo

hmfssantos commented 3 months ago

Some additional information. gathered from the log. Subscribing to the stats/daily and stats/monthly, but not fetching+publishing the result for these:

FINE: 2024-05-28 11:50:53.784295: MqttClientWrapper: Subscribing to SJNFAAZE1U0123456/command FINE: 2024-05-28 11:50:53.784421: MqttClientWrapper: Subscribing to command FINE: 2024-05-28 11:50:53.784461: MqttClientWrapper: Subscribing to SJNFAAZE1U0123456/command/battery FINE: 2024-05-28 11:50:53.784485: MqttClientWrapper: Subscribing to command/battery FINE: 2024-05-28 11:50:53.784523: MqttClientWrapper: Subscribing to SJNFAAZE1U0123456/command/climate FINE: 2024-05-28 11:50:53.784571: MqttClientWrapper: Subscribing to command/climate FINE: 2024-05-28 11:50:53.784612: MqttClientWrapper: Subscribing to SJNFAAZE1U0123456/command/stats/daily FINE: 2024-05-28 11:50:53.784641: MqttClientWrapper: Subscribing to command/stats/daily FINE: 2024-05-28 11:50:53.784663: MqttClientWrapper: Subscribing to SJNFAAZE1U0123456/command/stats/monthly FINE: 2024-05-28 11:50:53.784700: MqttClientWrapper: Subscribing to command/stats/monthly FINE: 2024-05-28 11:50:53.784728: MqttClientWrapper: Subscribing to SJNFAAZE1U0123456/command/location FINE: 2024-05-28 11:50:53.784750: MqttClientWrapper: Subscribing to command/location FINE: 2024-05-28 11:50:53.784791: MqttClientWrapper: Subscribing to SJNFAAZE1U0123456/command/cockpitStatus FINE: 2024-05-28 11:50:53.784817: MqttClientWrapper: Subscribing to command/cockpitStatus FINER: 2024-05-28 11:50:53.784840: main: fetchAndPublishAllStatus for SJNFAAZE1U0123456

FINER: 2024-05-28 11:50:53.784905: main: fetchAndPublishBatteryStatus for SJNFAAZE1U0123456 FINEST: 2024-05-28 11:50:53.784962: LeafSession: Executing FINER: 2024-05-28 11:50:53.785807: main: fetchAndPublishClimateStatus for SJNFAAZE1U0123456 FINEST: 2024-05-28 11:50:53.785890: LeafSession: Executing

FINER: 2024-05-28 11:50:53.787109: main: fetchAndPublishLocation for SJNFAAZE1U0123456 FINEST: 2024-05-28 11:50:53.787201: LeafSession: Executing FINER: 2024-05-28 11:50:53.787894: main: fetchAndPublishCockpit for SJNFAAZE1U0123456 FINEST: 2024-05-28 11:50:53.787985: LeafSession: Executing

kamiKAC commented 3 months ago

Hi Why not publish MQTT payloads periodically or on status update using HA? leaf/command/stats/daily update leaf/command/stats/monthly update

hmfssantos commented 3 months ago

Hello Marcin

Time is always short and sometimes a quick solution is the best solution. I tried your advise and it works like a charm! 💯 Thanks for the sharing the idea.