this is what a have so far
substitutions:
ini219_1: "Oil Press"
ini219_2: "Coolant Temp"
ini219_3: "Fuel"
esphome:
name: emu-2
friendly_name: EMU 2
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Emu Hotspot"
password: "FallbackPassword123"
# Enable Home Assistant API
api:
encryption:
key:
ota:
- platform: esphome
password:
captive_portal:
# Enable web server (optional for monitoring)
web_server:
local: true
# I2C configuration for INA219 sensors
i2c:
sda: GPIO21
scl: GPIO22
# INA219 sensors configuration
sensor:
# INA219 - Oil Press
- platform: ina219
address: 0x40
shunt_resistance: 0.1 ohm
current:
name: "$ini219_1 Current"
id: ini219_1_current
power:
name: "$ini219_1 Power"
bus_voltage:
name: "$ini219_1 Voltage"
id: ini219_1_bus_voltage
shunt_voltage:
name: "$ini219_1 Shunt Voltage"
max_voltage: 32.0V
max_current: 3.2A
update_interval: 5s
# INA219 - Coolant Temp
- platform: ina219
address: 0x41
shunt_resistance: 0.1 ohm
current:
name: "$ini219_2 Current"
id: ini219_2_current
power:
name: "$ini219_2 Power"
bus_voltage:
name: "$ini219_2 Bus Voltage"
id: ini219_2_bus_voltage
shunt_voltage:
name: "$ini219_2 Shunt Voltage"
max_voltage: 32.0V
max_current: 3.2A
update_interval: 5s
# INA219 - Fuel
- platform: ina219
address: 0x44
shunt_resistance: 0.1 ohm
current:
name: "$ini219_3 Current"
id: ini219_3_current
power:
name: "$ini219_3 Power"
bus_voltage:
name: "$ini219_3 Bus Voltage"
id: ini219_3_bus_voltage
shunt_voltage:
name: "$ini219_3 Shunt Voltage"
max_voltage: 32.0V
max_current: 3.2A
update_interval: 5s
# Calculate Oil Pressure
- platform: template
name: "$ini219_1 Pressure"
lambda: |-
float raw_voltage = id(ini219_1_bus_voltage).state;
if (raw_voltage <= 6.0) {
return (raw_voltage / 6.0) * 50.0; // Linear scaling for oil pressure
} else if (raw_voltage <= 12.0) {
return 50.0 + ((raw_voltage - 6.0) / 6.0) * 50.0; // Scaling for higher values
} else {
return 100.0; // Maximum value (could represent 100% pressure)
}
unit_of_measurement: "psi"
update_interval: 5s
# Calculate Coolant Temperature
- platform: template
name: "$ini219_2 Temp"
lambda: |-
float raw_voltage = id(ini219_2_bus_voltage).state;
if (raw_voltage <= 6.0) {
return (raw_voltage / 6.0) * 100.0; // Linear scaling for coolant temp (in °C)
} else if (raw_voltage <= 12.0) {
return 100.0 + ((raw_voltage - 6.0) / 6.0) * 100.0;
} else {
return 200.0; // Maximum value (could represent 200°C)
}
unit_of_measurement: "°C"
update_interval: 5s
# Calculate Fuel Percentage
- platform: template
name: "$ini219_3 Fuel"
lambda: |-
return (id(ini219_3_bus_voltage).state / 12.0) * 100.0; // Assuming full voltage is 12V (Fuel level)
unit_of_measurement: "%"
update_interval: 5s
# CAN bus configuration
canbus:
- platform: esp32_can
tx_pin: GPIO04
rx_pin: GPIO05
can_id: 4
bit_rate: 125000 # Use a supported bit rate like 125000
id: can0
# Transmit sensor data over CAN bus (every 5 seconds in this example)
interval:
- interval: 5s
then:
- canbus.transmit:
id: can0
data: !lambda |-
// Send Oil Pressure (1 byte), Coolant Temp (1 byte), and Fuel Percentage (1 byte) over CAN
std::array<uint8_t, 8> message = {0};
// Send Oil Pressure (scaled to an appropriate byte value)
message[0] = static_cast<uint8_t>(id(ini219_1_pressure).state); // Oil Pressure as byte (0-255)
// Send Coolant Temperature (scaled to an appropriate byte value)
message[1] = static_cast<uint8_t>(id(ini219_2_temp).state); // Coolant Temp as byte (0-255)
// Send Fuel Percentage (scaled to an appropriate byte value)
message[2] = static_cast<uint8_t>(id(ini219_3_fuel).state); // Fuel Percentage as byte (0-100)
// Remaining bytes can be padded with zeros
message[3] = 0;
message[4] = 0;
message[5] = 0;
message[6] = 0;
message[7] = 0;
return message;