Raphael303
Member
- Joined
- Nov 23, 2017
- Messages
- 9
Thanks to the work done in this forum and the known CanIDs the following can be done to get iMiev Battery Data from the iMiev to MQTT / HomeAssistant or any other SmartHome System capable of MQTT. (NodeRed etc.)
The only disadvantage I see is that you will only get data when the iMiev is charging (ignition/key is irrelevant) I have not managed to get data from the battery by requesting it, when the ignition was off. Never tried it with ignition on, though.
This works just the same with ANY EV where you know the CAN IDs to read. Just the Json below would need to be changed.
Here is how:
Here is the jSon File, if you want / know, more data to be sent to MQTT you can of course add the necessary IDs and conversions.
Here is a node red flow to get the data from MQTT and send each to a separate Debug-Node
I hope this helps someone.
I can now not only monitor the Charging of the iMiev, but I can also charge only to a certain point. Furthermore I have automations which check the battery state in the evening (turn on charging for 10 seconds) then decides if the car needs to be charged for the next day during the night and charges up to a desired level. This is handy for me, because I try to charge during the night only as rarely as possible, since we have solar panels and a powerwall (sortof) and charging the EV through the night should only be done when absolutely necessary.
The only disadvantage I see is that you will only get data when the iMiev is charging (ignition/key is irrelevant) I have not managed to get data from the battery by requesting it, when the ignition was off. Never tried it with ignition on, though.
This works just the same with ANY EV where you know the CAN IDs to read. Just the Json below would need to be changed.
Here is how:
- Get MeatPi WiCanOBD - https://github.com/meatpiHQ/wican-fw (Around 40$) (Great support on GitHub!)
- Plug WiCanOBD into iMiev
- Connect to your Wlan - according to manual (above)
- Install newest firmware - according to manual (above)
- Setup with your MQTT server / login - according to manual (above)
- Connect to WiCan via FTP with filezilla as described here: https://github.com/meatpiHQ/wican-fw/issues/66
- Edit the file "mqtt_canfilt.json" and replace its content with the json-content bellow
- Reboot and get the MQTT-data anyway you know how - for example via NodeRed (flow below) or by creating MQTT-Sensors in HomeAssistant
Here is the jSon File, if you want / know, more data to be sent to MQTT you can of course add the necessary IDs and conversions.
Code:
{
{
"can_flt": [
{
"CANID": 884,
"Name": "SOC1",
"PID": -1,
"StartBit": 0,
"BitLength": 8,
"Expression": "(B0-10)/2",
"Cycle": 9999
},
{
"CANID": 883,
"Name": "BatteryVolts",
"PID": -1,
"StartBit": 0,
"BitLength": 8,
"Expression": "(B4*256+B5)/10",
"Cycle": 9999
},
{
"CANID": 883,
"Name": "CellMaxVolt",
"PID": -1,
"StartBit": 0,
"BitLength": 8,
"Expression": "(B0 + 210) / 100",
"Cycle": 9999
},
{
"CANID": 883,
"Name": "CellMinVolt",
"PID": -1,
"StartBit": 0,
"BitLength": 8,
"Expression": "(B1 + 210) / 100",
"Cycle": 9999
},
{
"CANID": 884,
"Name": "SOC2",
"PID": -1,
"StartBit": 0,
"BitLength": 8,
"Expression": "(B1-10)/2",
"Cycle": 9999
},
{
"CANID": 884,
"Name": "CellMaxTemp",
"PID": -1,
"StartBit": 0,
"BitLength": 8,
"Expression": "B4-50",
"Cycle": 9999
},
{
"CANID": 884,
"Name": "CellMinTemp",
"PID": -1,
"StartBit": 0,
"BitLength": 8,
"Expression": "B5-50",
"Cycle": 9999
},
{
"CANID": 884,
"Name": "Battery100Cap",
"PID": -1,
"StartBit": 0,
"BitLength": 8,
"Expression": "B6/2",
"Cycle": 9999
},
{
"CANID": 905,
"Name": "ChargeVoltsDC",
"PID": -1,
"StartBit": 0,
"BitLength": 8,
"Expression": "2*B0+0.5",
"Cycle": 9999
},
{
"CANID": 905,
"Name": "ChargeVoltsAC",
"PID": -1,
"StartBit": 0,
"BitLength": 8,
"Expression": "B1",
"Cycle": 9999
},
{
"CANID": 905,
"Name": "ChargeAmpsDC",
"PID": -1,
"StartBit": 0,
"BitLength": 8,
"Expression": "B2/10",
"Cycle": 9999
},
{
"CANID": 905,
"Name": "ChargerTemp1",
"PID": -1,
"StartBit": 0,
"BitLength": 8,
"Expression": "B3-50",
"Cycle": 9999
},
{
"CANID": 905,
"Name": "ChargerTemp2",
"PID": -1,
"StartBit": 0,
"BitLength": 8,
"Expression": "B4-50",
"Cycle": 9999
},
{
"CANID": 905,
"Name": "ChargeAmpsAC",
"PID": -1,
"StartBit": 0,
"BitLength": 8,
"Expression": "B6/10",
"Cycle": 9999
},
{
"CANID": 1042,
"Name": "Odometer",
"PID": -1,
"StartBit": 0,
"BitLength": 8,
"Expression": "B2*65536+B3*256+B4",
"Cycle": 9999
},
{
"CANID": 646,
"Name": "OutdoorTemp",
"PID": -1,
"StartBit": 0,
"BitLength": 8,
"Expression": "B3-50",
"Cycle": 9999
}
]}
Here is a node red flow to get the data from MQTT and send each to a separate Debug-Node
Code:
[{"id":"a88c67ea87483243","type":"debug","z":"387e7197d6bc2272","name":"SOC1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":790,"y":320,"wires":[]},{"id":"ad37989ca23a9e9a","type":"debug","z":"387e7197d6bc2272","name":"SOC2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":790,"y":340,"wires":[]},{"id":"9e81ddf40702ce38","type":"debug","z":"387e7197d6bc2272","name":"debug 81","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":360,"wires":[]},{"id":"5e21d034d0e323f1","type":"debug","z":"387e7197d6bc2272","name":"debug 82","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":380,"wires":[]},{"id":"7a62e9ade27d1c40","type":"debug","z":"387e7197d6bc2272","name":"debug 83","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":400,"wires":[]},{"id":"a8249754724c2a3b","type":"debug","z":"387e7197d6bc2272","name":"debug 84","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":420,"wires":[]},{"id":"3de5984943a69458","type":"debug","z":"387e7197d6bc2272","name":"debug 85","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":440,"wires":[]},{"id":"e0d7067a8b772b40","type":"debug","z":"387e7197d6bc2272","name":"debug 86","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":460,"wires":[]},{"id":"35047cd9dd4c4123","type":"debug","z":"387e7197d6bc2272","name":"debug 87","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":480,"wires":[]},{"id":"c2ed070d573f5647","type":"debug","z":"387e7197d6bc2272","name":"debug 88","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":500,"wires":[]},{"id":"5a8d28d49e07392c","type":"debug","z":"387e7197d6bc2272","name":"debug 89","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":520,"wires":[]},{"id":"beb0448d43cd49a1","type":"debug","z":"387e7197d6bc2272","name":"debug 90","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":540,"wires":[]},{"id":"60f627d009ce8e0c","type":"debug","z":"387e7197d6bc2272","name":"debug 91","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":560,"wires":[]},{"id":"8ca7999e2879d514","type":"debug","z":"387e7197d6bc2272","name":"debug 92","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":580,"wires":[]},{"id":"8e59721c1cd40964","type":"debug","z":"387e7197d6bc2272","name":"debug 93","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":600,"wires":[]},{"id":"eb5271cbacf8544b","type":"debug","z":"387e7197d6bc2272","name":"debug 94","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":620,"wires":[]},{"id":"c960c70417f219b5","type":"function","z":"387e7197d6bc2272","name":"Parse CAN EV1","func":"// Your variables\nvar SOC1, SOC2, Battery100Cap, CellMaxTemp, CellMinTemp, BatteryVolts, CellMaxVolt, CellMinVolt, ChargeAmpsAC, ChargeAmpsDC, ChargeVoltsAC, ChargeVoltsDC, ChargerTemp1, ChargerTemp2, Odometer, OutdoorTemp;\n\n// Initialize all variables to null to ensure no data is sent if a variable is not updated\nSOC1 = SOC2 = Battery100Cap = CellMaxTemp = CellMinTemp = BatteryVolts = CellMaxVolt = CellMinVolt = ChargeAmpsAC = ChargeAmpsDC = ChargeVoltsAC = ChargeVoltsDC = ChargerTemp1 = ChargerTemp2 = Odometer = OutdoorTemp = null;\n\n// Check if the incoming message payload has one of the expected keys\nvar key = Object.keys(msg.payload)[0]; // Get the key from the incoming message\nvar value = msg.payload[key]; // Get the value associated with the key\n\n// Assign the incoming value to the corresponding variable\nswitch (key) {\n case 'SOC1': SOC1 = value; break;\n case 'SOC2': SOC2 = value; break;\n case 'Battery100Cap': Battery100Cap = value; break;\n case 'CellMaxTemp': CellMaxTemp = value; break;\n case 'CellMinTemp': CellMinTemp = value; break;\n case 'BatteryVolts': BatteryVolts = value; break;\n case 'CellMaxVolt': CellMaxVolt = value; break;\n case 'CellMinVolt': CellMinVolt = value; break;\n case 'ChargeAmpsAC': ChargeAmpsAC = value; break;\n case 'ChargeAmpsDC': ChargeAmpsDC = value; break;\n case 'ChargeVoltsAC': ChargeVoltsAC = value; break;\n case 'ChargeVoltsDC': ChargeVoltsDC = value; break;\n case 'ChargerTemp1': ChargerTemp1 = value; break;\n case 'ChargerTemp2': ChargerTemp2 = value; break;\n case 'Odometer': Odometer = value; break;\n case 'OutdoorTemp': OutdoorTemp = value; break;\n // Add more cases as needed\n default: node.warn(\"Unexpected key: \" + key); // Warn if an unexpected key is received\n}\n\n// Return the variables as message payloads for the corresponding outputs\nreturn [SOC1, SOC2, Battery100Cap, CellMaxTemp, CellMinTemp, BatteryVolts, CellMaxVolt, CellMinVolt, ChargeAmpsAC, ChargeAmpsDC, ChargeVoltsAC, ChargeVoltsDC, ChargerTemp1, ChargerTemp2, Odometer, OutdoorTemp].map(function (data) {\n return data !== null ? { payload: data } : null;\n});\n","outputs":16,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":460,"wires":[["a88c67ea87483243"],["ad37989ca23a9e9a"],["9e81ddf40702ce38"],["5e21d034d0e323f1"],["7a62e9ade27d1c40"],["a8249754724c2a3b"],["3de5984943a69458"],["e0d7067a8b772b40"],["35047cd9dd4c4123"],["c2ed070d573f5647"],["5a8d28d49e07392c"],["beb0448d43cd49a1"],["60f627d009ce8e0c"],["8ca7999e2879d514"],["8e59721c1cd40964"],["eb5271cbacf8544b"]]},{"id":"80c20fc9b8646b6e","type":"mqtt in","z":"387e7197d6bc2272","name":"","topic":"wican/84f703413a1d/can/rx","qos":"0","datatype":"auto-detect","broker":"1044669fd246f1da","nl":false,"rap":true,"rh":0,"inputs":0,"x":120,"y":460,"wires":[["5962c475f4beb5b1","c960c70417f219b5"]]},{"id":"5962c475f4beb5b1","type":"debug","z":"387e7197d6bc2272","name":"debug 95","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":300,"y":360,"wires":[]},{"id":"1044669fd246f1da","type":"mqtt-broker","name":"Mosquitto","broker":"192.168.1.103","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]
I hope this helps someone.
I can now not only monitor the Charging of the iMiev, but I can also charge only to a certain point. Furthermore I have automations which check the battery state in the evening (turn on charging for 10 seconds) then decides if the car needs to be charged for the next day during the night and charges up to a desired level. This is handy for me, because I try to charge during the night only as rarely as possible, since we have solar panels and a powerwall (sortof) and charging the EV through the night should only be done when absolutely necessary.