Fala Galera tudo bem?
Testei todas as duas alternativas possíveis e acabei criando uma terceira =)
Por que?
Via MQTT tive problemas com a execução do automate, em alguns momentos se você abrir o Torque fora dele, meio que ele se perde, e se você adicionar novos PIDs ele embaralha todos os dados.
Via integração, toda vez que você reinicia o Home Assistant somem os sensores.
Ai dei uma estuda e descobri que o APP torque no Web Uploader dele apenas faz uma requisição HTTP GET padrão que OBRIGATORIAMENTE precisa responder um “OK!”, então o que fiz? criei uma logica no nodered para criar meu proprio endpoint para receber os dados.
Devem existir maneiras mais simples e lógicas de tratar os dados, mas foi assim que acabei fazendo, compartilho o codigo aqui, fiquem a vontade para evoluirmos ele juntos
Segue código dos nodes:
[
{
"id": "f213f64ad148d591",
"type": "ha-entity",
"z": "dc5ac461340aa2d5",
"name": "Marcha",
"server": "e139b0fa5ad35f1b",
"version": 2,
"debugenabled": false,
"outputs": 1,
"entityType": "sensor",
"config": [
{
"property": "name",
"value": "Etyos Current Gear"
},
{
"property": "device_class",
"value": ""
},
{
"property": "icon",
"value": "mdi:car"
},
{
"property": "unit_of_measurement",
"value": ""
},
{
"property": "state_class",
"value": ""
},
{
"property": "last_reset",
"value": ""
}
],
"state": "$round($number(payload), 0)",
"stateType": "jsonata",
"attributes": [],
"resend": true,
"outputLocation": "payload",
"outputLocationType": "none",
"inputOverride": "allow",
"outputOnStateChange": false,
"outputPayload": "",
"outputPayloadType": "str",
"x": 1300,
"y": 580,
"wires": [
[]
]
},
{
"id": "a6ff5353e803551a",
"type": "ha-entity",
"z": "dc5ac461340aa2d5",
"name": "% Alcool",
"server": "e139b0fa5ad35f1b",
"version": 2,
"debugenabled": false,
"outputs": 1,
"entityType": "sensor",
"config": [
{
"property": "name",
"value": "Etyos Alcohol Fuel Percentage"
},
{
"property": "device_class",
"value": ""
},
{
"property": "icon",
"value": "mdi:car"
},
{
"property": "unit_of_measurement",
"value": "%"
},
{
"property": "state_class",
"value": ""
},
{
"property": "last_reset",
"value": ""
}
],
"state": "$round($number(payload[0]), 2)",
"stateType": "jsonata",
"attributes": [],
"resend": true,
"outputLocation": "payload",
"outputLocationType": "none",
"inputOverride": "allow",
"outputOnStateChange": false,
"outputPayload": "",
"outputPayloadType": "str",
"x": 1300,
"y": 1300,
"wires": [
[]
]
},
{
"id": "e129133359b48a7d",
"type": "ha-entity",
"z": "dc5ac461340aa2d5",
"name": "Autonomia - Estimado",
"server": "e139b0fa5ad35f1b",
"version": 2,
"debugenabled": false,
"outputs": 1,
"entityType": "sensor",
"config": [
{
"property": "name",
"value": "Etyos Distance to empty"
},
{
"property": "device_class",
"value": ""
},
{
"property": "icon",
"value": "mdi:car"
},
{
"property": "unit_of_measurement",
"value": "km"
},
{
"property": "state_class",
"value": ""
},
{
"property": "last_reset",
"value": ""
}
],
"state": "$round($number(payload), 2)",
"stateType": "jsonata",
"attributes": [],
"resend": true,
"outputLocation": "payload",
"outputLocationType": "none",
"inputOverride": "allow",
"outputOnStateChange": false,
"outputPayload": "",
"outputPayloadType": "str",
"x": 1340,
"y": 760,
"wires": [
[]
]
},
{
"id": "6a86b03598588ef5",
"type": "ha-entity",
"z": "dc5ac461340aa2d5",
"name": "Tanque de combustível",
"server": "e139b0fa5ad35f1b",
"version": 2,
"debugenabled": false,
"outputs": 1,
"entityType": "sensor",
"config": [
{
"property": "name",
"value": "Etyos Fuel Level"
},
{
"property": "device_class",
"value": ""
},
{
"property": "icon",
"value": "mdi:car"
},
{
"property": "unit_of_measurement",
"value": "%"
},
{
"property": "state_class",
"value": ""
},
{
"property": "last_reset",
"value": ""
}
],
"state": "$round($number(payload), 2)",
"stateType": "jsonata",
"attributes": [],
"resend": true,
"outputLocation": "payload",
"outputLocationType": "none",
"inputOverride": "allow",
"outputOnStateChange": false,
"outputPayload": "",
"outputPayloadType": "str",
"x": 1350,
"y": 460,
"wires": [
[]
]
},
{
"id": "6703a07dd17b528f",
"type": "ha-entity",
"z": "dc5ac461340aa2d5",
"name": "Temperatura do motor (Radiador)",
"server": "e139b0fa5ad35f1b",
"version": 2,
"debugenabled": false,
"outputs": 1,
"entityType": "sensor",
"config": [
{
"property": "name",
"value": "Etyos Engine Coolant Temperature"
},
{
"property": "device_class",
"value": ""
},
{
"property": "icon",
"value": "mdi:car"
},
{
"property": "unit_of_measurement",
"value": "°C"
},
{
"property": "state_class",
"value": ""
},
{
"property": "last_reset",
"value": ""
}
],
"state": "$round($number(payload), 0)",
"stateType": "jsonata",
"attributes": [],
"resend": true,
"outputLocation": "payload",
"outputLocationType": "none",
"inputOverride": "allow",
"outputOnStateChange": false,
"outputPayload": "",
"outputPayloadType": "str",
"x": 1380,
"y": 640,
"wires": [
[]
]
},
{
"id": "1b4c2a0c4eb5991f",
"type": "ha-entity",
"z": "dc5ac461340aa2d5",
"name": "Velocidade",
"server": "e139b0fa5ad35f1b",
"version": 2,
"debugenabled": false,
"outputs": 1,
"entityType": "sensor",
"config": [
{
"property": "name",
"value": "Etyos Speed (OBD)"
},
{
"property": "device_class",
"value": ""
},
{
"property": "icon",
"value": "mdi:car"
},
{
"property": "unit_of_measurement",
"value": "km/h"
},
{
"property": "state_class",
"value": ""
},
{
"property": "last_reset",
"value": ""
}
],
"state": "$round($number(payload), 0)",
"stateType": "jsonata",
"attributes": [],
"resend": true,
"outputLocation": "payload",
"outputLocationType": "none",
"inputOverride": "allow",
"outputOnStateChange": false,
"outputPayload": "",
"outputPayloadType": "str",
"x": 1310,
"y": 940,
"wires": [
[]
]
},
{
"id": "c0bed3cc01247e11",
"type": "ha-entity",
"z": "dc5ac461340aa2d5",
"name": "RPM",
"server": "e139b0fa5ad35f1b",
"version": 2,
"debugenabled": false,
"outputs": 1,
"entityType": "sensor",
"config": [
{
"property": "name",
"value": "Etyos Engine RPM"
},
{
"property": "device_class",
"value": ""
},
{
"property": "icon",
"value": "mdi:car"
},
{
"property": "unit_of_measurement",
"value": "rpm"
},
{
"property": "state_class",
"value": ""
},
{
"property": "last_reset",
"value": ""
}
],
"state": "$round($number(payload), 0)",
"stateType": "jsonata",
"attributes": [],
"resend": true,
"outputLocation": "payload",
"outputLocationType": "none",
"inputOverride": "allow",
"outputOnStateChange": false,
"outputPayload": "",
"outputPayloadType": "str",
"x": 1290,
"y": 700,
"wires": [
[]
]
},
{
"id": "5bd62d62faf25f61",
"type": "ha-entity",
"z": "dc5ac461340aa2d5",
"name": "Voltagem no modulo",
"server": "e139b0fa5ad35f1b",
"version": 2,
"debugenabled": false,
"outputs": 1,
"entityType": "sensor",
"config": [
{
"property": "name",
"value": "Etyos Voltage (Control Module)"
},
{
"property": "device_class",
"value": ""
},
{
"property": "icon",
"value": "mdi:car"
},
{
"property": "unit_of_measurement",
"value": "V"
},
{
"property": "state_class",
"value": ""
},
{
"property": "last_reset",
"value": ""
}
],
"state": "$round($number(payload), 2)",
"stateType": "jsonata",
"attributes": [],
"resend": true,
"outputLocation": "payload",
"outputLocationType": "none",
"inputOverride": "allow",
"outputOnStateChange": false,
"outputPayload": "",
"outputPayloadType": "str",
"x": 1340,
"y": 820,
"wires": [
[]
]
},
{
"id": "293eaa832f24f82f",
"type": "ha-entity",
"z": "dc5ac461340aa2d5",
"name": "Média KPL Longa",
"server": "e139b0fa5ad35f1b",
"version": 2,
"debugenabled": false,
"outputs": 1,
"entityType": "sensor",
"config": [
{
"property": "name",
"value": "Etyos Etyos Kilometers Per Litre(Long Term Average)"
},
{
"property": "device_class",
"value": ""
},
{
"property": "icon",
"value": "mdi:car"
},
{
"property": "unit_of_measurement",
"value": "km/L"
},
{
"property": "state_class",
"value": ""
},
{
"property": "last_reset",
"value": ""
}
],
"state": "$round($number(payload), 2)",
"stateType": "jsonata",
"attributes": [],
"resend": true,
"outputLocation": "payload",
"outputLocationType": "none",
"inputOverride": "allow",
"outputOnStateChange": false,
"outputPayload": "",
"outputPayloadType": "str",
"x": 1330,
"y": 520,
"wires": [
[]
]
},
{
"id": "fe76a8b93d8418e3",
"type": "ha-entity",
"z": "dc5ac461340aa2d5",
"name": "Média KPL Viagem",
"server": "e139b0fa5ad35f1b",
"version": 2,
"debugenabled": false,
"outputs": 1,
"entityType": "sensor",
"config": [
{
"property": "name",
"value": "Etyos Trip average KPL"
},
{
"property": "device_class",
"value": ""
},
{
"property": "icon",
"value": "mdi:car"
},
{
"property": "unit_of_measurement",
"value": "km/L"
},
{
"property": "state_class",
"value": ""
},
{
"property": "last_reset",
"value": ""
}
],
"state": "$round($number(payload), 2)",
"stateType": "jsonata",
"attributes": [],
"resend": true,
"outputLocation": "payload",
"outputLocationType": "none",
"inputOverride": "allow",
"outputOnStateChange": false,
"outputPayload": "",
"outputPayloadType": "str",
"x": 1330,
"y": 1000,
"wires": [
[]
]
},
{
"id": "96275ee390a252a2",
"type": "ha-entity",
"z": "dc5ac461340aa2d5",
"name": "Média KPL Instantâneo",
"server": "e139b0fa5ad35f1b",
"version": 2,
"debugenabled": false,
"outputs": 1,
"entityType": "sensor",
"config": [
{
"property": "name",
"value": "Etyos Kilometers Per Litre(Instant)"
},
{
"property": "device_class",
"value": ""
},
{
"property": "icon",
"value": "mdi:car"
},
{
"property": "unit_of_measurement",
"value": "km/L"
},
{
"property": "state_class",
"value": ""
},
{
"property": "last_reset",
"value": ""
}
],
"state": "$round($number(payload), 2)",
"stateType": "jsonata",
"attributes": [],
"resend": true,
"outputLocation": "payload",
"outputLocationType": "none",
"inputOverride": "allow",
"outputOnStateChange": false,
"outputPayload": "",
"outputPayloadType": "str",
"x": 1350,
"y": 880,
"wires": [
[]
]
},
{
"id": "a275d60d0c7727ee",
"type": "ha-entity",
"z": "dc5ac461340aa2d5",
"name": "Carga do motor",
"server": "e139b0fa5ad35f1b",
"version": 2,
"debugenabled": false,
"outputs": 1,
"entityType": "sensor",
"config": [
{
"property": "name",
"value": "Etyos Engine Load(Absolute)"
},
{
"property": "device_class",
"value": ""
},
{
"property": "icon",
"value": "mdi:car"
},
{
"property": "unit_of_measurement",
"value": "%"
},
{
"property": "state_class",
"value": ""
},
{
"property": "last_reset",
"value": ""
}
],
"state": "$round($number(payload), 2)",
"stateType": "jsonata",
"attributes": [],
"resend": true,
"outputLocation": "payload",
"outputLocationType": "none",
"inputOverride": "allow",
"outputOnStateChange": false,
"outputPayload": "",
"outputPayloadType": "str",
"x": 1320,
"y": 1240,
"wires": [
[]
]
},
{
"id": "a65f8f9465c34372",
"type": "ha-entity",
"z": "dc5ac461340aa2d5",
"name": "Combustível usado na viagem",
"server": "e139b0fa5ad35f1b",
"version": 2,
"debugenabled": false,
"outputs": 1,
"entityType": "sensor",
"config": [
{
"property": "name",
"value": "Etyos Fuel used (trip)"
},
{
"property": "device_class",
"value": ""
},
{
"property": "icon",
"value": "mdi:car"
},
{
"property": "unit_of_measurement",
"value": "l"
},
{
"property": "state_class",
"value": ""
},
{
"property": "last_reset",
"value": ""
}
],
"state": "$round($number(payload), 2)",
"stateType": "jsonata",
"attributes": [],
"resend": true,
"outputLocation": "payload",
"outputLocationType": "none",
"inputOverride": "allow",
"outputOnStateChange": false,
"outputPayload": "",
"outputPayloadType": "str",
"x": 1370,
"y": 1060,
"wires": [
[]
]
},
{
"id": "75a2a55d0bdcfcd1",
"type": "ha-entity",
"z": "dc5ac461340aa2d5",
"name": "Média de velocidade Andando",
"server": "e139b0fa5ad35f1b",
"version": 2,
"debugenabled": false,
"outputs": 1,
"entityType": "sensor",
"config": [
{
"property": "name",
"value": "Etyos Average trip speed"
},
{
"property": "device_class",
"value": ""
},
{
"property": "icon",
"value": "mdi:car"
},
{
"property": "unit_of_measurement",
"value": "km/h"
},
{
"property": "state_class",
"value": ""
},
{
"property": "last_reset",
"value": ""
}
],
"state": "$round($number(payload), 2)",
"stateType": "jsonata",
"attributes": [],
"resend": true,
"outputLocation": "payload",
"outputLocationType": "none",
"inputOverride": "allow",
"outputOnStateChange": false,
"outputPayload": "",
"outputPayloadType": "str",
"x": 1370,
"y": 1120,
"wires": [
[]
]
},
{
"id": "7a15d21cafa5043f",
"type": "ha-entity",
"z": "dc5ac461340aa2d5",
"name": "Média de velocidade Andando e parado",
"server": "e139b0fa5ad35f1b",
"version": 2,
"debugenabled": false,
"outputs": 1,
"entityType": "sensor",
"config": [
{
"property": "name",
"value": "Etyos Average trip speed(whilst stopped or moving)"
},
{
"property": "device_class",
"value": ""
},
{
"property": "icon",
"value": "mdi:car"
},
{
"property": "unit_of_measurement",
"value": "km/h"
},
{
"property": "state_class",
"value": ""
},
{
"property": "last_reset",
"value": ""
}
],
"state": "$round($number(payload), 2)",
"stateType": "jsonata",
"attributes": [],
"resend": true,
"outputLocation": "payload",
"outputLocationType": "none",
"inputOverride": "allow",
"outputOnStateChange": false,
"outputPayload": "",
"outputPayloadType": "str",
"x": 1400,
"y": 1180,
"wires": [
[]
]
},
{
"id": "b85fff4374e83968",
"type": "http in",
"z": "dc5ac461340aa2d5",
"name": "",
"url": "/torque",
"method": "get",
"upload": false,
"swaggerDoc": "",
"x": 850,
"y": 100,
"wires": [
[
"ac6c1dcfa7cfeb78",
"37a56a679a5df365"
]
]
},
{
"id": "6c223c7c441e24cb",
"type": "http response",
"z": "dc5ac461340aa2d5",
"name": "",
"statusCode": "200",
"headers": {},
"x": 1300,
"y": 100,
"wires": []
},
{
"id": "ac6c1dcfa7cfeb78",
"type": "template",
"z": "dc5ac461340aa2d5",
"name": "",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "OK!",
"output": "str",
"x": 1100,
"y": 100,
"wires": [
[
"6c223c7c441e24cb"
]
]
},
{
"id": "37a56a679a5df365",
"type": "split",
"z": "dc5ac461340aa2d5",
"name": "",
"splt": "\\n",
"spltType": "str",
"arraySplt": 1,
"arraySpltType": "len",
"stream": false,
"addname": "key",
"x": 1010,
"y": 140,
"wires": [
[
"0fe73d4adcf0e2c6"
]
]
},
{
"id": "0fe73d4adcf0e2c6",
"type": "switch",
"z": "dc5ac461340aa2d5",
"name": "",
"property": "key",
"propertyType": "msg",
"rules": [
{
"t": "cont",
"v": "defaultUnit",
"vt": "str"
},
{
"t": "cont",
"v": "userFullName",
"vt": "str"
},
{
"t": "cont",
"v": "userShortName",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": true,
"outputs": 4,
"x": 1010,
"y": 340,
"wires": [
[
"588ad38b3eeab57d"
],
[
"b51b31f54952970f"
],
[
"c78dc6cae2a72dbf"
],
[
"325a6251deba01bf"
]
]
},
{
"id": "588ad38b3eeab57d",
"type": "change",
"z": "dc5ac461340aa2d5",
"name": "",
"rules": [
{
"t": "set",
"p": "pid",
"pt": "msg",
"to": "$substringAfter(key, 'defaultUnit')",
"tot": "jsonata"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload",
"tot": "msg"
},
{
"t": "set",
"p": "key",
"pt": "msg",
"to": "key",
"tot": "msg"
},
{
"t": "set",
"p": "classe",
"pt": "msg",
"to": "defaultUnit",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1300,
"y": 300,
"wires": [
[
"7d71e667e15948cc"
]
]
},
{
"id": "b51b31f54952970f",
"type": "change",
"z": "dc5ac461340aa2d5",
"name": "",
"rules": [
{
"t": "set",
"p": "pid",
"pt": "msg",
"to": "$substringAfter(key, 'userFullName')",
"tot": "jsonata"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload",
"tot": "msg"
},
{
"t": "set",
"p": "key",
"pt": "msg",
"to": "key",
"tot": "msg"
},
{
"t": "set",
"p": "classe",
"pt": "msg",
"to": "userFullName",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1300,
"y": 340,
"wires": [
[
"7d71e667e15948cc"
]
]
},
{
"id": "c78dc6cae2a72dbf",
"type": "change",
"z": "dc5ac461340aa2d5",
"name": "",
"rules": [
{
"t": "set",
"p": "pid",
"pt": "msg",
"to": "$substringAfter(key, 'userShortName')",
"tot": "jsonata"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload",
"tot": "msg"
},
{
"t": "set",
"p": "key",
"pt": "msg",
"to": "key",
"tot": "msg"
},
{
"t": "set",
"p": "classe",
"pt": "msg",
"to": "userShortName",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1300,
"y": 380,
"wires": [
[
"7d71e667e15948cc"
]
]
},
{
"id": "360f2cd1e1fe060e",
"type": "switch",
"z": "dc5ac461340aa2d5",
"name": "PIDs",
"property": "key",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "k2f",
"vt": "str"
},
{
"t": "eq",
"v": "kff5202",
"vt": "str"
},
{
"t": "eq",
"v": "k-212e",
"vt": "str"
},
{
"t": "eq",
"v": "k5",
"vt": "str"
},
{
"t": "eq",
"v": "kc",
"vt": "str"
},
{
"t": "eq",
"v": "kff126a",
"vt": "str"
},
{
"t": "eq",
"v": "k42",
"vt": "str"
},
{
"t": "eq",
"v": "kff1203",
"vt": "str"
},
{
"t": "eq",
"v": "kd",
"vt": "str"
},
{
"t": "eq",
"v": "kff1206",
"vt": "str"
},
{
"t": "eq",
"v": "kff1271",
"vt": "str"
},
{
"t": "eq",
"v": "kff1263",
"vt": "str"
},
{
"t": "eq",
"v": "kff1272",
"vt": "str"
},
{
"t": "eq",
"v": "k43",
"vt": "str"
},
{
"t": "eq",
"v": "k52",
"vt": "str"
}
],
"checkall": "false",
"repair": false,
"outputs": 15,
"x": 1050,
"y": 800,
"wires": [
[
"6a86b03598588ef5"
],
[
"293eaa832f24f82f"
],
[
"f213f64ad148d591"
],
[
"6703a07dd17b528f"
],
[
"c0bed3cc01247e11"
],
[
"e129133359b48a7d"
],
[
"5bd62d62faf25f61"
],
[
"96275ee390a252a2"
],
[
"1b4c2a0c4eb5991f"
],
[
"fe76a8b93d8418e3"
],
[
"a65f8f9465c34372"
],
[
"75a2a55d0bdcfcd1"
],
[
"7a15d21cafa5043f"
],
[
"a275d60d0c7727ee"
],
[
"a6ff5353e803551a"
]
]
},
{
"id": "325a6251deba01bf",
"type": "change",
"z": "dc5ac461340aa2d5",
"name": "Key - Payload",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload",
"tot": "msg"
},
{
"t": "set",
"p": "key",
"pt": "msg",
"to": "key",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 850,
"y": 800,
"wires": [
[
"360f2cd1e1fe060e"
]
]
},
{
"id": "e139b0fa5ad35f1b",
"type": "server",
"name": "Home Assistant",
"version": 4,
"addon": false,
"rejectUnauthorizedCerts": true,
"ha_boolean": "y|yes|true|on|home|open",
"connectionDelay": true,
"cacheJson": true,
"heartbeat": false,
"heartbeatInterval": "30",
"areaSelector": "friendlyName",
"deviceSelector": "friendlyName",
"entitySelector": "friendlyName",
"statusSeparator": ": ",
"statusYear": "hidden",
"statusMonth": "short",
"statusDay": "numeric",
"statusHourCycle": "default",
"statusTimeFormat": "h:m"
}]
Explicando os nodes:
No bloco 1 crio o endpoint HTTP com a resposta “OK!”
No bloco 2 separo os registros dos exemplos de dados (Sim, o Torque envia a cada inicio de upload os dados do PID, Nome curto, Nome Longo e a Unidade de medida, o PID vem embaralhado, mas separo eles nos nodes finais deste bloco), no meu caso salvei os dados em um Banco de dados, mas daria pra usar para criar os sensores, ou criar saidas mqtt ou algo do tipo
No bloco 3 crio os sensores e separo e aloco os valores em seu respectivos sensores
Espero que gostem.
####DESAFIO####
Estou procurando uma forma de usar o timestamp vindo do torque (hora real da leitura) e não o que ele entrou no HA, isso fará com que dashboards Grafana fiquem corretos no caso de envio de dados após um período offline por exemplo.
Bora ajudar ai galera