July 21, 2024
Description
This project contains a box to hide the nodeMCU esp8266 together with a 0.96" oled display. The box is then connected to an external usb power supply that is on the nodeMCU board.
First, the nodeMCU board is slid into the bottom box on four sticks, attached with a melt gun, and then the display is attached to the lid using a melt gun. The lid is slid onto the box. The box can be attached anywhere using double-sided adhesive tape. The lid can be removed from the box at any time.
If you want to use this case as it is in the photo to display PV data from a Solax inverter, you can download the source code below. You will need Home assistant and the ESPHome add-on installed for this. You can also use the icons, which are also downloadable.
esphome:
name: photovoltaics
friendly_name: photovoltaics
esp8266:
board: nodemcuv2
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "yourkey"
ota:
platform: esphome
password: "yourpassword"
# num_attempts: 3
# safe_mode: no
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Photovoltaics Fallback Hotspot"
password: "password"
#switch:
# - platform: gpio
# pin: D4 #interni led
# inverted: True
# name: "NodeMCU internal LED"
# id: internal_led
time:
- platform: homeassistant
id: homeassistant_time
timezone: Europe/Prague
image: # The folder for images is (create) on HA in \config\esphome\_icons
- file: "_icons/pv.png"
id: imgPV
- file: "_icons/bat.png"
id: imgBat
- file: "_icons/grid.png"
id: imgGrid
- file: "_icons/house.png"
id: imgDum
sensor:
- platform: homeassistant
id: fve_production
entity_id: sensor.solax_pv_power_total
internal: true
- platform: homeassistant
id: fve_consumption
entity_id: sensor.solax_house_load
internal: true
- platform: homeassistant
id: fve_battery
entity_id: sensor.solax_battery_power_charge
internal: true
- platform: homeassistant
id: fve_battery_soc
entity_id: sensor.solax_battery_capacity
internal: true
- platform: homeassistant
id: fve_grid
entity_id: sensor.solax_grid_import
internal: true
font:
- file: 'arial.ttf'
id: font1
size: 13
- file: 'arial.ttf'
id: font2
size: 12
i2c:
sda: D2
scl: D1
scan: false
display:
- platform: ssd1306_i2c
model: SSD1306_128X64
address: 0x3C
id: my_display
lambda: |-
it.image(0, 2, id(imgPV));
if (id(fve_production).state <= 999) {
it.printf(15, 0, id(font1), TextAlign::TOP_LEFT, "%.0f W", id(fve_production).state);
} else {
it.printf(15, 0, id(font1), TextAlign::TOP_LEFT, "%.2f kW", id(fve_production).state/1000);
}
it.image(0, 19, id(imgDum));
if (id(fve_consumption).state <= 999) {
it.printf(15, 33, id(font1), TextAlign::BOTTOM_LEFT, "%.0f W", id(fve_consumption).state);
} else {
it.printf(15, 33, id(font1), TextAlign::BOTTOM_LEFT, "%.2f kW", id(fve_consumption).state/1000);
}
it.image(0, 35, id(imgGrid));
if (id(fve_grid).state <= 999) {
it.printf(15, 49, id(font1), TextAlign::BOTTOM_LEFT, "%.0f W", id(fve_grid).state);
} else {
it.printf(15, 49, id(font1), TextAlign::BOTTOM_LEFT, "%.2f kW", id(fve_grid).state/1000);
}
it.strftime(0, 51, id(font1), " %d.%m.%Y %H:%M", id(homeassistant_time).now());
it.image(116, 2, id(imgBat));
it.printf(115, 0, id(font1), TextAlign::TOP_RIGHT, "%.0f%%", id(fve_battery_soc).state);
it.image(116, 19, id(imgBat));
if ((id(fve_consumption).state) >= 0) {
if ((id(fve_consumption).state) <= 999) {
it.printf(115, 19, id(font2), TextAlign::TOP_RIGHT, "%.0f W", id(fve_battery).state);
} else {
it.printf(115, 19, id(font2), TextAlign::TOP_RIGHT, "%.2fkW", id(fve_battery).state/1000);
}
} else {
if ((id(fve_consumption).state) >= -999) {
it.printf(115, 19, id(font2), TextAlign::TOP_RIGHT, "-%.0f W", id(fve_battery).state);
} else {
it.printf(115, 19, id(font2), TextAlign::TOP_RIGHT, "-%.2fkW", id(fve_battery).state/1000);
}
}
captive_portal: License:
Creative Commons — Public Domain
8