r/Esphome • u/kap-abel • 5h ago
INA228 doesn’t connect
Hello! I am stuck with a problem of an INA228 sensor. Here a script which is working:
``` esphome: name: ina228reader
esp32: board: esp32dev framework: type: arduino
logger: level: DEBUG
Enable OTA updates
ota: platform: esphome
Enable API (optional, for Home Assistant)
api:
wifi: ssid: « xxx » password: « xxx »
i2c: sda: GPIO21 scl: GPIO22 scan: true # Will print all devices found on bus frequency: 100000
INA228 sensor configuration
sensor: - platform: ina2xx_i2c model: INA228 address: 0x40 shunt_resistance: 0.02 ohm max_current: 10 A update_interval: 2s
bus_voltage:
name: "INA228 Bus Voltage"
current:
name: "INA228 Current"
power:
name: "INA228 Power"
```
This outputs successfully:
``` 14:43:55.984 -> [0;36m[D][sensor:103]: 'INA228 Bus Voltage': Sending state 3.31562 V with 5 decimals of accuracy[0m
```
Then I wanted to integrate this into my bigger device but doing so without success: ```esphome: name: voltage-sensor on_boot: priority: -100 then: - light.turn_on: board_led - delay: 10s # Give time to get measurements #- component.update: solar_voltage_bus_voltage - component.update: battery_voltage - component.update: battery_status - component.update: solar_status - component.update: timestamp - component.update: outside_temperature - component.update: inside_temperature
- wait_until:
condition:
lambda: return !isnan(id(solar_voltage).state) && !isnan(id(battery_voltage).state);
timeout: 10s
- mqtt.publish:
topic: voltage-sensor/solar_voltage
payload: !lambda 'return to_string(id(solar_voltage_bus_voltage).state);'
- mqtt.publish:
topic: voltage-sensor/battery_voltage
payload: !lambda 'return to_string(id(battery_voltage).state);'
- mqtt.publish:
topic: voltage-sensor/battery_status
payload: !lambda 'return id(battery_status).state;'
- mqtt.publish:
topic: voltage-sensor/solar_status
payload: !lambda 'return id(solar_status).state;'
- mqtt.publish:
topic: voltage-sensor/outside_temperature
payload: !lambda 'return to_string(id(outside_temperature).state);'
- mqtt.publish:
topic: voltage-sensor/inside_temperature
payload: !lambda 'return to_string(id(inside_temperature).state);'
- wait_until:
condition:
lambda: return id(sntp_time).now().is_valid();
timeout: 15s
- component.update: timestamp
- mqtt.publish:
topic: voltage-sensor/timestamp
payload: !lambda 'return id(timestamp).state;'
- delay: 10s # Give MQTT time to publish
- light.turn_off: board_led
- deep_sleep.enter: deep_sleep_1
esp32: board: esp32dev framework: type: esp-idf
Enable logging
logger:
Enable Home Assistant API
api:
encryption:
key: "xxx"
ota: - platform: esphome password: « xxx »
mqtt: broker: xxx.s1.eu.hivemq.cloud port: 8883 username: xxx password: xxx discovery: false certificate_authority: | -----BEGIN CERTIFICATE----- xxx -----END CERTIFICATE-----
wifi: ssid: !secret wifi_ssid password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails ap: ssid: "Voltage-Sensor Fallback Hotspot" password: « xxx »
captive_portal:
time: - platform: sntp id: sntp_time timezone: Pacific/Tahiti
one_wire: - platform: gpio pin: GPIO4 id: bus_ds18b20
i2c: sda: GPIO21 scl: GPIO22 scan: true # Will print all devices found on bus frequency: 100000
sensor: - platform: ina2xx_i2c model: INA228 address: 0x40 shunt_resistance: 0.02 ohm max_current: 10 A update_interval: 2s bus_voltage: name: "Solar Voltage" id: solar_voltage_bus_voltage
platform: adc pin: GPIO35
name: "Battery Voltage"
id: battery_voltage update_interval: 10min attenuation: 11db filters:
- multiply: 5 unit_of_measurement: "V" accuracy_decimals: 3
platform: dallas_temp one_wire_id: bus_ds18b20 address: 0x7a3ce1045753f828
name: "Outside Temperature"
id: outside_temperature resolution: 12 update_interval: 60s
platform: dallas_temp one_wire_id: bus_ds18b20 address: 0x593ce10457150728
name: "Inside Temperature"
id: inside_temperature resolution: 12 update_interval: 60s
text_sensor: - platform: template #name: "Battery Status" id: battery_status icon: "mdi:battery" lambda: |- if (id(battery_voltage).state > 12.7) { return std::string("Full"); } else if (id(battery_voltage).state > 12.4) { return std::string("Charging"); } else if (id(battery_voltage).state > 12.0) { return std::string("Medium"); } else if (id(battery_voltage).state > 11.5) { return std::string("Low"); } else { return std::string("Critical"); }
platform: template id: solar_status icon: "mdi:white-balance-sunny" lambda: |- auto voltage = id(solar_voltage_bus_voltage).state; if (voltage > 20.0) { return std::string("Full Sun"); } else if (voltage > 10.0) { return std::string("Partial Sun"); } else if (voltage > 1.0) { return std::string("Weak Sun"); } else { return std::string("Night"); }
platform: template id: timestamp lambda: |- auto t = id(sntp_time).now(); if (!t.is_valid()) return std::string("invalid");
const char* months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
char buffer[48]; snprintf(buffer, sizeof(buffer), "%02d %s %d, %02d:%02d:%02d %s", t.day_of_month, months[t.month - 1], t.year, t.hour, t.minute, t.second, "TAHT");
return std::string(buffer); update_interval: 60s
output: - platform: gpio pin: GPIO2 id: led_builtin
light: - platform: binary name: "Board LED" output: led_builtin id: board_led
deep_sleep: id: deep_sleep_1 sleep_duration: 10min
```
Here I get:
``` 14:49:38.290 -> [0;35m[C][ina2xx:196]: INA2xx:[0m 14:49:38.322 -> [0;35m[C][ina2xx:197]: Device model = INA228[0m 14:49:38.322 -> [1;31m[E][ina2xx:200]: Device model mismatch. Found device with ID = 0. Please check your configuration.[0m 14:49:38.322 -> [1;31m[E][ina2xx:204]: Communication failed[0m 14:49:38.322 -> [0;35m[C][ina2xx:206]: Update Interval: 2.0s[0m 14:49:38.322 -> [0;35m[C][ina2xx:207]: Shunt resistance = 0.020000 Ohm 14:49:38.322 -> Max current = 10.000000 A 14:49:38.322 -> Shunt temp coeff = 0 ppm/°C 14:49:38.354 -> ADCRANGE = 0 (±163.84 mV) 14:49:38.354 -> CURRENT_LSB = 0.000000 14:49:38.354 -> SHUNT_CAL = 0[0m 14:49:38.354 -> [0;35m[C][ina2xx:218]: ADC Samples = 128; ADC times: Bus = 4120 μs, Shunt = 4120 μs, Temp = 4120 μs[0m 14:49:38.354 -> [0;35m[C][ina2xx:224]: Device is INA228[0m 14:49:38.354 -> [0;35m[C][ina2xx:227]: Bus Voltage 'Solar Voltage' 14:49:38.354 -> State Class: 'measurement' 14:49:38.354 -> Unit of Measurement: 'V' 14:49:38.354 -> Accuracy Decimals: 5[0m 14:49:38.354 -> [0;35m[C][ina2xx:227]: Device Class: 'voltage'[0m 14:49:38.387 -> [0;35m[C][ina2xx_i2c:020]: Address: 0x40[0m 14:49:38.387 -> [1;31m[E][component:145]: ina2xx_base is marked FAILED: unspecified[0m 14:49:38.387 -> [0;35m[C][adc.esp32:121]: ADC Sensor 'battery_voltage' 14:49:38.387 -> State Class: 'measurement' 14:49:38.387 -> Unit of Measurement: 'V' 14:49:38.387 -> Accuracy Decimals: 3[0m
```
Someone has as idea why this isn’t working?